Extract raw string literal auto-insert logic into reusable service#80871
Merged
Extract raw string literal auto-insert logic into reusable service#80871
Conversation
Co-authored-by: dibarbet <[email protected]>
Co-authored-by: dibarbet <[email protected]>
Co-authored-by: dibarbet <[email protected]>
Copilot
AI
changed the title
[WIP] Extract custom VS behavior into workspace service
Extract raw string literal auto-insert logic into reusable service
Oct 23, 2025
Open
3 tasks
Contributor
|
I can review tomorrow |
dibarbet
reviewed
Oct 24, 2025
| namespace Microsoft.CodeAnalysis.LanguageServer.UnitTests.OnAutoInsert; | ||
|
|
||
| [Trait(Traits.Feature, Traits.Features.AutomaticCompletion)] | ||
| public abstract class AbstractOnAutoInsertTests(ITestOutputHelper testOutputHelper) : AbstractLanguageServerProtocolTests(testOutputHelper) |
| TryGenerateInitialEmptyRawString(caret.Value, cancellationToken) ?? | ||
| TryGrowInitialEmptyRawString(caret.Value, cancellationToken) ?? | ||
| TryGrowRawStringDelimiters(caret.Value, cancellationToken); | ||
| var root = document.GetRequiredSyntaxRootSynchronously(cancellationToken); |
Contributor
There was a problem hiding this comment.
This is a problem for me. A core idea in the original code was that it did nothing related to syntax unless it first had verified textually that it was in a reasonable position to do so (like checking if it was around quotes). This prevented parsing the syntax tree for most edits.
I don't want to roll that logic back. Can the service just take the document and defer creating the root until needed?
| var textChange = service.GetTextChangeForQuote(root, text, caret.Value.Position); | ||
|
|
||
| if (textChangeOpt is not TextChange textChange) | ||
| if (textChange is null) |
Contributor
There was a problem hiding this comment.
seems like you could keep this code :)
Member
src/Features/CSharp/Portable/RawStringLiteral/CSharpRawStringLiteralOnAutoInsertService.cs
Show resolved
Hide resolved
CyrusNajmabadi
approved these changes
Oct 24, 2025
Contributor
CyrusNajmabadi
left a comment
There was a problem hiding this comment.
tentatively approving, since hte overall change is good. just please change to defer syntaxroot acquisition until needed.
This was referenced Oct 30, 2025
davidwengier
added a commit
to dotnet/razor
that referenced
this pull request
Nov 3, 2025
Three things I've been tracking from Roslyn: 1. Auto insert support for raw string literals: dotnet/roslyn#80871 2. Line Folding Only support in VS Code: dotnet/roslyn#80955 (fixes #12414) * We already did this in our folding range response anyway 3. Allow FormattingLogTest can use real types, and remove our temporary equivalent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Resolves #68537 by extracting the custom Visual Studio behavior for raw string literal auto-insertion into a workspace service that can be shared between the VS command handler and LSP OnAutoInsert handler.
Problem
Previously, the logic for automatically expanding raw string literals when typing quote characters was hardcoded in the VS-specific command handler (
RawStringLiteralCommandHandler_TypeChar.cs). This made it impossible to provide the same functionality through LSP for other editors.Solution
This PR extracts the raw string literal expansion logic into a new workspace service:
Created
IRawStringLiteralOnAutoInsertServiceinterface in the Features layerTextChangeif raw string expansion should occurnullif no special handling is neededImplemented
CSharpRawStringLiteralOnAutoInsertServicein the C# Features layer""+"→"""""""""$$"""+"→""""$$"""""""$$ content """+"→"""" content """"Updated
RawStringLiteralCommandHandler_TypeChar.csto use the serviceIntegrated with
OnAutoInsertHandler.csImpact
The service follows Roslyn's standard patterns with
[ExportLanguageService]and proper MEF construction.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/dotnet/roslyn/issues/68537curl -s REDACTED(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.