Only auto add projects if there is a root directory that matches the pattern for a project
parent
320c2bcd10
commit
29f7169490
|
|
@ -3,13 +3,16 @@ local repo = require("cd-project.project-repo")
|
||||||
local utils = require("cd-project.utils")
|
local utils = require("cd-project.utils")
|
||||||
|
|
||||||
---@return string|nil
|
---@return string|nil
|
||||||
local function find_project_dir()
|
local function find_project_dir(auto)
|
||||||
local found = vim.fs.find(
|
local found = vim.fs.find(
|
||||||
vim.g.cd_project_config.project_dir_pattern,
|
vim.g.cd_project_config.project_dir_pattern,
|
||||||
{ upward = true, stop = vim.loop.os_homedir(), path = vim.fs.dirname(vim.fn.expand("%:p")) }
|
{ upward = true, stop = vim.loop.os_homedir(), path = vim.fs.dirname(vim.fn.expand("%:p")) }
|
||||||
)
|
)
|
||||||
|
|
||||||
if #found == 0 then
|
if #found == 0 then
|
||||||
|
if auto then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
-- if there are no parent directories matching the project pattern then use current directory as project directory
|
-- if there are no parent directories matching the project pattern then use current directory as project directory
|
||||||
return vim.fn.getcwd()
|
return vim.fn.getcwd()
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ local function setup()
|
||||||
vim.api.nvim_create_autocmd({ "VimEnter" }, {
|
vim.api.nvim_create_autocmd({ "VimEnter" }, {
|
||||||
group = auto_group_name,
|
group = auto_group_name,
|
||||||
callback = function(_)
|
callback = function(_)
|
||||||
|
if api.find_project_dir(true) ~ nil then
|
||||||
api.add_current_project({ show_duplicate_hints = false })
|
api.add_current_project({ show_duplicate_hints = false })
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue