mirror of
https://github.com/Myzel394/jsonfly.nvim.git
synced 2025-06-18 12:15:25 +02:00
feat: Add option for cache
This commit is contained in:
parent
1455d877cd
commit
a36cb5b0b1
@ -11,6 +11,7 @@
|
|||||||
---@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 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
|
||||||
---
|
---
|
||||||
---@class Highlights
|
---@class Highlights
|
||||||
---@field number string - Highlight group for numbers, Default: "@number.json"
|
---@field number string - Highlight group for numbers, Default: "@number.json"
|
||||||
@ -48,6 +49,7 @@ local opts = {
|
|||||||
jump_behavior = "key_start",
|
jump_behavior = "key_start",
|
||||||
subkeys_display = "normal",
|
subkeys_display = "normal",
|
||||||
backend = "lsp",
|
backend = "lsp",
|
||||||
|
use_cache = 500,
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param entries Entry[]
|
---@param entries Entry[]
|
||||||
@ -141,16 +143,21 @@ return require"telescope".register_extension {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
cache:register_listeners(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)
|
||||||
local content = table.concat(content_lines, "\n")
|
local content = table.concat(content_lines, "\n")
|
||||||
|
local allow_cache = opts.use_cache > 0 and #content_lines >= opts.use_cache
|
||||||
|
|
||||||
|
if allow_cache then
|
||||||
|
cache:register_listeners(current_buf)
|
||||||
|
end
|
||||||
|
|
||||||
local function run_lua_parser()
|
local function run_lua_parser()
|
||||||
local parsed = json:decode(content)
|
local parsed = json:decode(content)
|
||||||
local entries = parsers:get_entries_from_lua_json(parsed)
|
local entries = parsers:get_entries_from_lua_json(parsed)
|
||||||
|
|
||||||
|
if allow_cache then
|
||||||
cache:cache_buffer(current_buf, entries)
|
cache:cache_buffer(current_buf, entries)
|
||||||
|
end
|
||||||
|
|
||||||
show_picker(entries, current_buf)
|
show_picker(entries, current_buf)
|
||||||
end
|
end
|
||||||
@ -169,7 +176,10 @@ return require"telescope".register_extension {
|
|||||||
end
|
end
|
||||||
|
|
||||||
local entries = parsers:get_entries_from_lsp_symbols(lsp_response)
|
local entries = parsers:get_entries_from_lsp_symbols(lsp_response)
|
||||||
|
|
||||||
|
if allow_cache then
|
||||||
cache:cache_buffer(current_buf, entries)
|
cache:cache_buffer(current_buf, entries)
|
||||||
|
end
|
||||||
|
|
||||||
show_picker(entries, current_buf)
|
show_picker(entries, current_buf)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user