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

@ -133,6 +133,64 @@ namespace UpsilonLanguageServer.Services
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 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)
{
return new CompletionList(
variables.Select(x =>
{
var (key, value) = x;
return new CompletionItem(key,
CompletionItemKind.Variable, value.Type.ToString(),
x.Value.CommentValue == null
? ""
: $"\n\n{string.Join(" \n", value.CommentValue)}");
}));
}
}
}
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)
@ -158,29 +216,8 @@ namespace UpsilonLanguageServer.Services
: $"{string.Join(" \n", value.CommentValue)}", null);
}));
}
}
}
else
{
var linePos = doc.SourceText.GetLineStartPos(position.Line);
var scope = doc.Bound.GetScopeAt(linePos + position.Character);
var variables = scope.GetBoundScopeVisibleVariables();
if (scope != null)
{
return new CompletionList(
variables.Select(x =>
{
var (key, value) = x;
return new CompletionItem(key,
CompletionItemKind.Variable, value.Type.ToString(),
x.Value.CommentValue == null
? ""
: $"\n\n{string.Join(" \n", value.CommentValue)}");
}));
}
}
}
return new CompletionList(new CompletionItem[0], false);
return null;
}
}