Humoroussix2799
Humoroussix2799
Explore posts from servers
CC#
Created by Humoroussix2799 on 11/11/2024 in #help
Incorrect Position for syntax tree nod
var documentLines = _documentContents[(Uri)request.TextDocument.Uri];

if (documentLines == null) FileLogger.Log("Doc is null???");

var documentText = string.Join(Environment.NewLine, documentLines);
FileLogger.Log("Docuemnt text: " + documentText);

var syntaxTree = CSharpSyntaxTree.ParseText(documentText);
var root = syntaxTree.GetRoot();

var text = syntaxTree.GetText();





var absolutePosition = text.Lines.GetPosition(new Microsoft.CodeAnalysis.Text.LinePosition(request.Position.Line, request.Position.Character));
FileLogger.Log("Absolute Position: " + absolutePosition);

var tokenAtCursor = root.FindToken(absolutePosition);




// Trace up the syntax tree to find an ObjectCreationExpressionSyntax
var objectCreation = tokenAtCursor.Parent.AncestorsAndSelf()
.OfType<ObjectCreationExpressionSyntax>()
.FirstOrDefault();


if (objectCreation != null)
{
// Check if the cursor is within the initializer span
if (objectCreation.Initializer != null &&
absolutePosition >= objectCreation.Initializer.SpanStart &&
absolutePosition <= objectCreation.Initializer.Span.End)
{
FileLogger.Log("Cursor inside ObjectCreationExpressionSyntax initializer.");
}
else
{
FileLogger.Log("Found ObjectCreationExpressionSyntax for object creation.");
}
}
else
{
FileLogger.Log("No ObjectCreationExpressionSyntax found at cursor position.");
}
var documentLines = _documentContents[(Uri)request.TextDocument.Uri];

if (documentLines == null) FileLogger.Log("Doc is null???");

var documentText = string.Join(Environment.NewLine, documentLines);
FileLogger.Log("Docuemnt text: " + documentText);

var syntaxTree = CSharpSyntaxTree.ParseText(documentText);
var root = syntaxTree.GetRoot();

var text = syntaxTree.GetText();





var absolutePosition = text.Lines.GetPosition(new Microsoft.CodeAnalysis.Text.LinePosition(request.Position.Line, request.Position.Character));
FileLogger.Log("Absolute Position: " + absolutePosition);

var tokenAtCursor = root.FindToken(absolutePosition);




// Trace up the syntax tree to find an ObjectCreationExpressionSyntax
var objectCreation = tokenAtCursor.Parent.AncestorsAndSelf()
.OfType<ObjectCreationExpressionSyntax>()
.FirstOrDefault();


if (objectCreation != null)
{
// Check if the cursor is within the initializer span
if (objectCreation.Initializer != null &&
absolutePosition >= objectCreation.Initializer.SpanStart &&
absolutePosition <= objectCreation.Initializer.Span.End)
{
FileLogger.Log("Cursor inside ObjectCreationExpressionSyntax initializer.");
}
else
{
FileLogger.Log("Found ObjectCreationExpressionSyntax for object creation.");
}
}
else
{
FileLogger.Log("No ObjectCreationExpressionSyntax found at cursor position.");
}
4 replies
CC#
Created by Humoroussix2799 on 11/11/2024 in #help
Incorrect Position for syntax tree nod
Huzzah! We Triumph!🎺 🎺 🎺 it was because the buffer was being split by \n before I passed it into the parse tree, Instead i just made the document contents a SourceText dict Before:
private readonly IDictionary<Uri, string[]> _documentContents;
private readonly IDictionary<Uri, string[]> _documentContents;
After:
private readonly IDictionary<Uri, SourceText> _documentContents;
private readonly IDictionary<Uri, SourceText> _documentContents;
and in my change/update doc handlers it was splitting by new lines to get it into one string
4 replies
CC#
Created by Humoroussix2799 on 11/11/2024 in #help
Incorrect Position for syntax tree nod
var documentLines = _documentContents[(Uri)request.TextDocument.Uri];

if (documentLines == null) FileLogger.Log("Doc is null???");

var documentText = string.Join(Environment.NewLine, documentLines);
FileLogger.Log("Docuemnt text: " + documentText);
var syntaxTree = CSharpSyntaxTree.ParseText(documentText);
var root = syntaxTree.GetRoot();

var text = syntaxTree.GetText();
FileLogger.Log("SyntaxTree text: " + text);
var nodesWithPositions = new List<Tuple<SyntaxNode, int, int>>();

