-
Notifications
You must be signed in to change notification settings - Fork 2
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 support #21
Comments
Hey, currently there is no plan for adding formatting support, but it would be nice to have. If i would add it i think i would like it be style-"preserving", ex make white space like new lines affect formatting, also placement of comments might be a bit tricky. To do this i think jq-lsp would have to use a parser that includes whitespace and comment, the current gojq based parser is not suitable for this. BTW have you looked at https://github.com/noperator/jqfmt? Also maybe this jqjq issue can be interesting wader/jqjq#8 (there is a jqjq branch with an unfinished AST to string function) |
Oh, I haven't looked at jqfmt. It looks like jqfmt is simple to be integrated to jq-lsp, right? |
https://github.com/noperator/jqfmt?tab=readme-ov-file#to-do |
Not sure how well the current jqfmt would work as a formatter to use while writing jq code. I have a feeling it might be a bit too aggressive with reformatting, as mentioned above i would like to have something that is a bit style aware. And also not sure how well it handles invalid syntax? also seem to strip comments atm $ jqfmt <<EOT
heredoc> # comment
heredoc> 1+2
heredoc> EOT
1 + 2 |
I asked about it some years ago itchyny/gojq#62 (comment) maybe could happen if someone would take on the task of doing it in a nice way and also convince itchyny. I think it would require quite a bit of changes to the parser and also tricky heuristics how to preserve things. But similar things has been done for other languages so it's probably technically possible. I would probably develop it independently of gojq first, maybe using a tree-sitter gramma etc? |
It shouldn't happened. Is it a bug? |
I would say so, but might be tricky to fix because of how gojq's parser work. Comments can be in many places so it's tricky to get them into an AST, maybe one would need another kind of syntax tree that is more suitable for formatting than compiling/evaluating. |
the indent of
def
just like python'sdef
. the indent of|
just like sh's pipe.TIA!
The text was updated successfully, but these errors were encountered: