From 29f7169490c38631a14f6cef6161487a781f4df1 Mon Sep 17 00:00:00 2001 From: Bryan Date: Mon, 16 Sep 2024 23:40:19 -0600 Subject: [PATCH] Only auto add projects if there is a root directory that matches the pattern for a project --- lua/cd-project/api.lua | 5 ++++- lua/cd-project/auto.lua | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/cd-project/api.lua b/lua/cd-project/api.lua index 863f45f..9e86bb1 100644 --- a/lua/cd-project/api.lua +++ b/lua/cd-project/api.lua @@ -3,13 +3,16 @@ local repo = require("cd-project.project-repo") local utils = require("cd-project.utils") ---@return string|nil -local function find_project_dir() +local function find_project_dir(auto) local found = vim.fs.find( vim.g.cd_project_config.project_dir_pattern, { upward = true, stop = vim.loop.os_homedir(), path = vim.fs.dirname(vim.fn.expand("%:p")) } ) 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 return vim.fn.getcwd() end diff --git a/lua/cd-project/auto.lua b/lua/cd-project/auto.lua index 38da777..8c9425f 100644 --- a/lua/cd-project/auto.lua +++ b/lua/cd-project/auto.lua @@ -6,7 +6,9 @@ local function setup() vim.api.nvim_create_autocmd({ "VimEnter" }, { group = auto_group_name, callback = function(_) - api.add_current_project({ show_duplicate_hints = false }) + if api.find_project_dir(true) ~ nil then + api.add_current_project({ show_duplicate_hints = false }) + end end, }) end