FileLogger.Log("Document is same as syntax text: " + (documentText.Equals(text)));
FileLogger.Log($"Document is same as syntax text count {documentText.Length} == {text.Length}: " + (documentText.Length == text.Length));

// Traverse the syntax tree and collect all nodes
TraverseSyntaxTree(root, nodesWithPositions);

// Output the nodes and their absolute positions
foreach (var tuple in nodesWithPositions)
{
var node = tuple.Item1;
var start = tuple.Item2;
var end = tuple.Item3;
FileLogger.Log($"{node.Kind()} - Start: {start}, End: {end}");
}


FileLogger.Log("(Not absolute) Pos: " + request.Position);

var absolutePosition = text.Lines.GetPosition(new Microsoft.CodeAnalysis.Text.LinePosition(request.Position.Line, request.Position.Character));
FileLogger.Log("Absolute Position: " + absolutePosition.ToString());

var tokenAtCursor = root.FindToken(absolutePosition);

FileLogger.Log("Token At Cursor: " + tokenAtCursor.ToString());



// Trace up the syntax tree to find an ObjectCreationExpressionSyntax
var objectCreation = tokenAtCursor.Parent.AncestorsAndSelf()
.OfType<ObjectCreationExpressionSyntax>()
.FirstOrDefault();
var documentLines = _documentContents[(Uri)request.TextDocument.Uri];

if (documentLines == null) FileLogger.Log("Doc is null???");

var documentText = string.Join(Environment.NewLine, documentLines);
FileLogger.Log("Docuemnt text: " + documentText);
var syntaxTree = CSharpSyntaxTree.ParseText(documentText);
var root = syntaxTree.GetRoot();

var text = syntaxTree.GetText();
FileLogger.Log("SyntaxTree text: " + text);
var nodesWithPositions = new List<Tuple<SyntaxNode, int, int>>();

FileLogger.Log("Document is same as syntax text: " + (documentText.Equals(text)));
FileLogger.Log($"Document is same as syntax text count {documentText.Length} == {text.Length}: " + (documentText.Length == text.Length));

// Traverse the syntax tree and collect all nodes
TraverseSyntaxTree(root, nodesWithPositions);

// Output the nodes and their absolute positions
foreach (var tuple in nodesWithPositions)
{
var node = tuple.Item1;
var start = tuple.Item2;
var end = tuple.Item3;
FileLogger.Log($"{node.Kind()} - Start: {start}, End: {end}");
}


FileLogger.Log("(Not absolute) Pos: " + request.Position);

var absolutePosition = text.Lines.GetPosition(new Microsoft.CodeAnalysis.Text.LinePosition(request.Position.Line, request.Position.Character));
FileLogger.Log("Absolute Position: " + absolutePosition.ToString());

var tokenAtCursor = root.FindToken(absolutePosition);

FileLogger.Log("Token At Cursor: " + tokenAtCursor.ToString());



