fix: Properly load options

This commit is contained in:
Myzel394 2024-04-12 22:26:16 +02:00
parent c96e5350e7
commit b9166ce560
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -1,6 +1,7 @@
--- Type definitions --- Type definitions
---@class Options ---@class Options
---@field key_max_length number - Length for the key column, 0 for no column-like display, Default: 50 ---@field key_max_length number - Length for the key column, 0 for no column-like display, Default: 50
---@field key_exact_length boolean - Whether to use exact length for the key column, This will pad the key column with spaces to match the length, Default: false
---@field max_length number - Maximum length for the value column, Default: 9999 (basically no limit) ---@field max_length number - Maximum length for the value column, Default: 9999 (basically no limit)
---@field overflow_marker string - Marker for truncated values, Default: "…" ---@field overflow_marker string - Marker for truncated values, Default: "…"
---@field conceal boolean|"auto" - Whether to conceal strings, If `true` strings will be concealed, If `false` strings will be displayed as they are, If `"auto"` strings will be concealed if `conceallevel` is greater than 0, Default: "auto" ---@field conceal boolean|"auto" - Whether to conceal strings, If `true` strings will be concealed, If `false` strings will be displayed as they are, If `"auto"` strings will be concealed if `conceallevel` is greater than 0, Default: "auto"
@ -84,29 +85,30 @@ local function create_display_preview(value, opts)
end end
end end
return require"telescope".register_extension { ---@type Options
setup = function() end, local opts = {
exports = { key_max_length = 50,
---@param opts Options key_exact_length = false,
jsonfly = function(opts) max_length = 9999,
opts = opts or {} overflow_marker = "",
opts.prompt_title = opts.prompt_title or "JSON(fly)" conceal = "auto",
opts.key_max_length = opts.key_max_length or 50 prompt_title = "JSON(fly)",
opts.max_length = opts.max_length or 9999 highlights = {
opts.overflow_marker = opts.overflow_marker or ""
opts.highlights = opts.highlights or {
string = "@string.json", string = "@string.json",
number = "@number.json", number = "@number.json",
boolean = "@boolean.json", boolean = "@boolean.json",
null = "@constant.builtin.json", null = "@constant.builtin.json",
other = "@label.json", other = "@label.json",
},
jump_behavior = "key_start",
} }
opts.jump_behavior = opts.jump_behavior or "key_start"
if opts.conceal == nil then
opts.conceal = "auto"
end
return require"telescope".register_extension {
setup = function(extension_config)
opts = vim.tbl_deep_extend("force", opts, extension_config or {})
end,
exports = {
jsonfly = function()
local current_buf = vim.api.nvim_get_current_buf() local current_buf = vim.api.nvim_get_current_buf()
local filename = vim.api.nvim_buf_get_name(current_buf) local filename = vim.api.nvim_buf_get_name(current_buf)
local content_lines = vim.api.nvim_buf_get_lines(current_buf, 0, -1, false) local content_lines = vim.api.nvim_buf_get_lines(current_buf, 0, -1, false)
@ -119,7 +121,7 @@ return require"telescope".register_extension {
separator = " ", separator = " ",
items = { items = {
{ width = 1 }, { width = 1 },
{ width = opts.key_max_length }, opts.key_exact_length and { width = opts.key_max_length } or { remaining = true },
{ remaining = true }, { remaining = true },
}, },
} }
@ -140,7 +142,14 @@ return require"telescope".register_extension {
return displayer { return displayer {
{ depth, "TelescopeResultsNumber"}, { depth, "TelescopeResultsNumber"},
{ entry.key, "@property.json" }, {
truncate_overflow(
entry.key,
opts.key_max_length,
opts.overflow_marker
),
"@property.json",
},
{ {
truncate_overflow( truncate_overflow(
preview, preview,