From bd9be2c533cb659a174ae031befeb245d57dd2e6 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Fri, 11 Feb 2022 18:30:15 +0100 Subject: [PATCH] repl: Fix completion of non-underscore extkeys For example .size for binary --- pkg/interp/repl.jq | 9 ++++----- pkg/interp/testdata/completion.fqtest | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/interp/repl.jq b/pkg/interp/repl.jq index 5e5a67f5..81502236 100644 --- a/pkg/interp/repl.jq +++ b/pkg/interp/repl.jq @@ -28,6 +28,8 @@ def _complete_keywords: def _complete_scope: [scope[], _complete_keywords[]]; +def _complete_keys: + [keys[]?, _extkeys[]?]; # TODO: handle variables via ast walk? # TODO: refactor this @@ -55,10 +57,7 @@ def _complete($line; $cursor_pos): # TODO: move map/add logic to here? | _query_completion( if .type | . == "func" or . == "var" then "_complete_scope" - elif .type == "index" then - if (.prefix | startswith("_")) then "_extkeys" - else "keys" - end + elif .type == "index" then "_complete_keys" else error("unreachable") end ) as {$type, $query, $prefix} @@ -79,7 +78,7 @@ def _complete($line; $cursor_pos): strings and # TODO: var type really needed? just func? (_is_ident or $type == "var") and - ((_is_internal | not) or $prefix_is_internal or $type == "index") and + ((_is_internal | not) or $prefix_is_internal) and startswith($prefix) ) ) diff --git a/pkg/interp/testdata/completion.fqtest b/pkg/interp/testdata/completion.fqtest index 727f91b6..7f587d68 100644 --- a/pkg/interp/testdata/completion.fqtest +++ b/pkg/interp/testdata/completion.fqtest @@ -56,4 +56,8 @@ mp3> .frames\t frames[] mp3> .frames[]\t . +mp3> "abc" | tobitsrange.s\t +size +start +stop mp3> ^D