Changes, fixes and features for autocompletion
This commit is contained in:
parent
1760e72117
commit
c7b8ef3463
Binary file not shown.
Binary file not shown.
|
@ -50,16 +50,6 @@ namespace UpsilonLanguageServer
|
||||||
using (var script = Executor.ParseInput(content, Options))
|
using (var script = Executor.ParseInput(content, Options))
|
||||||
{
|
{
|
||||||
session.SourceText = script.ScriptString;
|
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();
|
var bound = script.Bind();
|
||||||
foreach (var error in script.Diagnostics.Errors)
|
foreach (var error in script.Diagnostics.Errors)
|
||||||
{
|
{
|
||||||
|
@ -70,10 +60,7 @@ namespace UpsilonLanguageServer
|
||||||
diag.Add(ConvertToVsCodeDiagnostic(warning));
|
diag.Add(ConvertToVsCodeDiagnostic(warning));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (script.Diagnostics.Errors.Count == 0)
|
session.Bound = bound;
|
||||||
{
|
|
||||||
session.Bound = bound;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
HoverProvider = true,
|
HoverProvider = true,
|
||||||
SignatureHelpProvider = new SignatureHelpOptions("()"),
|
SignatureHelpProvider = new SignatureHelpOptions("()"),
|
||||||
CompletionProvider = new CompletionOptions(true, "."),
|
CompletionProvider = new CompletionOptions(true, ""),
|
||||||
TextDocumentSync = new TextDocumentSyncOptions
|
TextDocumentSync = new TextDocumentSyncOptions
|
||||||
{
|
{
|
||||||
OpenClose = true,
|
OpenClose = true,
|
||||||
|
|
|
@ -10,6 +10,7 @@ using LanguageServer.VsCode.Contracts;
|
||||||
using Upsilon.Binder;
|
using Upsilon.Binder;
|
||||||
using Upsilon.BoundTypes;
|
using Upsilon.BoundTypes;
|
||||||
using Upsilon.Utilities;
|
using Upsilon.Utilities;
|
||||||
|
using Type = Upsilon.BaseTypes.Type;
|
||||||
|
|
||||||
namespace UpsilonLanguageServer.Services
|
namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,10 @@ namespace UpsilonLanguageServer.Services
|
||||||
contents.Append($"\n\nReturns: {fVar.ResultType}");
|
contents.Append($"\n\nReturns: {fVar.ResultType}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (findNode is BoundFunctionExpression fe)
|
||||||
|
{
|
||||||
|
contents.Append($"\n\nReturns: {fe.ReturnType}");
|
||||||
|
}
|
||||||
|
|
||||||
return new Hover()
|
return new Hover()
|
||||||
{
|
{
|
||||||
|
@ -128,71 +133,53 @@ namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
if (Session.Documents.TryGetValue(textDocument.Uri, out var doc) && doc.Bound != null)
|
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);
|
if (nodeIterator.MoveNext())
|
||||||
var findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character - 2);
|
|
||||||
if (findNode is BoundVariableSymbol variableSymbol)
|
|
||||||
{
|
{
|
||||||
var result = await GetListFromVariableSymbol(variableSymbol);
|
var node = nodeIterator.Current;
|
||||||
if (result != null)
|
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 scope = doc.Bound.GetScopeAt(characterPosition);
|
var variables = scope.GetBoundScopeVisibleVariables();
|
||||||
var variables = scope.GetBoundScopeVisibleVariables();
|
if (scope != null)
|
||||||
if (scope != null)
|
{
|
||||||
{
|
return new CompletionList(
|
||||||
return new CompletionList(
|
variables.Select(x =>
|
||||||
variables.Select(x =>
|
{
|
||||||
{
|
var (key, value) = x;
|
||||||
var (key, value) = x;
|
return new CompletionItem(key,
|
||||||
return new CompletionItem(key,
|
CompletionItemKind.Variable, value.Type.ToString(),
|
||||||
CompletionItemKind.Variable, value.Type.ToString(),
|
x.Value.CommentValue == null
|
||||||
x.Value.CommentValue == null
|
? ""
|
||||||
? ""
|
: $"\n\n{string.Join(" \n", value.CommentValue)}");
|
||||||
: $"\n\n{string.Join(" \n", value.CommentValue)}");
|
}));
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new CompletionList(new CompletionItem[0], false);
|
return new CompletionList(new CompletionItem[0], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<CompletionList> GetListFromVariableSymbol(BoundVariableSymbol variableSymbol)
|
private static async Task<CompletionList> GetListFromVariableSymbol(VariableSymbol variableSymbol)
|
||||||
{
|
{
|
||||||
if (variableSymbol.VariableSymbol is FunctionParameterSymbol parameterSymbol &&
|
if (variableSymbol is FunctionParameterSymbol parameterSymbol &&
|
||||||
parameterSymbol.BoundTypeDefinition is UserDataBoundTypeDefinition udBoundDef)
|
parameterSymbol.BoundTypeDefinition is UserDataBoundTypeDefinition udBoundDef)
|
||||||
{
|
{
|
||||||
return new CompletionList(
|
return new CompletionList(
|
||||||
|
@ -203,7 +190,7 @@ namespace UpsilonLanguageServer.Services
|
||||||
$"{value.ActualType}({value.Type})", $"{value.Comment}", null);
|
$"{value.ActualType}({value.Type})", $"{value.Comment}", null);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
if (variableSymbol.VariableSymbol is TableVariableSymbol tableSymbol)
|
if (variableSymbol is TableVariableSymbol tableSymbol)
|
||||||
{
|
{
|
||||||
return new CompletionList(
|
return new CompletionList(
|
||||||
tableSymbol.Variables.Select(x =>
|
tableSymbol.Variables.Select(x =>
|
||||||
|
@ -220,5 +207,33 @@ namespace UpsilonLanguageServer.Services
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue