chore: apply stylua

This commit is contained in:
Myzel394 2025-06-06 12:54:16 +02:00
parent 895e9adfdf
commit 0e5158a8d4
Signed by: Myzel394
GPG Key ID: 79E65B4AA44EBBF0
2 changed files with 57 additions and 52 deletions

View File

@ -208,7 +208,9 @@ end
---@param name string ---@param name string
---@return boolean ---@return boolean
function M:is_module_available(name) function M:is_module_available(name)
return pcall(function() require(name) end) == true return pcall(function()
require(name)
end) == true
end end
return M return M

View File

@ -42,36 +42,36 @@ local action_state = require("telescope.actions.state")
---@type Options ---@type Options
local DEFAULT_CONFIG = { local DEFAULT_CONFIG = {
key_max_length = 50, key_max_length = 50,
key_exact_length = false, key_exact_length = false,
max_length = 9999, max_length = 9999,
overflow_marker = "", overflow_marker = "",
conceal = "auto", conceal = "auto",
prompt_title = "JSON(fly)", prompt_title = "JSON(fly)",
highlights = { highlights = {
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", jump_behavior = "key_start",
subkeys_display = "normal", subkeys_display = "normal",
show_nested_child_preview = true, show_nested_child_preview = true,
backend = "lsp", backend = "lsp",
use_cache = 500, use_cache = 500,
commands = { commands = {
add_key = {"i", "<C-a>"}, add_key = { "i", "<C-a>" },
copy_jsonpath = { copy_jsonpath = {
"i", "i",
"<C-j>", "<C-j>",
---@param path string ---@param path string
---@param prompt_bufnr number ---@param prompt_bufnr number
function(path, prompt_bufnr) function(path, prompt_bufnr)
vim.fn.setreg("+", path) vim.fn.setreg("+", path)
end end,
} },
} },
} }
local global_config = {} local global_config = {}
@ -112,30 +112,33 @@ local function show_picker(entries, buffer, xopts)
insert:insert_new_key(entries, key_descriptor, buffer) insert:insert_new_key(entries, key_descriptor, buffer)
end) end)
if global_config.commands.copy_jsonpath and utils:is_module_available("jsonpath") then if global_config.commands.copy_jsonpath and utils:is_module_available("jsonpath") then
map( map(
global_config.commands.copy_jsonpath[1], global_config.commands.copy_jsonpath[1],
global_config.commands.copy_jsonpath[2], global_config.commands.copy_jsonpath[2],
function(prompt_bufnr) function(prompt_bufnr)
local jsonpath = require("jsonpath") local jsonpath = require("jsonpath")
local current_picker = action_state.get_current_picker(prompt_bufnr) local current_picker = action_state.get_current_picker(prompt_bufnr)
local selection = current_picker:get_selection() local selection = current_picker:get_selection()
local path = jsonpath.get(vim.treesitter.get_node({ local path = jsonpath.get(
bufnr = buffer, vim.treesitter.get_node({
pos = { bufnr = buffer,
selection.lnum - 1, pos = {
selection.index, selection.lnum - 1,
} selection.index,
}), buffer) },
}),
buffer
)
if path then if path then
global_config.commands.copy_jsonpath[3](path, prompt_bufnr) global_config.commands.copy_jsonpath[3](path, prompt_bufnr)
end end
end end
) )
end end
return true return true
end, end,