feat: Add option to not show nested objects

This commit is contained in:
Myzel394 2024-05-25 19:18:03 +02:00
parent 5a2a67bff2
commit ce0e163b8f
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 9 additions and 3 deletions

View File

@ -63,14 +63,18 @@ end
---@param value any ---@param value any
---@param conceal boolean ---@param conceal boolean
function M:create_display_preview(value, conceal) ---@param render_objects boolean
function M:create_display_preview(value, conceal, render_objects)
local t = type(value) local t = type(value)
if t == "table" then if t == "table" then
if render_objects == false then
return "", "other"
end
local preview_table = {} local preview_table = {}
for k, v in pairs(value) do for k, v in pairs(value) do
preview_table[#preview_table + 1] = k .. ": " .. M:create_display_preview(v, conceal) preview_table[#preview_table + 1] = k .. ": " .. M:create_display_preview(v, conceal, render_objects)
end end
return "{ " .. table.concat(preview_table, ", ") .. " }", "other" return "{ " .. table.concat(preview_table, ", ") .. " }", "other"

View File

@ -10,6 +10,7 @@
---@field highlights Highlights - Highlight groups for different types ---@field highlights Highlights - Highlight groups for different types
---@field jump_behavior "key_start"|"value_start" - Behavior for jumping to the location, "key_start" == Jump to the start of the key, "value_start" == Jump to the start of the value, Default: "key_start" ---@field jump_behavior "key_start"|"value_start" - Behavior for jumping to the location, "key_start" == Jump to the start of the key, "value_start" == Jump to the start of the value, Default: "key_start"
---@field subkeys_display "normal"|"waterfall" - Display subkeys in a normal or waterfall style, Default: "normal" ---@field subkeys_display "normal"|"waterfall" - Display subkeys in a normal or waterfall style, Default: "normal"
---@field show_nested_child_preview boolean - Whether to show a preview of nested children, Default: true
---@field backend "lua"|"lsp" - Backend to use for parsing JSON, "lua" = Use our own Lua parser to parse the JSON, "lsp" = Use your LSP to parse the JSON (currently only https://github.com/Microsoft/vscode-json-languageservice is supported). If the "lsp" backend is selected but the LSP fails, it will fallback to the "lua" backend, Default: "lsp" ---@field backend "lua"|"lsp" - Backend to use for parsing JSON, "lua" = Use our own Lua parser to parse the JSON, "lsp" = Use your LSP to parse the JSON (currently only https://github.com/Microsoft/vscode-json-languageservice is supported). If the "lsp" backend is selected but the LSP fails, it will fallback to the "lua" backend, Default: "lsp"
---@field use_cache number - Whether to use cache the parsed JSON. The cache will be activated if the number of lines is greater or equal to this value, By default, the cache is activate when the file if 1000 lines or more; `0` to disable the cache, Default: 500 ---@field use_cache number - Whether to use cache the parsed JSON. The cache will be activated if the number of lines is greater or equal to this value, By default, the cache is activate when the file if 1000 lines or more; `0` to disable the cache, Default: 500
---@field commands Commands - Shortcuts for commands ---@field commands Commands - Shortcuts for commands
@ -55,6 +56,7 @@ local DEFAULT_CONFIG = {
}, },
jump_behavior = "key_start", jump_behavior = "key_start",
subkeys_display = "normal", subkeys_display = "normal",
show_nested_child_preview = false,
backend = "lsp", backend = "lsp",
use_cache = 500, use_cache = 500,
commands = { commands = {
@ -116,7 +118,7 @@ local function show_picker(entries, buffer, xopts)
value = buffer, value = buffer,
ordinal = entry.key, ordinal = entry.key,
display = function(_) display = function(_)
local preview, hl_group_key = utils:create_display_preview(entry.value, conceal) local preview, hl_group_key = utils:create_display_preview(entry.value, conceal, global_config.show_nested_child_preview)
local key = global_config.subkeys_display == "normal" and entry.key or utils:replace_previous_keys(entry.key, " ") local key = global_config.subkeys_display == "normal" and entry.key or utils:replace_previous_keys(entry.key, " ")