jq-mode
jq-mode copied to clipboard
Feature request: Incremental completion for jq-interactively
It would be great to be able to see the buffer narrowing as you type (and perhaps have tab-completion). Wrapping calls to jq
in something like this would get you part of the way there, but you'd then need to reconstruct the original query:
.|with_entries(select(.key|match("^foo.*")))
*Of course, this breaks lists
Thank you for contributing to jq-mode.
I am not sure I understand what you are suggesting.
buffer narrowing as you type
jq-interactively should already show the result of the command that you type.
By tab-completion, do you mean completion based on what is in the json?
That could be interesting.
Let me illustrate my request with an example. Say you have a JSON file:
{"foobar": 1, "foobaz": 2, "fooquux": 3}
Currently if you type .foob
, the buffer shows null
. But ideally, it should wrap your query in .|with_entries(select(.key|match("^foob.*")))
, so that as you type, the buffer gets narrowed to {"foobar": 1, "foobaz": 2}
. You can then press a key (say, C-c C-c
) to unwrap your query back to .foob
, or have it done when you type a |
.
From this, tab completion comes naturally. The query can be completed to the greatest common prefix using the list of matching keys.
I'll get to implementing this sometime soon. Of course, it will be configurable, and probably off by default.
That sounds like a nice feature! I am not entirely how that would be implemented in practice, but I am more than happy to accept a PR.