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

Cleanup CompletionTriggerAndCommitCharacters #11600

Merged

Conversation

DustinCampbell
Copy link
Member

Recently, I was taking a look at completion performance and noticed that CompletionTriggerAndCommitCharacters has gotten into a halfway state where it's sometimes accessed statically, and sometimes as an instance. This change refactors CompletionTriggerAndCommitCharacters to be fully instance-based and cleans it up significantly.

Because this type only has a single dependency in Visual Studio, it's a bit overkill to include it in the MEF composition. Instead, that dependency (CohostDocumentCompletionEndpoint) can import LanguageServerFeatureOptions and create an instance of CompletionTriggerAndCommitCharacters.
Rather than directly exposing a set, this change adds instance methods to test for valid C# triggers.
Rather than directly exposing a set, this change adds instance methods to test for valid Razor triggers.
Rather than directly exposing a set, this change adds an instance method to test for the Razor delegation trigger character (i.e. '@').
Rather than directly exposing a set, this change adds instance methods to test for valid delegation triggers.

Note this change requires a bit of a test change, but I think it's an improvement since the original test was verifying a Razor scenario that could never happen.
Rather than directly exposing a set, this change adds instance methods to test for valid HTML triggers.
This change transforms CompletionTriggerAndCommitCharacters from being a partly static and partly instance service to being fully instance-based. Here is a summary of the changes:

- All collections are now private and operations on them are exposed via instance methods.
- I've switched from FrozenSet<string> to HashSet<char>. Honestly, I doubt we were getting much value from FrozenSet<string> for strings with the same length.
- All initialization is performed in the constructor.
- Accessing AllTriggerCharacters or AllCommitCharacters returns a new array each time to avoid modifying the original array.
- The Razor transition character ('@') is now a constant rather than a set with a single element.
@DustinCampbell DustinCampbell requested a review from a team as a code owner March 10, 2025 20:18
Rather than returning mutable array copies from AllTriggerCharacters and AllCommitCharacters, return an ImmutableArray and let the call sites make the copies as needed.
@DustinCampbell DustinCampbell merged commit e0517b8 into dotnet:main Mar 10, 2025
17 checks passed
@DustinCampbell DustinCampbell deleted the cleanup-triggers-and-commit-chars branch March 10, 2025 23:04
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Mar 10, 2025
ryzngard added a commit to dotnet/vscode-csharp that referenced this pull request Mar 13, 2025
[View Complete Diff of Changes](https://github.com/dotnet/razor/compare/2798396c3481573aa49f9c792179ebbb5e183dca...c0bd75d99369adcd5a2f7e1f1ac42bee8a3bf619?w=1)
  * Move VS Code To Pull Diagnostics (#11602) (PR: [#11602](dotnet/razor#11602))
  * Upgrade to net9 (#11535) (PR: [#11535](dotnet/razor#11535))
  * Cleanup CompletionTriggerAndCommitCharacters (#11600) (PR: [#11600](dotnet/razor#11600))
  * Add constraints to CaptureParameters method (#11530) (PR: [#11530](dotnet/razor#11530))
  * [main] Update dependencies from dotnet/source-build-reference-packages (#11598) (PR: [#11598](dotnet/razor#11598))
  * [FUSE] Layout mapping (#11567) (PR: [#11567](dotnet/razor#11567))
  * Stop running cohosting tests with and without FUSE (#11592) (PR: [#11592](dotnet/razor#11592))
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