Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 30, 2021

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
@@ -49,8 +49,7 @@ static CompletionItemRules MakeRule((bool importDirective, bool preselect, bool
{
// '<' 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

@@ -365,7 +366,9 @@ static void PromoteCommonCommitCharactersOntoList(LSP.VSCompletionList completio
var commitCharacters = completionItem.CommitCharacters;
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
Contributor

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