108 lines
3.0 KiB
Lua
108 lines
3.0 KiB
Lua
local map = core.misc.map
|
|
|
|
--- get the root directory for telescope to search
|
|
---@return string the root directory
|
|
local function root_dir()
|
|
local clients = vim.lsp.get_clients({ bufnr = 0 })
|
|
if #clients > 0 then
|
|
return clients[1].config.root_dir
|
|
end
|
|
|
|
return "."
|
|
end
|
|
|
|
--- wrap a telebuilt picker to make it work for the current project root
|
|
---@param fn function telebuilt function
|
|
---@return function the new function
|
|
local function telebuilt_picker(fn)
|
|
return function()
|
|
fn { cwd = root_dir() }
|
|
end
|
|
end
|
|
|
|
return { "nvim-telescope/telescope.nvim",
|
|
disable = not vim.fn.has("nvim-0.9.0"),
|
|
requires = {
|
|
"nvim-lua/plenary.nvim",
|
|
{ "nvim-telescope/telescope-fzf-native.nvim",
|
|
config = function()
|
|
vim.cmd("make")
|
|
end
|
|
},
|
|
"nvim-telescope/telescope-ui-select.nvim"
|
|
},
|
|
|
|
function()
|
|
local telescope = require("telescope")
|
|
local actions = require("telescope.actions")
|
|
|
|
telescope.setup {
|
|
defaults = {
|
|
borderchars = {
|
|
prompt = { " ", " ", " ", " ", " ", " ", " ", " " },
|
|
results = { " ", " ", " ", " ", " ", " ", " ", " " },
|
|
preview = { " ", " ", " ", " ", " ", " ", " ", " " },
|
|
},
|
|
winblend = 0,
|
|
layout_strategy = "horizontal",
|
|
sorting_strategy = "descending",
|
|
scroll_strategy = "limit",
|
|
layout_config = {
|
|
horizontal = {
|
|
height = 20,
|
|
prompt_position = "bottom",
|
|
anchor = "N",
|
|
}
|
|
},
|
|
mappings = {
|
|
i = {
|
|
["<esc>"] = actions.close,
|
|
["<C-j>"] = actions.move_selection_next,
|
|
["<C-k>"] = actions.move_selection_previous,
|
|
["<C-u>"] = actions.preview_scrolling_up,
|
|
["<C-d>"] = actions.preview_scrolling_down,
|
|
}
|
|
}
|
|
},
|
|
extensions = {
|
|
fzf = {}
|
|
}
|
|
}
|
|
|
|
-- load in the fzf extension
|
|
telescope.load_extension("fzf")
|
|
telescope.load_extension("ui-select")
|
|
|
|
-- keymaps
|
|
local telebuilt = require("telescope.builtin")
|
|
map("n", "<leader>f", telebuilt_picker(telebuilt.find_files), {
|
|
desc = "Find files."
|
|
})
|
|
map("n", "<leader>o", telebuilt.oldfiles, { desc = "Find old." })
|
|
map("n", "<leader>s", telebuilt_picker(telebuilt.live_grep), {
|
|
desc = "Find strings."
|
|
})
|
|
map("n", "<leader>i", telebuilt.help_tags, { desc = "find help tags." })
|
|
map("n", "<leader>l", telebuilt.lsp_document_symbols, {
|
|
desc = "Find symbols."
|
|
})
|
|
|
|
-- find over specific directories
|
|
map("n", "<leader>tc", function()
|
|
telebuilt.find_files { cwd = vim.fn.stdpath("config") }
|
|
end, { desc = "find config files" })
|
|
map("n", "<leader>tp", function()
|
|
telebuilt.find_files {
|
|
cwd = vim.fs.joinpath(vim.fn.stdpath("data"), "site/pack/deps/opt")
|
|
}
|
|
end, { desc = "find files in plugin directory" })
|
|
|
|
-- enable previewing in the default colorscheme switcher
|
|
telebuilt.colorscheme = function()
|
|
require("telescope.builtin.__internal").colorscheme {
|
|
enable_preview = true
|
|
}
|
|
end
|
|
end
|
|
}
|