Merge pull request #12 from Myzel394/11-fix-theme

Fix configs
This commit is contained in:
Myzel394 2024-05-12 21:53:05 +02:00 committed by GitHub
commit 5a2a67bff2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,14 +32,14 @@ local insert = require"jsonfly.insert"
local json = require"jsonfly.json"
local finders = require "telescope.finders"
local pickers = require "telescope.pickers"
local conf = require"telescope.config".values
local conf = require("telescope.config").values
local make_entry = require "telescope.make_entry"
local entry_display = require "telescope.pickers.entry_display"
local action_state = require "telescope.actions.state"
---@type Options
local opts = {
local DEFAULT_CONFIG = {
key_max_length = 50,
key_exact_length = false,
max_length = 9999,
@ -62,34 +62,37 @@ local opts = {
}
}
local global_config = {}
---@param entries Entry[]
---@param buffer number
local function show_picker(entries, buffer)
local function show_picker(entries, buffer, xopts)
local config = vim.tbl_deep_extend("force", global_config, xopts or {})
local filename = vim.api.nvim_buf_get_name(buffer)
local displayer = entry_display.create {
separator = " ",
items = {
{ width = 1 },
opts.key_exact_length and { width = opts.key_max_length } or { remaining = true },
global_config.key_exact_length and { width = global_config.key_max_length } or { remaining = true },
{ remaining = true },
},
}
---@type boolean
local conceal
if opts.conceal == "auto" then
if global_config.conceal == "auto" then
conceal = vim.o.conceallevel > 0
else
conceal = opts.conceal == true
conceal = global_config.conceal == true
end
pickers.new(opts, {
prompt_title = opts.prompt_title,
pickers.new(config, {
prompt_title = global_config.prompt_title,
attach_mappings = function(_, map)
map(
opts.commands.add_key[1],
opts.commands.add_key[2],
global_config.commands.add_key[1],
global_config.commands.add_key[2],
function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
local input = current_picker:_get_prompt()
@ -115,25 +118,25 @@ local function show_picker(entries, buffer)
display = function(_)
local preview, hl_group_key = utils:create_display_preview(entry.value, conceal)
local key = opts.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, " ")
return displayer {
{ depth, "TelescopeResultsNumber"},
{
utils:truncate_overflow(
key,
opts.key_max_length,
opts.overflow_marker
global_config.key_max_length,
global_config.overflow_marker
),
"@property.json",
},
{
utils:truncate_overflow(
preview,
opts.max_length,
opts.overflow_marker
global_config.max_length,
global_config.overflow_marker
),
opts.highlights[hl_group_key] or "TelescopeResultsString",
global_config.highlights[hl_group_key] or "TelescopeResultsString",
},
}
end,
@ -141,22 +144,22 @@ local function show_picker(entries, buffer)
bufnr = buffer,
filename = filename,
lnum = entry.position.line_number,
col = opts.jump_behavior == "key_start"
col = global_config.jump_behavior == "key_start"
and entry.position.key_start
-- Use length ("#" operator) as vim jumps to the bytes, not characters
or entry.position.value_start
}, opts)
}, config)
end,
},
previewer = conf.grep_previewer(opts),
sorter = conf.generic_sorter(opts),
previewer = conf.grep_previewer(config),
sorter = conf.generic_sorter(config),
sorting_strategy = "ascending",
}):find()
end
return require"telescope".register_extension {
return require("telescope").register_extension {
setup = function(extension_config)
opts = vim.tbl_deep_extend("force", opts, extension_config or {})
global_config = vim.tbl_deep_extend("force", DEFAULT_CONFIG, extension_config or {})
end,
exports = {
jsonfly = function(xopts)
@ -165,13 +168,13 @@ return require"telescope".register_extension {
local cached_entries = cache:get_cache(current_buf)
if cached_entries ~= nil then
show_picker(cached_entries, current_buf)
show_picker(cached_entries, current_buf, xopts)
return
end
local content_lines = vim.api.nvim_buf_get_lines(current_buf, 0, -1, false)
local content = table.concat(content_lines, "\n")
local allow_cache = opts.use_cache > 0 and #content_lines >= opts.use_cache
local allow_cache = global_config.use_cache > 0 and #content_lines >= global_config.use_cache
if allow_cache then
cache:register_listeners(current_buf)
@ -185,10 +188,10 @@ return require"telescope".register_extension {
cache:cache_buffer(current_buf, entries)
end
show_picker(entries, current_buf)
show_picker(entries, current_buf, xopts)
end
if opts.backend == "lsp" then
if global_config.backend == "lsp" then
local params = vim.lsp.util.make_position_params(xopts.winnr)
vim.lsp.buf_request(
@ -207,7 +210,7 @@ return require"telescope".register_extension {
cache:cache_buffer(current_buf, entries)
end
show_picker(entries, current_buf)
show_picker(entries, current_buf, xopts)
end
)
else