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

fmt dedent only works if first multiline string character is a newline #1251

Open
polirritmico opened this issue Nov 7, 2024 · 3 comments
Open

Comments

@polirritmico
Copy link
Contributor

polirritmico commented Nov 7, 2024

Description

Hi! Don't know if this is the designed behavior or some kind of bug but if I have this markdown snippet, then the default de-indentation work without problems:

return {
  s(
    { trig = "prettierignore", desc = "Prettier format ignore region" },
    fmt(
      [=[
      <!-- prettier-ignore-start -->
      {}
      <!-- prettier-ignore-end -->
      ]=],
      {
        i(1),
      }
    )
  ),
}

output:

_ represent the cursor position when expanded

<!-- prettier-ignore-start -->
_
<!-- prettier-ignore-end -->

But if [=[text is used, then it doesn't work:

return {
  s(
    { trig = "prettierignorebad", desc = "Prettier format ignore region" },
    fmt(
      [=[<!-- prettier-ignore-start -->
      {}
      <!-- prettier-ignore-end -->
      ]=],
      {
        i(1),
      },
      { dedent = true } -- this made no difference
    )
  ),
}

output:

<!-- prettier-ignore-start -->
      _
      <!-- prettier-ignore-end -->

I'm opening this issue cause there is no mention for this in the docs (at least in the dedent description :h luasnip-extras-fmt, /dedent) and took me some time to figure out what was happening.

Possible solutions

  • Add to the docs that the dedent feature requires the multiline string to begin with a newline
  • dedent the multiline string even for this cases: [=[no newline char

Regards

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Nov 7, 2024

I think this is somewhat expected, if "remove common indent from the snippet's lines" is taken very literally: the first line does not have any whitespace in front of the string, so the "common indent" can be at most an empty string, and the subsequent lines' indentation is thus treated as not indentation but just leading whitespace.

I'd appreciate if you'd add this as a kind of hint to the documentation, if not I can also find some time to do so :)

@polirritmico
Copy link
Contributor Author

polirritmico commented Nov 9, 2024

Yes, if you put it in those terms, then it's kind of obvious 😅.

What about this?:

 - `dedent`: remove indent common to all lines in `format`. Again, makes
        passing multiline-strings a bit nicer (default true). (Remember to
        add the indentation on the first line too.)

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Nov 14, 2024

I think you can even go so far as showing your example, shouldn't hurt to be explicit here :D

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

2 participants