diff --git a/UpsilonLanguageServer/Lib/Upsilon.dll b/UpsilonLanguageServer/Lib/Upsilon.dll index 5210340..2c03dc7 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 9ed4e9f..0ed0e56 100644 Binary files a/UpsilonLanguageServer/Lib/Upsilon.pdb and b/UpsilonLanguageServer/Lib/Upsilon.pdb differ diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs b/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs index 2369caa..b5a1ac7 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs @@ -50,16 +50,6 @@ namespace UpsilonLanguageServer using (var script = Executor.ParseInput(content, Options)) { session.SourceText = script.ScriptString; - if (script.Diagnostics.Errors.Count > 0) - { - foreach (var error in script.Diagnostics.Errors) - { - diag.Add(ConvertToVsCodeDiagnostic(error)); - } - - return; - } - var bound = script.Bind(); foreach (var error in script.Diagnostics.Errors) { @@ -70,10 +60,7 @@ namespace UpsilonLanguageServer diag.Add(ConvertToVsCodeDiagnostic(warning)); } - if (script.Diagnostics.Errors.Count == 0) - { - session.Bound = bound; - } + session.Bound = bound; } } catch (Exception e) diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs index a71870c..23f57dc 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs @@ -30,7 +30,7 @@ namespace UpsilonLanguageServer.Services { HoverProvider = true, SignatureHelpProvider = new SignatureHelpOptions("()"), - 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 28d6368..0e63a31 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs @@ -10,6 +10,7 @@ using LanguageServer.VsCode.Contracts; using Upsilon.Binder; using Upsilon.BoundTypes; using Upsilon.Utilities; +using Type = Upsilon.BaseTypes.Type; namespace UpsilonLanguageServer.Services { @@ -47,6 +48,10 @@ namespace UpsilonLanguageServer.Services contents.Append($"\n\nReturns: {fVar.ResultType}"); } } + else if (findNode is BoundFunctionExpression fe) + { + contents.Append($"\n\nReturns: {fe.ReturnType}"); + } return new Hover() { @@ -128,71 +133,53 @@ namespace UpsilonLanguageServer.Services { if (Session.Documents.TryGetValue(textDocument.Uri, out var doc) && doc.Bound != null) { - if (context.TriggerCharacter == '.') + var linePos = doc.SourceText.GetLineStartPos(position.Line); + var characterPosition = linePos + position.Character; + using (var nodeIterator = doc.Bound.GetNodeAtPosition(characterPosition).GetEnumerator()) { - var linePos = doc.SourceText.GetLineStartPos(position.Line); - var findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character - 2); - if (findNode is BoundVariableSymbol variableSymbol) + if (nodeIterator.MoveNext()) { - var result = await GetListFromVariableSymbol(variableSymbol); - if (result != null) + var node = nodeIterator.Current; + if (node.Kind != BoundKind.BoundFullstopIndexExpression && nodeIterator.MoveNext()) { - return result; + node = nodeIterator.Current; + } + + if (node is BoundFullStopIndexExpression indexExpression) + { + var expression = indexExpression.Expression; + var variableSymbol = ResolveVariable(expression); + var result = await GetListFromVariableSymbol(variableSymbol); + if (result != null) + { + return result; + } } } } - else - { - 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; - 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) - { - 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)}"); - })); - } + 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(key, + CompletionItemKind.Variable, value.Type.ToString(), + x.Value.CommentValue == null + ? "" + : $"\n\n{string.Join(" \n", value.CommentValue)}"); + })); } } return new CompletionList(new CompletionItem[0], false); } - private static async Task GetListFromVariableSymbol(BoundVariableSymbol variableSymbol) + private static async Task GetListFromVariableSymbol(VariableSymbol variableSymbol) { - if (variableSymbol.VariableSymbol is FunctionParameterSymbol parameterSymbol && + if (variableSymbol is FunctionParameterSymbol parameterSymbol && parameterSymbol.BoundTypeDefinition is UserDataBoundTypeDefinition udBoundDef) { return new CompletionList( @@ -203,7 +190,7 @@ namespace UpsilonLanguageServer.Services $"{value.ActualType}({value.Type})", $"{value.Comment}", null); })); } - if (variableSymbol.VariableSymbol is TableVariableSymbol tableSymbol) + if (variableSymbol is TableVariableSymbol tableSymbol) { return new CompletionList( tableSymbol.Variables.Select(x => @@ -220,5 +207,33 @@ namespace UpsilonLanguageServer.Services return null; } + private VariableSymbol ResolveVariable(BoundExpression expression) + { + if (expression.Kind == BoundKind.VariableExpression) + { + var variableExpression = (BoundVariableExpression) expression; + return variableExpression.Variable.VariableSymbol; + } + if (expression.Kind == BoundKind.BoundFullstopIndexExpression) + { + var fullStopIndexExpression = (BoundFullStopIndexExpression) expression; + var indexerExpression = fullStopIndexExpression.Expression; + var indexerVariable = ResolveVariable(indexerExpression); + if (indexerVariable.Type == Type.Table) + { + return ((TableVariableSymbol)indexerVariable).Variables[fullStopIndexExpression.Index]; + } + if (indexerVariable.Type == Type.UserData) + { + var bDefProperty = ((UserDataBoundTypeDefinition) ((FunctionParameterSymbol) indexerVariable) + .BoundTypeDefinition).Properties[fullStopIndexExpression.Index]; + var boundDef = BoundTypeHandler.GetTypeDefinition(bDefProperty.ActualType); + return new FunctionParameterSymbol(fullStopIndexExpression.Index, boundDef); + } + } + return null; + } + + } }