fix (#1363): use change_dir.fn instead of lib.open in M.change_root

This commit is contained in:
lixvbnet
2022-06-25 12:14:08 +08:00
committed by GitHub
parent 65beb55ac7
commit b299a877ad

View File

@@ -41,7 +41,7 @@ function M.change_root(filepath, bufnr)
-- test if in vim_cwd -- test if in vim_cwd
if utils.path_relative(filepath, vim_cwd) ~= filepath then if utils.path_relative(filepath, vim_cwd) ~= filepath then
if vim_cwd ~= cwd then if vim_cwd ~= cwd then
lib.open(vim_cwd) change_dir.fn(vim_cwd)
end end
return return
end end
@@ -52,19 +52,19 @@ function M.change_root(filepath, bufnr)
-- otherwise test M.init_root -- otherwise test M.init_root
if _config.prefer_startup_root and utils.path_relative(filepath, M.init_root) ~= filepath then if _config.prefer_startup_root and utils.path_relative(filepath, M.init_root) ~= filepath then
lib.open(M.init_root) change_dir.fn(M.init_root)
return return
end end
-- otherwise root_dirs -- otherwise root_dirs
for _, dir in pairs(_config.root_dirs) do for _, dir in pairs(_config.root_dirs) do
dir = vim.fn.fnamemodify(dir, ":p") dir = vim.fn.fnamemodify(dir, ":p")
if utils.path_relative(filepath, dir) ~= filepath then if utils.path_relative(filepath, dir) ~= filepath then
lib.open(dir) change_dir.fn(dir)
return return
end end
end end
-- finally fall back to the folder containing the file -- finally fall back to the folder containing the file
lib.open(vim.fn.fnamemodify(filepath, ":p:h")) change_dir.fn(vim.fn.fnamemodify(filepath, ":p:h"))
end end
---@deprecated ---@deprecated