// Trace up the syntax tree to find an ObjectCreationExpressionSyntax
var objectCreation = tokenAtCursor.Parent.AncestorsAndSelf()
.OfType<ObjectCreationExpressionSyntax>()
.FirstOrDefault();
this is the relevant code
4 replies
CC#
Created by Humoroussix2799 on 10/22/2024 in #help
Message header must separate key and value using ':', OmniSharpLSP
4 replies
CC#
Created by Humoroussix2799 on 10/22/2024 in #help
Message header must separate key and value using ':', OmniSharpLSP
4 replies
CC#
Created by Humoroussix2799 on 10/22/2024 in #help
Message header must separate key and value using ':', OmniSharpLSP
Debug.txt
2024-10-22 16:50:38 [Worker] Initialized
2024-10-22 16:50:38 [Worker] Starting LSP server...
2024-10-22 16:50:38 [Worker] Request received: InitializeParams { ProcessId = 38876, ClientInfo = Visual Studio Code (1.94.1), RootPath = , RootUri = , InitializationOptions = , Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities.ClientCapabilities, Trace = Off, WorkspaceFolders = , WorkDoneToken = , Locale = }
2024-10-22 16:50:38 [Worker] Response: InitializeResult { Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities.ServerCapabilities, ServerInfo = WorldBoxLSP (1.0.0) }
2024-10-22 16:50:41 [Worker] Initialized
2024-10-22 16:50:41 [Worker] Starting LSP server...
2024-10-22 16:50:41 [Worker] Request received: InitializeParams { ProcessId = 38876, ClientInfo = Visual Studio Code (1.94.1), RootPath = , RootUri = , InitializationOptions = , Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities.ClientCapabilities, Trace = Off, WorkspaceFolders = , WorkDoneToken = , Locale = }
2024-10-22 16:50:41 [Worker] Response: InitializeResult { Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities.ServerCapabilities, ServerInfo = WorldBoxLSP (1.0.0) }
2024-10-22 16:50:44 [Worker] Initialized
2024-10-22 16:50:44 [Worker] Starting LSP server...
2024-10-22 16:50:44 [Worker] Request received: InitializeParams { ProcessId = 38876, ClientInfo = Visual Studio Code (1.94.1), RootPath = , RootUri = , InitializationOptions = , Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities.ClientCapabilities, Trace = Off, WorkspaceFolders = , WorkDoneToken = , Locale = }
2024-10-22 16:50:44 [Worker] Response: InitializeResult { Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities.ServerCapabilities, ServerInfo = WorldBoxLSP (1.0.0) }
2024-10-22 16:50:38 [Worker] Initialized
2024-10-22 16:50:38 [Worker] Starting LSP server...
2024-10-22 16:50:38 [Worker] Request received: InitializeParams { ProcessId = 38876, ClientInfo = Visual Studio Code (1.94.1), RootPath = , RootUri = , InitializationOptions = , Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities.ClientCapabilities, Trace = Off, WorkspaceFolders = , WorkDoneToken = , Locale = }
2024-10-22 16:50:38 [Worker] Response: InitializeResult { Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities.ServerCapabilities, ServerInfo = WorldBoxLSP (1.0.0) }
2024-10-22 16:50:41 [Worker] Initialized
2024-10-22 16:50:41 [Worker] Starting LSP server...
2024-10-22 16:50:41 [Worker] Request received: InitializeParams { ProcessId = 38876, ClientInfo = Visual Studio Code (1.94.1), RootPath = , RootUri = , InitializationOptions = , Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities.ClientCapabilities, Trace = Off, WorkspaceFolders = , WorkDoneToken = , Locale = }
2024-10-22 16:50:41 [Worker] Response: InitializeResult { Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities.ServerCapabilities, ServerInfo = WorldBoxLSP (1.0.0) }
2024-10-22 16:50:44 [Worker] Initialized
2024-10-22 16:50:44 [Worker] Starting LSP server...
2024-10-22 16:50:44 [Worker] Request received: InitializeParams { ProcessId = 38876, ClientInfo = Visual Studio Code (1.94.1), RootPath = , RootUri = , InitializationOptions = , Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities.ClientCapabilities, Trace = Off, WorkspaceFolders = , WorkDoneToken = , Locale = }
2024-10-22 16:50:44 [Worker] Response: InitializeResult { Capabilities = OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities.ServerCapabilities, ServerInfo = WorldBoxLSP (1.0.0) }
4 replies
CC#
Created by Humoroussix2799 on 6/11/2024 in #help
Reading in JSON-RPC for LSP msg returning Null???
I needed a Buffer
7 replies
CC#
Created by Humoroussix2799 on 6/11/2024 in #help
Reading in JSON-RPC for LSP msg returning Null???
there is a couple of weird things I noticed which is that the length doesnt match. Im not really sure what thats about but its out of the scope of this Q since it should'nt affect this
7 replies
CC#
Created by Humoroussix2799 on 6/11/2024 in #help
Reading in JSON-RPC for LSP msg returning Null???
and here is the CustomScanner Class:
public class CustomScanner
{
private readonly Stream stream;
//private byte[] buffer = new byte[0];

public CustomScanner(Stream inputStream)
{
stream = inputStream;
}

public bool Scan()
{
Program.logger.Log("We are in the Scan process");
// Simulate splitting logic using Rpc.Split
try
{

(int advance, byte[] token) = Rpc.Split(ReadStream(stream), true);
if (token != null)
{
return true;
}
}catch (Exception e)
{
Program.logger.Log("Ran Into a Problem trying to access the Split funciton ERR: " + e.Message);

}


return false;
}

public byte[] Bytes()
{
// Return the current token/message
Program.logger.Log("We Made it to the Bytes process and the current stream is: " + Encoding.UTF8.GetString(ReadStream(stream)));
return Rpc.Split(ReadStream(stream), true).token;

}

private byte[] ReadStream(Stream inputStream)
{
// Read all bytes from the stream
using (MemoryStream ms = new MemoryStream())
{
inputStream.CopyTo(ms);
return ms.ToArray();
}
}
}
public class CustomScanner
{
private readonly Stream stream;
//private byte[] buffer = new byte[0];

public CustomScanner(Stream inputStream)
{
stream = inputStream;
}

public bool Scan()
{
Program.logger.Log("We are in the Scan process");
// Simulate splitting logic using Rpc.Split
try
{

(int advance, byte[] token) = Rpc.Split(ReadStream(stream), true);
if (token != null)
{
return true;
}
}catch (Exception e)
{
Program.logger.Log("Ran Into a Problem trying to access the Split funciton ERR: " + e.Message);

}


return false;
}

public byte[] Bytes()
{
// Return the current token/message
Program.logger.Log("We Made it to the Bytes process and the current stream is: " + Encoding.UTF8.GetString(ReadStream(stream)));
return Rpc.Split(ReadStream(stream), true).token;

}

private byte[] ReadStream(Stream inputStream)
{
// Read all bytes from the stream
using (MemoryStream ms = new MemoryStream())
{
inputStream.CopyTo(ms);
return ms.ToArray();
}
}
}
As you can see it logs the message right before it reaches the bytes func... but once it does suddenly the message eviscerates gone just like that its null???? hence why it ''fails'' and yet just before the actual check in the log you can clearly see the message is complete?
7 replies
CC#
Created by Humoroussix2799 on 6/11/2024 in #help
Reading in JSON-RPC for LSP msg returning Null???
and here is my main program:
static void Main(string[] args)
{
if (Debugger.IsAttached) Debugger.Launch();

logger = GetLogger("C:/Users/Admin/Desktop/test-log.txt");
logger.Log("Hey I started");
// byte[] incomingMsg = Encoding.UTF8.GetBytes("Content-Length: 15\r\n\r\n{\"Method\":\"hi\"}");
// Read input from stdin

using (StreamReader reader = new StreamReader(Console.OpenStandardInput()))
{
logger.Log("We Opened Stdout");
CustomScanner scanner = new CustomScanner(reader.BaseStream);
logger.Log("Okay We Just Made It Past Custom Scanner");
while (scanner.Scan())
{
logger.Log("Currently Scanning!!!");
byte[] msg = scanner.Bytes();
if (msg != null)
{
logger.Log("The MSG was not null");
string message = System.Text.Encoding.UTF8.GetString(msg);
HandleMessage(logger, message);
}
else
{
logger.Log("Msg Was Null I.e it failed :(");
}
}
}

}




