A lot more auto complete support

This commit is contained in:
Deukhoofd 2018-11-27 19:05:18 +01:00
parent fdd97fa9b3
commit 34751d9edc
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 20 additions and 7 deletions

View File

@ -9,6 +9,7 @@ using LanguageServer.VsCode.Contracts;
using LanguageServer.VsCode.Server;
using Upsilon.Binder;
using Upsilon.Parser;
using Upsilon.Utilities;
namespace UpsilonLanguageServer.Services
{
@ -25,7 +26,7 @@ namespace UpsilonLanguageServer.Services
if (doc.Bound != null && doc.SourceText != null)
{
var linePos = doc.SourceText.GetLineStartPos(position.Line);
var findNode = doc.Bound.GetNodeAtPosition(linePos + position.Character);
var findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character);
if (findNode != null)
{
var contents = new StringBuilder($"Kind: {findNode.Kind}");
@ -117,7 +118,7 @@ namespace UpsilonLanguageServer.Services
if (context.TriggerCharacter == '.')
{
var linePos = doc.SourceText.GetLineStartPos(position.Line);
var findNode = doc.Bound.GetNodeAtPosition(linePos + position.Character - 2);
var findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character - 2);
if (findNode is BoundVariableSymbol variableSymbol)
{
if (variableSymbol.VariableSymbol is TableVariableSymbol tableSymbol)
@ -133,13 +134,25 @@ namespace UpsilonLanguageServer.Services
: $"\n\n{string.Join(" \n", value.CommentValue)}");
}));
}
return new CompletionList(
new[]
}
}
else
{
new CompletionItem(findNode.Kind.ToString(), CompletionItemKind.Variable,
variableSymbol.VariableSymbol.Name, ""),
},
false);
var linePos = doc.SourceText.GetLineStartPos(position.Line);
var scope = doc.Bound.GetScopeAt(linePos + position.Character);
var variables = scope.GetBoundScopeVisibleVariables();
if (scope != null)
{
return new CompletionList(
variables.Select(x =>
{
var (key, value) = x;
return new CompletionItem(key,
CompletionItemKind.Variable, value.Type.ToString(),
x.Value.CommentValue == null
? ""
: $"\n\n{string.Join(" \n", value.CommentValue)}");
}));
}
}
}