make telescope work better in projects
This commit is contained in:
@ -1,6 +1,26 @@
|
|||||||
local misc = require("core.misc")
|
local misc = require("core.misc")
|
||||||
local map = misc.map
|
local map = 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",
|
return { "nvim-telescope/telescope.nvim",
|
||||||
disable = not vim.fn.has("nvim-0.9.0"),
|
disable = not vim.fn.has("nvim-0.9.0"),
|
||||||
requires = {
|
requires = {
|
||||||
@ -56,12 +76,14 @@ return { "nvim-telescope/telescope.nvim",
|
|||||||
|
|
||||||
-- keymaps
|
-- keymaps
|
||||||
local telebuilt = require("telescope.builtin")
|
local telebuilt = require("telescope.builtin")
|
||||||
map("n", "<leader>f", telebuilt.find_files, { desc = "Find files." })
|
map("n", "<leader>f", telebuilt_picker(telebuilt.find_files), {
|
||||||
map("n", "<leader>o", telebuilt.oldfiles, { desc = "Find old." })
|
desc = "Find files."
|
||||||
map("n", "<leader>s", telebuilt.live_grep, { desc = "Find strings." })
|
|
||||||
map("n", "<leader>i", telebuilt.help_tags, {
|
|
||||||
desc = "find help tags."
|
|
||||||
})
|
})
|
||||||
|
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, {
|
map("n", "<leader>l", telebuilt.lsp_document_symbols, {
|
||||||
desc = "Find symbols."
|
desc = "Find symbols."
|
||||||
})
|
})
|
||||||
@ -78,7 +100,9 @@ return { "nvim-telescope/telescope.nvim",
|
|||||||
|
|
||||||
-- enable previewing in the default colorscheme switcher
|
-- enable previewing in the default colorscheme switcher
|
||||||
telebuilt.colorscheme = function()
|
telebuilt.colorscheme = function()
|
||||||
require("telescope.builtin.__internal").colorscheme { enable_preview = true }
|
require("telescope.builtin.__internal").colorscheme {
|
||||||
|
enable_preview = true
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user