nvim-puppeteer icon indicating copy to clipboard operation
nvim-puppeteer copied to clipboard

[Bug]: Puppeteer gets in the way when using GraphQL or other tools that require curly braced strings

Open Popkornium18 opened this issue 2 years ago • 6 comments

Bug Description

When using GraphQL in Python you often deal with multiline strings like this:

"""
{
  project(name: "GraphQL") {
    tagline
  }
}
"""

Whenever you change anything on these strings puppeteer will turn them (falsely) into f-strings and won't let you turn them into normal strings again.

A couple of Ideas how to fix/work-around this:

  1. Don't touch multiline strings (breaks legitimate multiline strings)
  2. Try to figure out (using Tree-Sitter, LSP, Linters or something like this) if the resulting f-string actually makes sense or would be bogus. Don't f-stringify if it would result in an error
  3. Detect when the user removed the f so you don't have to fight with puppeteer to get your will

Relevant Screenshot

No response

To Reproduce

No response

neovim version

0.9

Make sure you have done the following

  • [X] I have updated to the latest version of the plugin.

Popkornium18 avatar Oct 25 '23 15:10 Popkornium18

  1. Don't touch multiline strings (breaks legitimate multiline strings)

That's problematic, since you can have multi-line f-strings.

  1. Detect when the user removed the f so you don't have to fight with puppeteer to get your will

Not ideal, since the user can always come back to the string and change it.

  1. Try to figure out (using Tree-Sitter, LSP, Linters or something like this) if the resulting f-string actually makes sense or would be bogus. Don't f-stringify if it would result in an error

something in this regard would be the correct solution. I am not familiar with graphQL, so to implement such a solution, I'd need some sort of specification in which cases {} in a string indicate an f-string and when it does not. Do you have such a documented spec?

chrisgrieser avatar Oct 25 '23 15:10 chrisgrieser

I think a more robust solution would be not to support anything that uses curly braces in strings directly but rather to check if whatever is in the curly-braces is valid python or something known to tree-sitter/LSP.

Popkornium18 avatar Oct 25 '23 16:10 Popkornium18

check if whatever is in the curly-braces is valid python

that won't work, in practice you often (temporarily) have invalid code when you are editing code.

Again, please provide some specification to discern graphql strings from normal strings. Since I am not familiar with graphql, I cannot do much without. Or you could make a PR adding respective treesitter-based conditions, but again, that's something I can't really do myself without having knowledge of graphql

chrisgrieser avatar Oct 25 '23 16:10 chrisgrieser

The current spec can be found here.

I also noticed this problem when writing a python tool that writes RPM macro files which use curly braces to reference variables.

Edit: Common GraphQL uses from within python can be referenced here.

Popkornium18 avatar Oct 25 '23 16:10 Popkornium18

The current spec can be found here.

yeah, that is a bit much, I really think this would be better if someone who actually has knowledge of graphQL would make a PR for this.

chrisgrieser avatar Oct 25 '23 16:10 chrisgrieser

What about a keybind to manually toggle f-strings and a command to disable automatic changes? That would at least give users working on code like this a way to use puppeteer without running into situations where you have to find ways to work around the automatic f-string changes.

Edit: or put simpler: an automatic and a manual mode and a command to switch between them.

Popkornium18 avatar Oct 25 '23 17:10 Popkornium18

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment, for example "bump", and it will be kept open.

github-actions[bot] avatar Aug 02 '24 04:08 github-actions[bot]

This issue has been closed due to inactivity, and will not be monitored.

github-actions[bot] avatar Aug 10 '24 04:08 github-actions[bot]