Complete item when full stop is pressed, after document has been bound

This commit is contained in:
Deukhoofd 2018-12-13 17:04:49 +01:00
parent f75b7fc223
commit 55c5f58b47
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 43 additions and 38 deletions

View File

@ -35,7 +35,7 @@ namespace UpsilonLanguageServer.Services
{ {
HoverProvider = true, HoverProvider = true,
SignatureHelpProvider = new SignatureHelpOptions( new[]{'(', ','}), SignatureHelpProvider = new SignatureHelpOptions( new[]{'(', ','}),
CompletionProvider = new CompletionOptions(true, ""), CompletionProvider = new CompletionOptions(true, "."),
TextDocumentSync = new TextDocumentSyncOptions TextDocumentSync = new TextDocumentSyncOptions
{ {
OpenClose = true, OpenClose = true,

View File

@ -157,49 +157,54 @@ namespace UpsilonLanguageServer.Services
[JsonRpcMethod] [JsonRpcMethod]
public async Task<CompletionList> Completion(TextDocumentIdentifier textDocument, Position position, CompletionContext context) public async Task<CompletionList> Completion(TextDocumentIdentifier textDocument, Position position, CompletionContext context)
{ {
if (Session.Documents.TryGetValue(textDocument.Uri, out var doc) && doc.Bound != null) if (!Session.Documents.TryGetValue(textDocument.Uri, out var doc))
{ return new CompletionList(new CompletionItem[0], false);
var linePos = doc.SourceText.GetLineStartPos(position.Line);
var characterPosition = linePos + position.Character;
using (var nodeIterator = doc.Bound.GetNodeAtPosition(characterPosition).GetEnumerator())
{
if (nodeIterator.MoveNext())
{
var node = nodeIterator.Current;
if (node.Kind != BoundKind.BoundFullstopIndexExpression && nodeIterator.MoveNext())
{
node = nodeIterator.Current;
}
if (node is BoundFullStopIndexExpression indexExpression) await doc.WaitForDocumentBound();
if (doc.Bound == null)
return new CompletionList(new CompletionItem[0], false);
var linePos = doc.SourceText.GetLineStartPos(position.Line);
var characterPosition = linePos + position.Character;
using (var nodeIterator = doc.Bound.GetNodeAtPosition(characterPosition).GetEnumerator())
{
if (nodeIterator.MoveNext())
{
var node = nodeIterator.Current;
if (node.Kind != BoundKind.BoundFullstopIndexExpression && nodeIterator.MoveNext())
{
node = nodeIterator.Current;
}
if (node is BoundFullStopIndexExpression indexExpression)
{
var expression = indexExpression.Expression;
var variableSymbol = Binder.ResolveVariable(expression, null);
var result = await GetListFromVariableSymbol(variableSymbol);
if (result != null)
{ {
var expression = indexExpression.Expression; return result;
var variableSymbol = Binder.ResolveVariable(expression, null);
var result = await GetListFromVariableSymbol(variableSymbol);
if (result != null)
{
return result;
}
} }
} }
} }
var scope = doc.Bound.GetScopeAt(characterPosition);
var variables = scope.GetBoundScopeVisibleVariables();
if (scope != null)
{
return new CompletionList(
variables.Select(x =>
{
var (key, value) = x;
return new CompletionItem(value.Name,
CompletionItemKind.Variable, value.Type.ToString(),
x.Value.CommentValue == null
? ""
: $"\n\n{string.Join(" \n", value.CommentValue)}");
}));
}
} }
var scope = doc.Bound.GetScopeAt(characterPosition);
var variables = scope.GetBoundScopeVisibleVariables();
if (scope != null)
{
return new CompletionList(
variables.Select(x =>
{
var (_, value) = x;
return new CompletionItem(value.Name,
CompletionItemKind.Variable, value.Type.ToString(),
x.Value.CommentValue == null
? ""
: $"\n\n{string.Join(" \n", value.CommentValue)}");
}));
}
return new CompletionList(new CompletionItem[0], false); return new CompletionList(new CompletionItem[0], false);
} }