Fix project root when listing files part 2

This commit is contained in:
Marcelo Jacobus 2024-11-18 15:26:48 -03:00
parent 14710a82ff
commit b362286745
2 changed files with 25 additions and 7 deletions

View file

@ -5,10 +5,19 @@ return {
config = function()
require("project_nvim").setup({
detection_methods = { "pattern" },
patterns = { ".git", "Gemfile", "package.json" }, -- Adjust for your project
sync_root_with_cwd = true, -- Ensure working directory syncs with root
patterns = { ".git", "Gemfile", "package.json" }, -- Adjust as needed
sync_root_with_cwd = true, -- Sync `cwd` with project root
})
vim.api.nvim_create_autocmd("BufEnter", {
callback = function()
local project_root = require("project_nvim.project").get_project_root()
if project_root and vim.fn.getcwd() ~= project_root then
print("Changing Project Root:", project_root)
vim.cmd("cd " .. project_root)
end
end,
})
require("telescope").load_extension("projects")
end,
},
}

View file

@ -4,12 +4,12 @@ return {
{
"nvim-telescope/telescope.nvim",
opts = function(_, opts)
opts.keys = opts.keys or {}
opts.keys["<Space><Space>"] = function()
vim.keymap.set("n", "<Space><Space>", function()
local project_root = require("project_nvim.project").get_project_root() or vim.fn.getcwd()
require("telescope.builtin").find_files({
cwd = require("project_nvim.project").get_project_root() or vim.fn.getcwd(),
cwd = project_root, -- Force project root
})
end
end, { desc = "Find Files (Project Root)" })
end,
},
{
@ -24,3 +24,12 @@ return {
end,
},
}
-- opts = function(_, opts)
-- vim.keymap.set("n", "<Space><Space>", function()
-- local project_root = require("project_nvim.project").get_project_root() or vim.fn.getcwd()
-- require("telescope.builtin").find_files({
-- cwd = project_root, -- Force project root
-- })
-- end, { desc = "Find Files (Project Root)" })
-- end,