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; |
|
} |
When computing completion proposals, more precisely in
CodeElementMatcher.MatchCompletionCodeElement, the server may replace the closest token to cursor with a fakeUserDefinedWord. 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.: seeCompletionAfterBetweenColonsandCompletionAfterDotFromTypedDataDefLSR 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.
TypeCobol/TypeCobol.LanguageServer/Completion Factory/CodeElementMatcher.cs
Lines 93 to 109 in 930ed19