-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
IDE response to raw string literals #58846
IDE response to raw string literals #58846
Conversation
src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxTreeExtensions.cs
Outdated
Show resolved
Hide resolved
|
||
return position == token.Span.End && | ||
(token.Span.Length == startLength || (token.Span.Length > startLength && !token.ToString().EndsWith(string.Concat(tokenStart)))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hrmmmmmmm something seems fishy here. we likely want to talk about what's going on here and if it's necessary. i'm guessing we can answer this question without having to stringigy the token. note: the existing code seems uber suspect to me as well :)
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxTreeExtensions.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxTreeExtensions.cs
Outdated
Show resolved
Hide resolved
overall seems fine. tests plz :) |
if (token.IsKind(SyntaxKind.InterpolatedStringStartToken) || | ||
token.IsKind(SyntaxKind.InterpolatedStringEndToken) || | ||
token.IsKind(SyntaxKind.InterpolatedStringTextToken)) | ||
token.IsKind(SyntaxKind.InterpolatedStringTextToken) || | ||
token.IsKind(SyntaxKind.InterpolatedSingleLineRawStringStartToken) || | ||
token.IsKind(SyntaxKind.InterpolatedSingleLineRawStringEndToken) || | ||
token.IsKind(SyntaxKind.InterpolatedMultiLineRawStringStartToken) || | ||
token.IsKind(SyntaxKind.InterpolatedMultiLineRawStringEndToken)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd need another conditional branch for MultiLineRawStringLiteral
and SingleLineRawStringLiteral
here as well and coordinate the F1 keyword to be used with dotnet/docs team.
if (token.IsKind(SyntaxKind.MultiLineRawStringLiteral) || token.IsKind(SyntaxKind.SingleLineRawStringLiteral))
{
text = "RawStringLiteral_CSharpKeyword"; // or """_CSharpKeyword
return true;
}
if (token.IsKind(SyntaxKind.InterpolatedStringStartToken) || | ||
token.IsKind(SyntaxKind.InterpolatedStringEndToken) || | ||
token.IsKind(SyntaxKind.InterpolatedStringTextToken)) | ||
token.IsKind(SyntaxKind.InterpolatedStringTextToken) || | ||
token.IsKind(SyntaxKind.InterpolatedSingleLineRawStringStartToken) || | ||
token.IsKind(SyntaxKind.InterpolatedSingleLineRawStringEndToken) || | ||
token.IsKind(SyntaxKind.InterpolatedMultiLineRawStringStartToken) || | ||
token.IsKind(SyntaxKind.InterpolatedMultiLineRawStringEndToken)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider refactoring this long list of syntax kinds into an extension in https://github.com/dotnet/roslyn/blob/main/src/Compilers/CSharp/Portable/CSharpExtensions.cs
@@ -143,7 +143,8 @@ public static IEnumerable<SyntaxKind> GetPreprocessorKeywordKinds() | |||
|
|||
public static bool IsPunctuation(SyntaxKind kind) | |||
{ | |||
return kind >= SyntaxKind.TildeToken && kind <= SyntaxKind.QuestionQuestionEqualsToken; | |||
return kind >= SyntaxKind.TildeToken && kind <= SyntaxKind.QuestionQuestionEqualsToken || | |||
kind is SyntaxKind.RawInterpolationOpenToken || kind is SyntaxKind.RawInterpolationCloseToken; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: tehse tokens kinds are gone now. sorry!
} | ||
|
||
[WpfFact, Trait(Traits.Feature, Traits.Features.SplitStringLiteral)] | ||
public void TestMissingInRawStringLiteralInterpolation_MultiBrace() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test name seems wrong...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the intender is applying one too many spaces for interpolated raw strings.
// case 1: $"""$$ | ||
// """ | ||
// case 2: $""" | ||
// text$$ | ||
// """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// case 1: $"""$$ | |
// """ | |
// case 2: $""" | |
// text$$ | |
// """ | |
// case 1: $"""$$ | |
// """ | |
// case 2: $""" | |
// text$$ | |
// """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the indenter isn't setting where the delimiter goes here. Instead, it's stating where the caret should go when enter is typed above teh delimeter. In that case, the caret is indented the same amount as the final string.
…ing enter in a delimiter.
Merging in. Note that we still need tests around indentation and splitting of raw strings. I will add those myself in a followup. |
The comment isn't stating that we will indent the end quote that much, just that we'll align the caret with the indentation of the end quote.
Fixed the following bugs:
{ x }
should be{x}
)Added tests for:
TO-DO:
$$"""{{x}}"""
. This is difficult with the current test infrastructure since$$
is often considered the cursor position.Relatest to test plan #55306