Skip to content

Fix embedded language classification inside multi-line string #78588

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

Merged
merged 1 commit into from
May 15, 2025

Conversation

dibarbet
Copy link
Member

@dibarbet dibarbet commented May 15, 2025

Resolves #74809

image

// two";
// The check below ensures we correctly return the spans in the correct order, i.e. 'one', '""', 'two'.
while (spanIndex + 1 < originalClassifiedSpans.Count &&
textSpan.Contains(originalClassifiedSpans[spanIndex + 1].TextSpan))
Copy link
Member Author

@dibarbet dibarbet May 15, 2025

Choose a reason for hiding this comment

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

this was buggy when there was a multi-line classification that had another multi-line classification inside of it. For example, in

// lang=c#-test
const string Code = @"
class C {
    //
}";

the entire (multi-line) string is classified as roslyn-test code, but there are also verbatim string classifications for all the whitespace in between, which also spans multiple lines (e.g from after the { to before the //).

As we create new spans line by line for roslyn-test classification, this code tries to insert classifications that are on the same line into the set, before it proceeds to the next line (to keep everything ordered). But that only happens for single line spans. If there is a multi-line span inside the one we're breaking up, this exits and does not add it until after the entire original multi-line is added, causing the spans to be out of order.

Instead of having this complexity, we can just break up the multi-line spans and sort the set afterwards.

@dibarbet dibarbet marked this pull request as ready for review May 15, 2025 01:25
@dibarbet dibarbet requested a review from a team as a code owner May 15, 2025 01:25
@dibarbet dibarbet merged commit 0eb510a into dotnet:main May 15, 2025
26 checks passed
@dibarbet dibarbet deleted the fix_semantic_tokens_embedded branch May 15, 2025 18:31
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 15, 2025
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.

InvalidOperationException in SemanticTokensHelpers when applying embedded classification on verbatim string
2 participants