diff --git a/UpsilonLanguageServer/Lib/Upsilon.dll b/UpsilonLanguageServer/Lib/Upsilon.dll index 9a7cb8b..f32e9b1 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 8d0f737..8d20367 100644 Binary files a/UpsilonLanguageServer/Lib/Upsilon.pdb and b/UpsilonLanguageServer/Lib/Upsilon.pdb differ diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/BoundTypeParser.cs b/UpsilonLanguageServer/UpsilonLanguageServer/BoundTypeParser.cs index a3ac5ad..a4e933d 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/BoundTypeParser.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/BoundTypeParser.cs @@ -120,12 +120,14 @@ namespace UpsilonLanguageServer foreach (var prop in properties) { var parameterValue = (JObject) prop.Value; + var parName = parameterValue.GetValue("name", StringComparison.InvariantCultureIgnoreCase) + ?.ToString(); var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase) ?.ToString(); var parsedType = ParseType(parType); var isOptional = parameterValue.GetValue("IsOptional", StringComparison.InvariantCultureIgnoreCase) ?.ToObject(); - parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(parsedType, + parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(parName, parsedType, isOptional.HasValue && isOptional.Value)); } } diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs b/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs index dfe004c..dcc2234 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs @@ -33,6 +33,7 @@ namespace UpsilonLanguageServer var task = RealLint(document, maxNumberOfProblems, session, content, diag); // either wait until the script is linted, or until a second has passed (timeout) await Task.WhenAny(task, Task.Delay(1000)); + session.IsChanging = false; return diag; } diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/LanguageServerSession.cs b/UpsilonLanguageServer/UpsilonLanguageServer/LanguageServerSession.cs index b61cde6..7b5b621 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/LanguageServerSession.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/LanguageServerSession.cs @@ -71,9 +71,11 @@ namespace UpsilonLanguageServer public BoundScript Bound { get; set; } public SourceText SourceText { get; set; } + public bool IsChanging { get; set; } public void NotifyChanges(IEnumerable changes) { + IsChanging = true; lock (_syncLock) { if (_impendingChanges == null) diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs index 359b683..0524393 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs @@ -34,7 +34,7 @@ namespace UpsilonLanguageServer.Services return new InitializeResult(new ServerCapabilities { HoverProvider = true, - SignatureHelpProvider = new SignatureHelpOptions("()"), + SignatureHelpProvider = new SignatureHelpOptions( new[]{'(', ','}), CompletionProvider = new CompletionOptions(true, ""), TextDocumentSync = new TextDocumentSyncOptions { diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs index 060ecca..062a14c 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs @@ -66,12 +66,37 @@ namespace UpsilonLanguageServer.Services } [JsonRpcMethod] - public SignatureHelp SignatureHelp(TextDocumentIdentifier textDocument, Position position) + public async Task SignatureHelp(TextDocumentIdentifier textDocument, Position position) { - // TODO - return new SignatureHelp(new List + if (Session.Documents.TryGetValue(textDocument.Uri, out var doc)) { - }); + await doc.WaitForDocumentBound(); + if (doc.Bound != null && doc.SourceText != null) + { + var linePos = doc.SourceText.GetLineStartPos(position.Line); + var findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character); + if (findNode != null) + { + if (findNode.Kind == BoundKind.BoundFunctionCallExpression) + { + var functionCall = (BoundFunctionCallExpression)findNode; + var exp = Binder.ResolveVariable(functionCall.Identifier, null); + if (exp is InternalFunctionVariableSymbol internalFunction) + { + var n = new SignatureHelp(new List() + { + new SignatureInformation(exp.Name, string.Join(" \n", exp.CommentValue), + internalFunction.FunctionParameters.Select( + x => new ParameterInformation("", $"{x.Name} ({x.ValidTypes})")).ToList()) + }, 0, functionCall.Parameters.Length); + return n; + } + } + } + } + } + + return new SignatureHelp(); } [JsonRpcMethod(IsNotification = true)] diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Utility.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Utility.cs index 483e8d4..e464834 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Utility.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Utility.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -15,5 +16,13 @@ namespace UpsilonLanguageServer { return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); } + + public static async Task WaitForDocumentBound(this SessionDocument doc) + { + while (doc.IsChanging) + { + await Task.Delay(20); + } + } } } \ No newline at end of file