Support for text completion when requesting complete in the middle of indexer

This commit is contained in:
Deukhoofd 2018-11-29 19:10:32 +01:00
parent 3f88783eec
commit 1760e72117
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 60 additions and 23 deletions

View File

@ -134,36 +134,43 @@ namespace UpsilonLanguageServer.Services
var findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character - 2);
if (findNode is BoundVariableSymbol variableSymbol)
{
if (variableSymbol.VariableSymbol is FunctionParameterSymbol parameterSymbol &&
parameterSymbol.BoundTypeDefinition is UserDataBoundTypeDefinition udBoundDef)
var result = await GetListFromVariableSymbol(variableSymbol);
if (result != null)
{
return new CompletionList(
udBoundDef.Properties.Select(x =>
{
var (key, value) = x;
return new CompletionItem(key, CompletionItemKind.Variable,
$"{value.ActualType}({value.Type})", $"{value.Comment}", null);
}));
}
if (variableSymbol.VariableSymbol is TableVariableSymbol tableSymbol)
{
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);
}));
return result;
}
}
}
else
{
var linePos = doc.SourceText.GetLineStartPos(position.Line);
var scope = doc.Bound.GetScopeAt(linePos + position.Character);
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 variables = scope.GetBoundScopeVisibleVariables();
if (scope != null)
{
@ -183,5 +190,35 @@ namespace UpsilonLanguageServer.Services
return new CompletionList(new CompletionItem[0], false);
}
private static async Task<CompletionList> GetListFromVariableSymbol(BoundVariableSymbol variableSymbol)
{
if (variableSymbol.VariableSymbol is FunctionParameterSymbol parameterSymbol &&
parameterSymbol.BoundTypeDefinition is UserDataBoundTypeDefinition udBoundDef)
{
return new CompletionList(
udBoundDef.Properties.Select(x =>
{
var (key, value) = x;
return new CompletionItem(key, CompletionItemKind.Variable,
$"{value.ActualType}({value.Type})", $"{value.Comment}", null);
}));
}
if (variableSymbol.VariableSymbol is TableVariableSymbol tableSymbol)
{
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);
}));
}
return null;
}
}
}