From f8f4473afd6c11732bb229bb1ee1e5b462b307f1 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Sat, 13 May 2023 21:39:56 +0200 Subject: [PATCH] repl: A bit nicer array completion --- pkg/interp/repl.jq | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/interp/repl.jq b/pkg/interp/repl.jq index 829eab16..c0c5e247 100644 --- a/pkg/interp/repl.jq +++ b/pkg/interp/repl.jq @@ -53,9 +53,10 @@ def _complete($line; $cursor_pos): def _is_separator: . as $c | " .;[]()|=" | contains($c); def _is_internal: startswith("_") or startswith("$_"); def _query_index_or_key($q): - ( ([.[] | _eval($q; {}) | type]) as $n - | if ($n | all(. == "object")) then "." - elif ($n | all(. == "array")) then "[]" + ( ([.[] | _eval($q; {}) | type]) + | if length > 0 and all(. == "object") then "." + # TODO: only [] if not first [1,2,3]\t -> [][] not [].[] + elif length > 0 and all(. == "array") then ".[]" else null end );