Skip to content

Replacing tokens when computing completion results is uncertain #2804

@fm-117

Description

@fm-117

When computing completion proposals, more precisely in CodeElementMatcher.MatchCompletionCodeElement, the server may replace the closest token to cursor with a fake UserDefinedWord. This is prone to error as the text from this made-up token is later used to filter proposals and if it was non-alphanumeric, the completion won't find anything.

As far as our unit tests can tell, this behavior is used to prevent completion from returning anything when invoked after a single : or a .: see CompletionAfterBetweenColons and CompletionAfterDotFromTypedDataDef LSR tests.

Removing the token replacing code has no effect except for these 2 tests so we should look for a way to replicate current behavior without having to create those fake tokens.

//The closestToken to cursor as to be added to this codeElement as a UserDefinedWord
if (closestTokenToCursor.TokenType != TokenType.UserDefinedWord)
{
var codeElement = codeElements.LastOrDefault();
if (codeElement != null)
{
//As we are altering our input, keep track of changes for later restore
codeElementsArrangedTokensToRestore.Add(new Tuple<CodeElementWrapper, List<Token>>(codeElement, codeElement.ArrangedConsumedTokens));
codeElement.ArrangedConsumedTokens = codeElement.ArrangedConsumedTokens.ConvertAll(ReplaceClosestTokenToCursor);
}
Token ReplaceClosestTokenToCursor(Token originalToken)
{
return closestTokenToCursor.Equals(originalToken)
? new Token(TokenType.UserDefinedWord, closestTokenToCursor.StartIndex, closestTokenToCursor.StopIndex, closestTokenToCursor.TokensLine)
: originalToken;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions