This commit is contained in:
nub31
2025-10-23 14:31:14 +02:00
parent acc38ad8ff
commit db46dbba03
3 changed files with 57 additions and 74 deletions

View File

@@ -1,9 +1,26 @@
using NubLang.Ast;
using NubLang.Syntax;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
namespace NubLang.LSP;
public static class AstExtensions
{
public static Location ToLocation(this Node node)
{
if (node.Tokens.Count == 0)
{
return new Location();
}
return new Location
{
Uri = node.Tokens.First().Span.FilePath,
Range = new Range(node.Tokens.First().Span.Start.Line - 1, node.Tokens.First().Span.Start.Column - 1, node.Tokens.Last().Span.End.Line - 1, node.Tokens.Last().Span.End.Column - 1)
};
}
public static bool ContainsPosition(this Node node, int line, int character)
{
if (node.Tokens.Count == 0)