mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-28 05:54:03 +02:00
[Refactor]: Remove vim-rooter and smart-cwd; then use project.nvim (#1315)
* Replace vim-rooter with project.nvim * Implement stylua format * Remove smart_cwd * Implicitly update nvim-tree dir when project active * Link datapath to cache * Fix stylua * Fix lint * Fix telescope bug * Fix telescope dependency * Fix telescope once and for all * Fix telescope once again
This commit is contained in:
parent
21b621c95a
commit
b9b9c69615
8 changed files with 69 additions and 42 deletions
|
@ -31,19 +31,16 @@ M.config = function()
|
|||
description = { " Find File " },
|
||||
command = "Telescope find_files",
|
||||
},
|
||||
b = {
|
||||
-- b is reserved for the core.project module
|
||||
c = {
|
||||
description = { " Recently Used Files" },
|
||||
command = "Telescope oldfiles",
|
||||
},
|
||||
-- c = {
|
||||
-- description = { " Load Last Session " },
|
||||
-- command = "SessionLoad",
|
||||
-- },
|
||||
c = {
|
||||
d = {
|
||||
description = { " Find Word " },
|
||||
command = "Telescope live_grep",
|
||||
},
|
||||
d = {
|
||||
e = {
|
||||
description = { " Settings " },
|
||||
command = ":e " .. USER_CONFIG_PATH,
|
||||
},
|
||||
|
|
|
@ -60,6 +60,12 @@ M.setup = function()
|
|||
g["nvim_tree_" .. opt] = val
|
||||
end
|
||||
|
||||
-- Implicitly update nvim-tree when project module is active
|
||||
if lvim.builtin.project.active then
|
||||
vim.g.nvim_tree_update_cwd = 1
|
||||
vim.g.nvim_tree_respect_buf_cwd = 1
|
||||
end
|
||||
|
||||
local tree_cb = nvim_tree_config.nvim_tree_callback
|
||||
|
||||
if not g.nvim_tree_bindings then
|
||||
|
|
48
lua/core/project.lua
Normal file
48
lua/core/project.lua
Normal file
|
@ -0,0 +1,48 @@
|
|||
local M = {}
|
||||
--
|
||||
function M.config()
|
||||
lvim.builtin.project = {
|
||||
--- This is on by default since it's currently the expected behavior.
|
||||
---@usage set to false to disable project.nvim.
|
||||
active = true,
|
||||
|
||||
-- Manual mode doesn't automatically change your root directory, so you have
|
||||
-- the option to manually do so using `:ProjectRoot` command.
|
||||
manual_mode = false,
|
||||
|
||||
-- Methods of detecting the root directory. **"lsp"** uses the native neovim
|
||||
-- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here
|
||||
-- order matters: if one is not detected, the other is used as fallback. You
|
||||
-- can also delete or rearangne the detection methods.
|
||||
detection_methods = { "lsp", "pattern" },
|
||||
|
||||
-- All the patterns used to detect root dir, when **"pattern"** is in
|
||||
-- detection_methods
|
||||
patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" },
|
||||
|
||||
-- When set to false, you will get a message when project.nvim changes your
|
||||
-- directory.
|
||||
silent_chdir = true,
|
||||
}
|
||||
end
|
||||
--
|
||||
function M.setup()
|
||||
local settings = lvim.builtin.project
|
||||
|
||||
-- Table of lsp clients to ignore by name
|
||||
-- eg: { "efm", ... }
|
||||
settings["ignore_lsp"] = {}
|
||||
|
||||
-- Path where project.nvim will store the project history for use in
|
||||
-- telescope
|
||||
settings["datapath"] = CACHE_PATH
|
||||
|
||||
require("project_nvim").setup(settings)
|
||||
|
||||
lvim.builtin.dashboard.custom_section["b"] = {
|
||||
description = { " Recent Projects " },
|
||||
command = "Telescope projects",
|
||||
}
|
||||
end
|
||||
--
|
||||
return M
|
|
@ -1,15 +0,0 @@
|
|||
local M = {}
|
||||
function M.config()
|
||||
lvim.builtin.rooter = {
|
||||
--- This is on by default since it's currently the expected behavior.
|
||||
---@usage set to false to disable vim-rooter.
|
||||
active = true,
|
||||
silent_chdir = 1,
|
||||
manual_only = 0,
|
||||
}
|
||||
end
|
||||
function M.setup()
|
||||
vim.g.rooter_silent_chdir = lvim.builtin.rooter.silent_chdir
|
||||
vim.g.rooter_manual_only = lvim.builtin.rooter.manual_only
|
||||
end
|
||||
return M
|
|
@ -119,6 +119,9 @@ function M.setup()
|
|||
return
|
||||
end
|
||||
telescope.setup(lvim.builtin.telescope)
|
||||
if lvim.builtin.project.active then
|
||||
pcall(require("telescope").load_extension, "projects")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -26,7 +26,7 @@ lvim = {
|
|||
gitsigns = {},
|
||||
which_key = {},
|
||||
comment = {},
|
||||
rooter = {},
|
||||
project = {},
|
||||
galaxyline = {},
|
||||
bufferline = {},
|
||||
dap = {},
|
||||
|
@ -102,8 +102,6 @@ lvim = {
|
|||
popup_border = "single",
|
||||
on_attach_callback = nil,
|
||||
on_init_callback = nil,
|
||||
---@usage query the project directory from the language server and use it to set the CWD
|
||||
smart_cwd = true,
|
||||
null_ls = {
|
||||
setup = {},
|
||||
},
|
||||
|
@ -1301,7 +1299,7 @@ require("core.terminal").config()
|
|||
require("core.telescope").config()
|
||||
require("core.treesitter").config()
|
||||
require("core.nvimtree").config()
|
||||
require("core.rooter").config()
|
||||
require("core.project").config()
|
||||
require("core.bufferline").config()
|
||||
require("core.autopairs").config()
|
||||
require("core.comment").config()
|
||||
|
|
|
@ -55,14 +55,6 @@ local function add_lsp_buffer_keybindings(bufnr)
|
|||
wk.register(keys, { mode = "n", buffer = bufnr })
|
||||
end
|
||||
|
||||
local function set_smart_cwd(client)
|
||||
local proj_dir = client.config.root_dir
|
||||
if lvim.lsp.smart_cwd and proj_dir ~= "/" then
|
||||
vim.api.nvim_set_current_dir(proj_dir)
|
||||
require("core.nvimtree").change_tree_dir(proj_dir)
|
||||
end
|
||||
end
|
||||
|
||||
function M.common_capabilities()
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
|
@ -127,7 +119,6 @@ function M.common_on_attach(client, bufnr)
|
|||
end
|
||||
lsp_highlight_document(client)
|
||||
add_lsp_buffer_keybindings(bufnr)
|
||||
set_smart_cwd(client)
|
||||
require("lsp.null-ls").setup(vim.bo.filetype)
|
||||
end
|
||||
|
||||
|
|
|
@ -147,17 +147,16 @@ return {
|
|||
disable = not lvim.builtin.comment.active,
|
||||
},
|
||||
|
||||
-- vim-rooter
|
||||
-- project.nvim
|
||||
{
|
||||
"airblade/vim-rooter",
|
||||
-- event = "BufReadPre",
|
||||
"ahmedkhalf/project.nvim",
|
||||
config = function()
|
||||
require("core.rooter").setup()
|
||||
if lvim.builtin.rooter.on_config_done then
|
||||
lvim.builtin.rooter.on_config_done()
|
||||
require("core.project").setup()
|
||||
if lvim.builtin.project.on_config_done then
|
||||
lvim.builtin.project.on_config_done()
|
||||
end
|
||||
end,
|
||||
disable = not lvim.builtin.rooter.active,
|
||||
disable = not lvim.builtin.project.active,
|
||||
},
|
||||
|
||||
-- Icons
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue