Skip to content

Fix LSP completions when all items have default commit characters#55262

Merged
dibarbet merged 3 commits intodotnet:mainfrom
dibarbet:lsp_completion_null_ref
Jul 30, 2021
Merged

Fix LSP completions when all items have default commit characters#55262
dibarbet merged 3 commits intodotnet:mainfrom
dibarbet:lsp_completion_null_ref

Conversation

@dibarbet
Copy link
Member

Fixes an exception stack trace seen in https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1362284

Also fixes behavior of promotion of commit characters to the list to include default commit characters

@dibarbet dibarbet requested a review from a team as a code owner July 30, 2021 02:43
@ghost ghost added the Area-IDE label Jul 30, 2021
// '<' should not filter the completion list, even though it's in generic items like IList<>
var generalBaseline = CompletionItemRules.Default.
WithFilterCharacterRule(CharacterSetModificationRule.Create(CharacterSetModificationKind.Remove, '<')).
WithCommitCharacterRule(CharacterSetModificationRule.Create(CharacterSetModificationKind.Add, '<'));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

< is part of the default commit characters set and doesn't need to be specified here as best I can tell, cc @genlu

if (commitCharacters == null)
{
continue;
// The commit characters on the item are null, this means the commit characters are actually
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes two issues

  1. We would hit a null ref on line 384 if all of the completion items had default commit characters (aka the commit characters field on every completion item was null).
  2. The algorithm is trying to promote the most used commit character set onto the list itself, then null out commit chars on any completion item using that set to save serialization. However this skipped originally null commit chars (indicating that the item should use commit chars from Initialize). This resulted in the second most used commit char set being promoted to the CompletionList.CommitChars, and both items with default chars and second most used commit chars having their commit chars nulled out. This means for items that originally had null commit chars (aka use default from Initialize), the client would use the wrong commit chars from the completion list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resulted in the second most used commit char set being promoted

lol 🤦‍♂️

Good find!

@dibarbet dibarbet enabled auto-merge July 30, 2021 18:11
@dibarbet dibarbet merged commit 65ee073 into dotnet:main Jul 30, 2021
@ghost ghost added this to the Next milestone Jul 30, 2021
@dibarbet dibarbet modified the milestones: Next, 17.0.P4 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants