Fixes and tweaks for completion
This commit is contained in:
parent
55c5f58b47
commit
37b3fe3680
Binary file not shown.
Binary file not shown.
|
@ -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<CompletionItem>(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<int>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue