nvim-jqx
nvim-jqx copied to clipboard
Work with buffer (not file)
It would be great if jqx could work with the buffer. My use case is to use with vim-rest-console. It would need following options :
- [ ] allow to specify custom file type in
populate_qf
(or all ft) ; - [ ] don't always use local file in https://github.com/gennaro-tedesco/nvim-jqx/blob/6e179064b580795770a4bf0c10d19ea53fd27357/lua/nvim-jqx/jqx.lua#L54
- [ ] allow to run JqxQuery on the buffer instead of current_file
Thx for the great work !
Could you please elaborate a little on your request, so that I could understand better?
jqx could work with the buffer
what do you have in mind here? An empty buffer or a buffer populated with some text and no filetype specified (I suspect the latter)?
In general the reason why I explicitly pass the filetype is to ensure that jqx
acts properly on json or yaml by calling jq
or yq
, respectively. Both of them need the filename to be explicitly passed to the query in order to produce results, as their grammar is something along the lines of jq <query> <filename>
. If I understand correctly, however, you would like that - in case the filetype is unset (for the sake of simplicity let us consider this case first) - the queries are run by considering the content of the buffer as input for the standard input?
what do you have in mind here? An empty buffer or a buffer populated with some text and no filetype specified (I suspect the latter)?
That's it: I use diepm/vim-rest-console that allow to send REST requet and display answer on a buffer.
In general the reason why I explicitly pass the filetype is to ensure that
jqx
acts properly on json or yaml by callingjq
oryq
, respectively. Both of them need the filename to be explicitly passed to the query in order to produce results, as their grammar is something along the lines ofjq <query> <filename>
.
jq
and yq
both an work with standard input, I use them almost everyday this way ;)
For instance : https://github.com/remche/terraform-openstack-rke2/blob/73b0018fda817b666ef226ead84c934b4f81dc46/modules/node/files/cloud-init.yml.tpl#L21
If I understand correctly, however, you would like that - in case the filetype is unset (for the sake of simplicity let us consider this case first) - the queries are run by considering the content of the buffer as input for the standard input?
Yes. I bet there will be a problem to know if we should use jq
or yq
is the ft is not set. As YAML is a superset of JSON, may be falling to yq is the way to handle that case ?
Thank you for clarifying. One thing that could be a "quick win" would be to introduce a condition such that, if the filename is null (namely the buffer isn't saved to a file but only temporarily filled with data) and the filetype is still set correctly to either json or yaml, then I could execute the query using the buffer text as standard input. I would have to check if this however breaks the query on keystrokes or JqxQuery
in general.
I will have a look over the weekend and test possible solutions :)
An update on this issue: I tried a few different solutions but have not yet found one that would not conflict with some parts of the plugin (or make the usage/code quite more cumbersome): I will continue looking into it.