Skip to content

Support MatchPriority comparison in LSP completion#83164

Merged
ToddGrun merged 3 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/MatchPriority
Apr 20, 2026
Merged

Support MatchPriority comparison in LSP completion#83164
ToddGrun merged 3 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/MatchPriority

Conversation

@ToddGrun
Copy link
Copy Markdown
Contributor

@ToddGrun ToddGrun commented Apr 14, 2026

When using C# LSP-based completion, typing "nu" incorrectly selects nuint instead of null. In Roslyn's native (non-LSP) completion, null is correctly selected.

Old Behavior New Behavior
image image

Approach

This PR adds a _vs_matchPriority VS-internal extension property to VSInternalCompletionItem so the full numeric MatchPriority value is available to the VS client for tiebreaking during best-match selection.

There are two companion PRs for to support this change:

1: VSLanguageServerClient PR
2: VSEditor PR

Microsoft Reviewers: Open in CodeFlow

When using C# LSP-based completion, typing "nu" incorrectly selects nuint instead of null. In Roslyn's native (non-LSP) completion, null is correctly selected.

Changes

This PR adds a _vs_matchPriority VS-internal extension property to VSInternalCompletionItem so the full numeric MatchPriority value is available to the VS client for tiebreaking during best-match selection.

There is a companion VsLanguageServerClient PR (https://devdiv.visualstudio.com/DevDiv/_git/VSLanguageServerClient/pullrequest/728272) that adds a custom IAsyncCompletionItemManager which consumes _vs_matchPriority as a tiebreaker in best-match selection.
Copy link
Copy Markdown
Member

@dibarbet dibarbet left a comment

Choose a reason for hiding this comment

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

Will this break anything if we merge before the client side change?

Comment thread src/LanguageServer/Protocol/Handler/Completion/CompletionResultFactory.cs Outdated
Copy link
Copy Markdown
Member

@dibarbet dibarbet left a comment

Choose a reason for hiding this comment

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

Actually... is this not something we could solve in the base LSP completion with sort text? E.g. the sort text for null puts it above nunit?

@dibarbet
Copy link
Copy Markdown
Member

Actually... is this not something we could solve in the base LSP completion with sort text? E.g. the sort text for null puts it above nunit?

Discussed offline - passing match priority allows the server to modify selection, without changing list order. This is technically possible with the base lsp spec using preselect, but requires the server to opt-in to completion requests on every key stroke (isIncomplete)

@ToddGrun
Copy link
Copy Markdown
Contributor Author

I don't think so (will verify), but was planning on waiting for the work on the VS LSP side to get approved and merged before proceeding on this.


In reply to: 4108793162

@ToddGrun
Copy link
Copy Markdown
Contributor Author

I don't think so (will verify)

Verified that the behavior isn't bad without the VSEditor or VSLanguageServerClient side.

Both VSEditor and VSLanguageServerClient have been merged (VSEditor is already in IntMain, VSLanguageServerClient will be there in the next day or two). Going ahead and merging the Roslyn side and this should all work once they meet in VS Main.

@ToddGrun ToddGrun merged commit 0610f7c into dotnet:main Apr 20, 2026
25 checks passed
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Apr 20, 2026
333fred added a commit to 333fred/roslyn that referenced this pull request Apr 20, 2026
…ture

* upstream/main: (77 commits)
  Fix ArgumentNullException in VB Edit and Continue (dotnet#83250)
  Fix property pattern completion filtering out member being edited (dotnet#83230)
  Add branch merge skill (dotnet#83229)
  [main] Source code updates from dotnet/dotnet (dotnet#83215)
  Support MatchPriority comparison in LSP completion (dotnet#83164)
  Have CompleteStatement handle EOF statements (dotnet#83205)
  Minor cleanups related to attributes in VB (dotnet#83206)
  Simplify
  Address additional PR feedback
  Port remaining unit test projects to Linux (dotnet#83153)
  Unsafe evolution: allow unsafe property accessors (dotnet#83115)
  Address PR review feedback
  Allow cohost rename in Razor source-generated docs
  Refine code review skill (dotnet#82666)
  Review feedback
  Allow creation of DocumentUri instances even if System.Uri cannot parse it
  Improve TextLine and line table performance by packing existing data into unused bits (dotnet#83000)
  Skip TestFindReferencesAsync_UsingAlias on non-Windows platforms (dotnet#83188)
  [main] Source code updates from dotnet/dotnet (dotnet#83174)
  fix comment
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants