mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
perf: reduce startup time by moving requires
This commit is contained in:
parent
62cbd4e7f5
commit
e5696afabd
@ -7,19 +7,7 @@ if not has_telescope then
|
|||||||
error "This plugin requires telescope.nvim (https://github.com/nvim-telescope/telescope.nvim)"
|
error "This plugin requires telescope.nvim (https://github.com/nvim-telescope/telescope.nvim)"
|
||||||
end
|
end
|
||||||
|
|
||||||
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
|
local config = {}
|
||||||
local actions = require "telescope.actions"
|
|
||||||
local conf = require("telescope.config").values
|
|
||||||
local entry_display = require "telescope.pickers.entry_display"
|
|
||||||
local finders = require "telescope.finders"
|
|
||||||
local Path = require "plenary.path"
|
|
||||||
local pickers = require "telescope.pickers"
|
|
||||||
local sorters = require "telescope.sorters"
|
|
||||||
local utils = require "telescope.utils"
|
|
||||||
local db_client = require "telescope._extensions.frecency.db_client"
|
|
||||||
|
|
||||||
local os_home = vim.loop.os_homedir()
|
|
||||||
local os_path_sep = utils.get_separator()
|
|
||||||
|
|
||||||
local state = {
|
local state = {
|
||||||
results = {},
|
results = {},
|
||||||
@ -35,18 +23,6 @@ local state = {
|
|||||||
picker = {},
|
picker = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
local function filepath_formatter(opts)
|
|
||||||
local path_opts = {}
|
|
||||||
for k, v in pairs(opts) do
|
|
||||||
path_opts[k] = v
|
|
||||||
end
|
|
||||||
|
|
||||||
return function (filename)
|
|
||||||
path_opts.cwd = state.active_filter or state.cwd
|
|
||||||
return utils.transform_path(path_opts, filename)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- returns `true` if workspaces exist
|
-- returns `true` if workspaces exist
|
||||||
---@param bufnr number
|
---@param bufnr number
|
||||||
---@param force? boolean
|
---@param force? boolean
|
||||||
@ -87,6 +63,23 @@ local function get_workspace_tags()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local frecency = function(opts)
|
local frecency = function(opts)
|
||||||
|
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
|
||||||
|
local entry_display = require "telescope.pickers.entry_display"
|
||||||
|
local finders = require "telescope.finders"
|
||||||
|
local Path = require "plenary.path"
|
||||||
|
local pickers = require "telescope.pickers"
|
||||||
|
local utils = require "telescope.utils"
|
||||||
|
|
||||||
|
local db_client = require "telescope._extensions.frecency.db_client"
|
||||||
|
|
||||||
|
-- start the database client
|
||||||
|
db_client.init(
|
||||||
|
config.db_root,
|
||||||
|
config.ignore_patterns,
|
||||||
|
vim.F.if_nil(config.db_safe_mode, true),
|
||||||
|
vim.F.if_nil(config.auto_validate, true)
|
||||||
|
)
|
||||||
|
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
state.previous_buffer = vim.fn.bufnr "%"
|
state.previous_buffer = vim.fn.bufnr "%"
|
||||||
@ -94,6 +87,8 @@ local frecency = function(opts)
|
|||||||
|
|
||||||
fetch_lsp_workspaces(state.previous_buffer)
|
fetch_lsp_workspaces(state.previous_buffer)
|
||||||
|
|
||||||
|
local os_home = vim.loop.os_homedir()
|
||||||
|
|
||||||
local function should_show_tail()
|
local function should_show_tail()
|
||||||
local filters = type(state.show_filter_column) == "table" and state.show_filter_column or { "LSP", "CWD" }
|
local filters = type(state.show_filter_column) == "table" and state.show_filter_column or { "LSP", "CWD" }
|
||||||
return vim.tbl_contains(filters, state.active_filter_tag)
|
return vim.tbl_contains(filters, state.active_filter_tag)
|
||||||
@ -120,6 +115,7 @@ local frecency = function(opts)
|
|||||||
table.insert(res, { remaining = true })
|
table.insert(res, { remaining = true })
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
local os_path_sep = utils.get_separator()
|
||||||
|
|
||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
separator = "",
|
separator = "",
|
||||||
@ -144,6 +140,18 @@ local frecency = function(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function filepath_formatter(path_opts0)
|
||||||
|
local path_opts = {}
|
||||||
|
for k, v in pairs(path_opts0) do
|
||||||
|
path_opts[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
|
return function (filename)
|
||||||
|
path_opts.cwd = state.active_filter or state.cwd
|
||||||
|
return utils.transform_path(path_opts, filename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local formatter = filepath_formatter(opts)
|
local formatter = filepath_formatter(opts)
|
||||||
|
|
||||||
local bufnr, buf_is_loaded, display_filename, hl_filename, display_items, icon, icon_highlight
|
local bufnr, buf_is_loaded, display_filename, hl_filename, display_items, icon, icon_highlight
|
||||||
@ -251,7 +259,7 @@ local frecency = function(opts)
|
|||||||
return { prompt = query_text, updated_finder = new_finder }
|
return { prompt = query_text, updated_finder = new_finder }
|
||||||
end,
|
end,
|
||||||
attach_mappings = function(prompt_bufnr)
|
attach_mappings = function(prompt_bufnr)
|
||||||
actions.select_default:replace_if(function()
|
require "telescope.actions".select_default:replace_if(function()
|
||||||
local compinfo = vim.fn.complete_info()
|
local compinfo = vim.fn.complete_info()
|
||||||
return compinfo.pum_visible == 1
|
return compinfo.pum_visible == 1
|
||||||
end, function()
|
end, function()
|
||||||
@ -267,8 +275,8 @@ local frecency = function(opts)
|
|||||||
results = state.results,
|
results = state.results,
|
||||||
entry_maker = entry_maker,
|
entry_maker = entry_maker,
|
||||||
},
|
},
|
||||||
previewer = conf.file_previewer(opts),
|
previewer = require("telescope.config").values.file_previewer(opts),
|
||||||
sorter = sorters.fuzzy_with_index_bias(opts),
|
sorter = require'telescope.sorters'.fuzzy_with_index_bias(opts),
|
||||||
})
|
})
|
||||||
state.picker:find()
|
state.picker:find()
|
||||||
|
|
||||||
@ -302,7 +310,7 @@ local function checkhealth()
|
|||||||
else
|
else
|
||||||
vim.health.report_error "Need sql.nvim to be installed."
|
vim.health.report_error "Need sql.nvim to be installed."
|
||||||
end
|
end
|
||||||
if has_devicons then
|
if pcall(require, "nvim-web-devicons") then
|
||||||
vim.health.report_ok "nvim-web-devicons installed."
|
vim.health.report_ok "nvim-web-devicons installed."
|
||||||
else
|
else
|
||||||
vim.health.report_info "nvim-web-devicons is not installed."
|
vim.health.report_info "nvim-web-devicons is not installed."
|
||||||
@ -318,19 +326,14 @@ return telescope.register_extension {
|
|||||||
set_config_state("user_workspaces", ext_config.workspaces, {})
|
set_config_state("user_workspaces", ext_config.workspaces, {})
|
||||||
set_config_state("disable_devicons", ext_config.disable_devicons, false)
|
set_config_state("disable_devicons", ext_config.disable_devicons, false)
|
||||||
set_config_state("default_workspace", ext_config.default_workspace, nil)
|
set_config_state("default_workspace", ext_config.default_workspace, nil)
|
||||||
|
config = vim.deepcopy(ext_config)
|
||||||
-- start the database client
|
|
||||||
db_client.init(
|
|
||||||
ext_config.db_root,
|
|
||||||
ext_config.ignore_patterns,
|
|
||||||
vim.F.if_nil(ext_config.db_safe_mode, true),
|
|
||||||
vim.F.if_nil(ext_config.auto_validate, true)
|
|
||||||
)
|
|
||||||
end,
|
end,
|
||||||
exports = {
|
exports = {
|
||||||
frecency = frecency,
|
frecency = frecency,
|
||||||
get_workspace_tags = get_workspace_tags,
|
get_workspace_tags = get_workspace_tags,
|
||||||
validate_db = db_client.validate,
|
validate_db = function(...)
|
||||||
|
require"telescope._extensions.frecency.db_client".validate(...)
|
||||||
|
end
|
||||||
},
|
},
|
||||||
health = checkhealth,
|
health = checkhealth,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user