-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Format raw string literals indentation #975
Comments
This won't be super straightforward like I was hoping, but there is code somewhere else that does something similar if I can track it down. I'm thinking that if someone already has the raw string literal dedented completely, that it should stay where it is. Something like this public class ClassName
{
public string M()
{
return """
This is a string that
spans multiple lines
and is really wide so someone dedented it completely
""";
return """
Also keep in mind
not to dedent this line
and this as well
so really just trimming the same amount off each line, which maybe is in multiline comments
""";
}
} |
Scanning through all the string literals in /~https://github.com/belav/csharpier-repos/pull/91/files there is a mix of "dedent completely" and "indent about one more than the previous line". Possibly more of the later. |
One objective argument FOR reformatting is that CSharpier might change indentation of surrounding lines. I personally would make no exception as the indented string just looks better and some editors don't handle code folding properly with those dedented strings. But if you want to make an exception when the raw string indentation is exactly zero, I guess that's reasonable too. (This is a slightly tricky feature indeed, as the spec. of raw strings is not trivial. You have to ignore empty lines, keep extra indentation on further lines and consider some literals might be invalid: less indented later lines, text on first or last line...) |
After seeing this case in the spec, I think we definitely want to have an exception for the end delimiter having zero indentation. If someone wants the resulting string to have a specific indentation, they can easily do it like this. Then they can copy/paste the raw string literal and it has the exact indentation they expect. var xml = """
<element attr="content">
<body>
</body>
</element>
"""; If that was reformatted and indented like this, they would lose that ability. var xml = """
<element attr="content">
<body>
</body>
</element>
"""; I did get it close to working in the linked PR, just have to deal with tabs and an edge case or two. |
* This isn't correct, but I wanna see what 3rd party code does closes #975 * Getting a basic version of this working * Handling everything except for tabs * format files * Fixing issues with tabs + passing options around * self code review * more tweaks * formatting files --------- Co-authored-by: Lasath Fernando <devel@lasath.org>
… (#1106) * fixing some issues with the recent raw string literal changes * Getting this mostly figured out * Fixing issues with interpolated raw strings * Fixing issues with interpolated raw strings * Update InterpolatedStringExpressions.test * remove using
CSharpier (as of 0.25.0) does not modify indentation of string literals.
The following code is left as-is:
I think it would be desirable to standardize the indentation of raw string literals to 1 indent more than the previous line.
I would expect the following result, which represents exactly the same string as before:
The text was updated successfully, but these errors were encountered: