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

Code inside interpolated raw literals is not formatted #1308

Closed
RReverser opened this issue Jul 26, 2024 · 3 comments
Closed

Code inside interpolated raw literals is not formatted #1308

RReverser opened this issue Jul 26, 2024 · 3 comments

Comments

@RReverser
Copy link

RReverser commented Jul 26, 2024

Input:

Minimal repro:

        var extensions =
                        $$"""
                                {{
                          $"""
                          nested
                          """
                                }}
                                """;

Output:

var extensions = $$"""
                                {{
                          $"""
                          nested
                          """
                                }}
                                """;

Expected behavior:

I saw that raw string literal formatting was implemented in #975 / #977, but for some reason it breaks when there are nested raw literals like in the example above (those are fairly common in complex codebase).

I'd expect those strings to be reindented just like they're when no nesting occurs, probably to something like this:

var extensions = $$"""
    {{
      $"""
      nested
      """
    }}
    """;
RReverser added a commit to clockworklabs/SpacetimeDB that referenced this issue Jul 29, 2024
Raw string literals automatically ignore indentation and can be correctly auto-formatted (although there are still some issues, eg belav/csharpier#1308), which makes them more suitable for multiline templates.
@RReverser
Copy link
Author

@belav Looking at changes in #977, it seems that the issue is that it never accounted for interpolated raw strings to begin with?

@RReverser
Copy link
Author

Yeah looks like it's not just nested raw literals; no formatting whatsoever currently happens inside interpolated raw strings. An even simpler example:

        var extensions =
                        $$"""
                                {{
                          foo
                                    .bar
                                 .baz(
                               )
                                }}
                                """;

@RReverser RReverser changed the title Nested raw literals are not reindented Code inside interpolated raw literals is not formatted Aug 6, 2024
@RReverser
Copy link
Author

Ah and now that I figured it's a general issue, I can see it's a duplicate of #1136, so closing.

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

No branches or pull requests

1 participant