Skip to content

Better handle attribute snippet completion in components#12281

Merged
ToddGrun merged 3 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/ExtraEqualsInsertedInCompletion
Oct 6, 2025
Merged

Better handle attribute snippet completion in components#12281
ToddGrun merged 3 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/ExtraEqualsInsertedInCompletion

Conversation

@ToddGrun
Copy link
Contributor

Better handle attribute snippet completion in components

This addresses a scenario where completion commit would insert an extra '=' inside the attribute value. For example, committing "@​ref" via typing '=' in this code

<p @re />

below would end up with the following document contents:

<p @ref="=" />

Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2581843

2) Break apart snippet context detection
3) Make local functions static
2) Add a couple statics for common IA collections
… to when creating a commit character for "="

2) Have the AddCompletion method return a RazorCommitCharacter instead of a string, to indicate whether the commit should insert the commit character
3) Add a couple more statics that are commonly used.
4) Add test
@ToddGrun ToddGrun requested a review from a team as a code owner September 29, 2025 23:11
@ToddGrun ToddGrun changed the title Dev/toddgrun/extra equals inserted in completion Better handle attribute snippet completion in components Sep 29, 2025
@ToddGrun
Copy link
Contributor Author

ToddGrun commented Oct 1, 2025

@dotnet/razor-tooling ptal

Copy link
Member

@chsienki chsienki left a comment

Choose a reason for hiding this comment

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

LGTM, but may want to wait for @davidwengier to take a look too

Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

It would be really good if you could do a quick test of this and #12271 in VS Code to make sure nothing regresses there. Feels like this area of completion keeps changing, and I wonder if we're accidentally yo-yo-ing between working in VS, and VS Code, and fixing for one breaks the other. Or we just have lots of little bugs. I'd believe either one tbh

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Oct 6, 2025

It would be really good if you could do a quick test of this and #12271 in VS Code to make sure nothing regresses there. Feels like this area of completion keeps changing, and I wonder if we're accidentally yo-yo-ing between working in VS, and VS Code, and fixing for one breaks the other. Or we just have lots of little bugs. I'd believe either one tbh

OK, I've verified in a vscode with these changes:

  1. completion still works (and thus Ensure RazorVSInternalCompletionParams is used for serialization of completion requests #12271 appears fine)
  2. attribute completion by typing "@ke=" doesn't commit to "@key="="" as it doesn't without this change. Unfortunately, it has the same behavior of not committing the attribute name, but that seems to be the normal behavior for other attributes too (both with and without this change)

@ToddGrun ToddGrun merged commit c73c7e4 into dotnet:main Oct 6, 2025
11 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 6, 2025
@davidwengier
Copy link
Member

Awesome, thank you <3

2. Unfortunately, it has the same behavior of not committing the attribute name, but that seems to be the normal behavior for other attributes too (both with and without this change)

Yeah, = is not a commit character in VS Code (#11681 and #12177) so if this nothing has regressed and re-introduced it, then that's a win

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.

3 participants