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,8 +157,13 @@ 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);
await doc.WaitForDocumentBound();
if (doc.Bound == null)
return new CompletionList(new CompletionItem[0], false);
var linePos = doc.SourceText.GetLineStartPos(position.Line); var linePos = doc.SourceText.GetLineStartPos(position.Line);
var characterPosition = linePos + position.Character; var characterPosition = linePos + position.Character;
using (var nodeIterator = doc.Bound.GetNodeAtPosition(characterPosition).GetEnumerator()) using (var nodeIterator = doc.Bound.GetNodeAtPosition(characterPosition).GetEnumerator())
@ -191,7 +196,7 @@ namespace UpsilonLanguageServer.Services
return new CompletionList( return new CompletionList(
variables.Select(x => variables.Select(x =>
{ {
var (key, value) = x; var (_, value) = x;
return new CompletionItem(value.Name, return new CompletionItem(value.Name,
CompletionItemKind.Variable, value.Type.ToString(), CompletionItemKind.Variable, value.Type.ToString(),
x.Value.CommentValue == null x.Value.CommentValue == null
@ -199,7 +204,7 @@ namespace UpsilonLanguageServer.Services
: $"\n\n{string.Join(" \n", value.CommentValue)}"); : $"\n\n{string.Join(" \n", value.CommentValue)}");
})); }));
} }
}
return new CompletionList(new CompletionItem[0], false); return new CompletionList(new CompletionItem[0], false);
} }