Skip to content

Conversation

@davidwengier
Copy link
Member

Fixes #11840

Two main bits to this change:

  1. Roslyn uses a command to perform text edits in VS Code, so this extends our text edit mapping to support that
  2. Roslyn uses the completion list ItemDefaults.Data for VS Code, and all of our data merging and wrapping didn't support it

I broke things up into lots of commits because it was lots of little changes in lots of places, so might be easier to review that way.

The SingleOrDefault here is running on a non-nullable TextChange, so the "default" result was `default(TextChange)` but all the callers, which get back `TextChange?`, were checking for null.
Sometimes resolve doesn't add an edit, but allowing that in tests means we can't validate that we expect a TextEdit, and ensuring we don't regress that is more important
// rather than the one LSP knows about.
if (resolvedCompletionItem.Command is
{
CommandIdentifier: "roslyn.client.completionComplexEdit",
Copy link
Member

Choose a reason for hiding this comment

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

Consider lifting this to a const, if we can't reference the const in Roslyn.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Will do this as a follow up, along with #11911 (comment), since both will require dual, or at least timed, insertion fun.

if (resolvedCompletionItem.Command is
{
CommandIdentifier: "roslyn.client.completionComplexEdit",
Arguments: [TextDocumentIdentifier, TextEdit complexEdit, _, int nextCursorPosition] args
Copy link
Member

Choose a reason for hiding this comment

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

Would it be useful to add a Debug.Assert somewhere to validate the number of arguments and their types? That would shine a light if Roslyn ever changes the shape of the data for this command.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. In fact, it's probably worth making it a log message so we get user reports (though I'll have to add another parameter to this method 😛)

@davidwengier davidwengier merged commit 74cb149 into dotnet:main Jun 12, 2025
11 checks passed
@davidwengier davidwengier deleted the VSCodeCohostOverrideCompletion branch June 12, 2025 03:54
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 12, 2025
davidwengier added a commit that referenced this pull request Jun 18, 2025
Razor side of dotnet/roslyn#78949

Two followups from previous PRs:
* Export formatting options for Razor testing:
#11911 (comment)
* Share const for complex edit command name:
#11938 (comment)

Won't build, of course, without the above PR merged and packages
referenced
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VS Code] [Cohosting] Override completion doesn't work

3 participants