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,12 +60,9 @@ 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)
|
||||||
{
|
{
|
||||||
diag.Add(new Diagnostic(DiagnosticSeverity.Error,
|
diag.Add(new Diagnostic(DiagnosticSeverity.Error,
|
||||||
|
|
|
@ -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()
|
||||||
{
|
{
|
||||||
|
@ -127,21 +132,6 @@ namespace UpsilonLanguageServer.Services
|
||||||
public async Task<CompletionList> Completion(TextDocumentIdentifier textDocument, Position position, CompletionContext context)
|
public async Task<CompletionList> Completion(TextDocumentIdentifier textDocument, Position position, CompletionContext context)
|
||||||
{
|
{
|
||||||
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 findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character - 2);
|
|
||||||
if (findNode is BoundVariableSymbol variableSymbol)
|
|
||||||
{
|
|
||||||
var result = await GetListFromVariableSymbol(variableSymbol);
|
|
||||||
if (result != null)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
var linePos = doc.SourceText.GetLineStartPos(position.Line);
|
var linePos = doc.SourceText.GetLineStartPos(position.Line);
|
||||||
var characterPosition = linePos + position.Character;
|
var characterPosition = linePos + position.Character;
|
||||||
|
@ -154,13 +144,12 @@ namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
node = nodeIterator.Current;
|
node = nodeIterator.Current;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node is BoundFullStopIndexExpression indexExpression)
|
if (node is BoundFullStopIndexExpression indexExpression)
|
||||||
{
|
{
|
||||||
var expression = indexExpression.Expression;
|
var expression = indexExpression.Expression;
|
||||||
if (expression.Kind == BoundKind.VariableExpression)
|
var variableSymbol = ResolveVariable(expression);
|
||||||
{
|
var result = await GetListFromVariableSymbol(variableSymbol);
|
||||||
var variableExpression = (BoundVariableExpression)expression;
|
|
||||||
var result = await GetListFromVariableSymbol(variableExpression.Variable);
|
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
|
@ -169,7 +158,6 @@ namespace UpsilonLanguageServer.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
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)
|
||||||
|
@ -186,13 +174,12 @@ namespace UpsilonLanguageServer.Services
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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