diff --git a/UpsilonLanguageServer/Lib/Upsilon.dll b/UpsilonLanguageServer/Lib/Upsilon.dll index 7105f35..5210340 100644 Binary files a/UpsilonLanguageServer/Lib/Upsilon.dll and b/UpsilonLanguageServer/Lib/Upsilon.dll differ diff --git a/UpsilonLanguageServer/Lib/Upsilon.pdb b/UpsilonLanguageServer/Lib/Upsilon.pdb index b5cfd3a..9ed4e9f 100644 Binary files a/UpsilonLanguageServer/Lib/Upsilon.pdb and b/UpsilonLanguageServer/Lib/Upsilon.pdb differ diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs index 722f438..28d6368 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs @@ -134,36 +134,43 @@ namespace UpsilonLanguageServer.Services var findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character - 2); if (findNode is BoundVariableSymbol variableSymbol) { - if (variableSymbol.VariableSymbol is FunctionParameterSymbol parameterSymbol && - parameterSymbol.BoundTypeDefinition is UserDataBoundTypeDefinition udBoundDef) + var result = await GetListFromVariableSymbol(variableSymbol); + if (result != null) { - return new CompletionList( - udBoundDef.Properties.Select(x => - { - var (key, value) = x; - return new CompletionItem(key, CompletionItemKind.Variable, - $"{value.ActualType}({value.Type})", $"{value.Comment}", null); - })); - } - if (variableSymbol.VariableSymbol is TableVariableSymbol tableSymbol) - { - return new CompletionList( - tableSymbol.Variables.Select(x => - { - var (key, value) = x; - return new CompletionItem(key, - CompletionItemKind.Variable, value.Type.ToString(), - x.Value.CommentValue == null - ? "" - : $"{string.Join(" \n", value.CommentValue)}", null); - })); + return result; } } } else { var linePos = doc.SourceText.GetLineStartPos(position.Line); - var scope = doc.Bound.GetScopeAt(linePos + position.Character); + 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; + if (expression.Kind == BoundKind.VariableExpression) + { + var variableExpression = (BoundVariableExpression)expression; + var result = await GetListFromVariableSymbol(variableExpression.Variable); + if (result != null) + { + return result; + } + } + } + } + + } + var scope = doc.Bound.GetScopeAt(characterPosition); var variables = scope.GetBoundScopeVisibleVariables(); if (scope != null) { @@ -183,5 +190,35 @@ namespace UpsilonLanguageServer.Services return new CompletionList(new CompletionItem[0], false); } + private static async Task GetListFromVariableSymbol(BoundVariableSymbol variableSymbol) + { + if (variableSymbol.VariableSymbol is FunctionParameterSymbol parameterSymbol && + parameterSymbol.BoundTypeDefinition is UserDataBoundTypeDefinition udBoundDef) + { + return new CompletionList( + udBoundDef.Properties.Select(x => + { + var (key, value) = x; + return new CompletionItem(key, CompletionItemKind.Variable, + $"{value.ActualType}({value.Type})", $"{value.Comment}", null); + })); + } + if (variableSymbol.VariableSymbol is TableVariableSymbol tableSymbol) + { + return new CompletionList( + tableSymbol.Variables.Select(x => + { + var (key, value) = x; + return new CompletionItem(key, + CompletionItemKind.Variable, value.Type.ToString(), + x.Value.CommentValue == null + ? "" + : $"{string.Join(" \n", value.CommentValue)}", null); + })); + } + + return null; + } + } }