From 3b481818d8c947b7f778b5719bf3069f0a346715 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Thu, 11 Apr 2024 23:02:47 +0200 Subject: [PATCH] feat: Add basic support for arrays --- lua/jsonfly/json.lua | 18 ++++++++++++++++-- lua/telescope/_extensions/jsonfly.lua | 7 ++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lua/jsonfly/json.lua b/lua/jsonfly/json.lua index 549d5d6..d8e0a7d 100644 --- a/lua/jsonfly/json.lua +++ b/lua/jsonfly/json.lua @@ -375,7 +375,13 @@ local function grok_object(self, text, start, options) local new_val, new_i = grok_one(self, text, i, options) ---- Add start position so we can quickly jump to it - VALUE[key] = {value = new_val, key_start = key_start, key_end = key_end, newlines = newlines, relative_start = relative_start} + VALUE[key] = { + value = new_val, + key_start = key_start, + key_end = key_end, + newlines = newlines or 0, + relative_start = relative_start, + } -- -- Expect now either '}' to end things, or a ',' to allow us to continue. @@ -417,9 +423,17 @@ local function grok_array(self, text, start, options) local text_len = text:len() while i <= text_len do local val, new_i = grok_one(self, text, i, options) + local newlines = count_newlines(text, i) + local relative_start = get_relative_i(text, i) -- can't table.insert(VALUE, val) here because it's a no-op if val is nil - VALUE[VALUE_INDEX] = val + VALUE[VALUE_INDEX] = { + value = val, + key_start = new_i, + key_end = new_i, + newlines = newlines or 0, + relative_start = relative_start, + } VALUE_INDEX = VALUE_INDEX + 1 i = skip_whitespace(text, new_i) diff --git a/lua/telescope/_extensions/jsonfly.lua b/lua/telescope/_extensions/jsonfly.lua index 4f34ff8..05f000e 100644 --- a/lua/telescope/_extensions/jsonfly.lua +++ b/lua/telescope/_extensions/jsonfly.lua @@ -141,9 +141,9 @@ return require"telescope".register_extension { { entry.key, "@property.json" }, { truncate_overflow( - preview, - opts.max_length, - opts.overflow_marker + preview, + opts.max_length, + opts.overflow_marker ), opts.highlights[hl_group_key] or "TelescopeResultsString", }, @@ -159,6 +159,7 @@ return require"telescope".register_extension { }, previewer = conf.grep_previewer(opts), sorter = conf.generic_sorter(opts), + sorting_strategy = "ascending", }):find() end }