diff --git a/UpsilonLanguageServer/Lib/Upsilon.dll b/UpsilonLanguageServer/Lib/Upsilon.dll index f32e9b1..639ee96 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 8d20367..b0b1ad8 100644 Binary files a/UpsilonLanguageServer/Lib/Upsilon.pdb and b/UpsilonLanguageServer/Lib/Upsilon.pdb differ diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/CompletionItemService.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/CompletionItemService.cs index b58c08c..a55178b 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/CompletionItemService.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/CompletionItemService.cs @@ -1,5 +1,7 @@ +using System; using JsonRpc.Standard.Contracts; using LanguageServer.VsCode.Contracts; +using Newtonsoft.Json.Linq; namespace UpsilonLanguageServer.Services { @@ -12,8 +14,22 @@ namespace UpsilonLanguageServer.Services public CompletionItem Resolve() { var item = RequestContext.Request.Parameters.ToObject(Utility.CamelCaseJsonSerializer); - // Add a pair of square brackets around the inserted text. item.InsertText = item.Label; + if (item.Kind == CompletionItemKind.Function) + { + var data = (JObject)item.Data; + var varcount = data.GetValue("varcount", StringComparison.InvariantCultureIgnoreCase)?.ToObject(); + item.InsertText += "("; + for (var i = varcount - 1; i >= 0; i--) + { + if (i != varcount - 1) + item.InsertText += ", "; + item.InsertText += $"${i}"; + } + item.InsertText += ")"; + } + + item.InsertTextFormat = InsertTextFormat.Snippet; return item; } } diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs index c1ab1c4..c8e8eef 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,6 +6,7 @@ using System.Threading.Tasks; using JsonRpc.Standard.Contracts; using LanguageServer.VsCode; using LanguageServer.VsCode.Contracts; +using Newtonsoft.Json.Linq; using Upsilon.Binder; using Upsilon.Binder.VariableSymbols; using Upsilon.BoundTypes; @@ -197,11 +197,7 @@ namespace UpsilonLanguageServer.Services 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 BuildItem(value); })); } @@ -216,9 +212,8 @@ namespace UpsilonLanguageServer.Services return new CompletionList( udBoundDef.Properties.Select(x => { - var (key, value) = x; - return new CompletionItem(key, CompletionItemKind.Variable, - $"{value.ActualType}({value.Type})", $"{value.Comment}", null); + var (_, value) = x; + return BuildItem(value); })); } if (variableSymbol is TableVariableSymbol tableSymbol) @@ -226,16 +221,59 @@ namespace UpsilonLanguageServer.Services 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); + var (_, value) = x; + return BuildItem(value); })); } return null; } + + private static CompletionItem BuildItem(VariableSymbol symbol) + { + var kind = CompletionItemKind.Variable; + var data = new JObject(); + if (symbol is FunctionVariableSymbol fun) + { + kind = CompletionItemKind.Function; + switch (fun) + { + case InternalFunctionVariableSymbol internalFunctionVariableSymbol: + data.Add("varCount", internalFunctionVariableSymbol.FunctionParameters.Length); + break; + case ScriptFunctionVariableSymbol scriptFunctionVariableSymbol: + data.Add("varCount", scriptFunctionVariableSymbol.Parameters.Length); + break; + } + } + else if (symbol is UserDataVariableSymbol boundVar) + { + if (boundVar.Type == Type.Function) + { + + } + } + + var documentation = symbol.CommentValue == null + ? "" + : $"{string.Join(" \n", symbol.CommentValue)}"; + return new CompletionItem(symbol.Name, kind, symbol.Type.ToString(), documentation, data); + } + + private static CompletionItem BuildItem(UserDataBoundProperty property) + { + var kind = CompletionItemKind.Variable; + var data = new JObject(); + if (property.Type == Type.Function) + { + var fun = (UserDataBoundMethod)property; + kind = CompletionItemKind.Function; + data.Add("varCount", fun.Parameters.Length); + } + + const string documentation = ""; + return new CompletionItem(property.Name, kind, property.Type.ToString(), documentation, data); + } + } }