diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs index 0524393..2a325e5 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs @@ -35,7 +35,7 @@ namespace UpsilonLanguageServer.Services { HoverProvider = true, SignatureHelpProvider = new SignatureHelpOptions( new[]{'(', ','}), - CompletionProvider = new CompletionOptions(true, ""), + CompletionProvider = new CompletionOptions(true, "."), TextDocumentSync = new TextDocumentSyncOptions { OpenClose = true, diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs index 062a14c..c1ab1c4 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs @@ -157,49 +157,54 @@ namespace UpsilonLanguageServer.Services [JsonRpcMethod] public async Task Completion(TextDocumentIdentifier textDocument, Position position, CompletionContext context) { - if (Session.Documents.TryGetValue(textDocument.Uri, out var doc) && doc.Bound != null) - { - 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 (!Session.Documents.TryGetValue(textDocument.Uri, out var doc)) + return new CompletionList(new CompletionItem[0], false); - 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; - var variableSymbol = Binder.ResolveVariable(expression, null); - var result = await GetListFromVariableSymbol(variableSymbol); - if (result != null) - { - return result; - } + 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); }