nvim-puppeteer
nvim-puppeteer copied to clipboard
[Bug]: Puppeteer gets in the way when using GraphQL or other tools that require curly braced strings
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:
- Don't touch multiline strings (breaks legitimate multiline strings)
- 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
- 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.
- Don't touch multiline strings (breaks legitimate multiline strings)
That's problematic, since you can have multi-line f-strings.
- 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.
- 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?
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.
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
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.
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.
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.
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.
This issue has been closed due to inactivity, and will not be monitored.