private static object HandleMessage(Logger loger, object message)
{
loger.Log(message.ToString());
return null;
}
static void Main(string[] args)
{
if (Debugger.IsAttached) Debugger.Launch();

logger = GetLogger("C:/Users/Admin/Desktop/test-log.txt");
logger.Log("Hey I started");
// byte[] incomingMsg = Encoding.UTF8.GetBytes("Content-Length: 15\r\n\r\n{\"Method\":\"hi\"}");
// Read input from stdin

using (StreamReader reader = new StreamReader(Console.OpenStandardInput()))
{
logger.Log("We Opened Stdout");
CustomScanner scanner = new CustomScanner(reader.BaseStream);
logger.Log("Okay We Just Made It Past Custom Scanner");
while (scanner.Scan())
{
logger.Log("Currently Scanning!!!");
byte[] msg = scanner.Bytes();
if (msg != null)
{
logger.Log("The MSG was not null");
string message = System.Text.Encoding.UTF8.GetString(msg);
HandleMessage(logger, message);
}
else
{
logger.Log("Msg Was Null I.e it failed :(");
}
}
}

}




private static object HandleMessage(Logger loger, object message)
{
loger.Log(message.ToString());
return null;
}
7 replies
CC#
Created by Humoroussix2799 on 6/11/2024 in #help
Reading in JSON-RPC for LSP msg returning Null???
ignore the json really just pay attention to the logs
7 replies
CC#
Created by Humoroussix2799 on 6/11/2024 in #help
Reading in JSON-RPC for LSP msg returning Null???
So here is the log.txt:
7 replies
CC#
Created by Humoroussix2799 on 5/24/2024 in #help
✅ Is there a way to programmatically formatt a file
Thank you that worked!🙂
28 replies
CC#
Created by Humoroussix2799 on 5/24/2024 in #help
✅ Is there a way to programmatically formatt a file
Yea the transpiler is built for people who don't know how to code (Its a data scripting language) In theory they should be able to look at the code without it looking like hieroglyphs or never look at the code, the goal of the language is to kinda point people in the right direction on how to actually code, knowing the command CTRL + K + CTRL + D may seem obvious to people who code but to someone who has never coded they would probably just think that coding is supposed to look like minified code on one line.
28 replies
CC#
Created by Humoroussix2799 on 5/24/2024 in #help
✅ Is there a way to programmatically formatt a file
The above results in no change to the src code
28 replies