diff --git a/src/ctags.cpp b/src/ctags.cpp index 0542931..87e25e1 100644 --- a/src/ctags.cpp +++ b/src/ctags.cpp @@ -19,11 +19,11 @@ Ctags::Ctags(const boost::filesystem::path &path, bool enable_scope, bool enable boost::system::error_code ec; if(boost::filesystem::is_directory(path, ec)) { auto build = Project::Build::create(path); - std::string exclude = " --exclude=node_modules"; + std::string exclude; if(!build->project_path.empty()) { project_path = build->project_path; - exclude += " --exclude=" + filesystem::escape_argument(filesystem::get_relative_path(build->get_default_path(), project_path).string()); - exclude += " --exclude=" + filesystem::escape_argument(filesystem::get_relative_path(build->get_debug_path(), project_path).string()); + for(auto &exclude_path : build->get_exclude_paths()) + exclude += " --exclude=" + filesystem::escape_argument(filesystem::get_relative_path(exclude_path, project_path).string()); } else project_path = path; diff --git a/src/grep.cpp b/src/grep.cpp index facc908..973aa09 100644 --- a/src/grep.cpp +++ b/src/grep.cpp @@ -7,20 +7,16 @@ Grep::Grep(const boost::filesystem::path &path, const std::string &pattern, bool case_sensitive, bool extended_regex) { auto build = Project::Build::create(path); -#ifdef JUCI_USE_GREP_EXCLUDE - std::string exclude = "--exclude=node_modules/*"; -#else - std::string exclude = "--exclude-dir=node_modules"; -#endif + std::string exclude; if(!build->project_path.empty()) { project_path = build->project_path; + for(auto &exclude_path : build->get_exclude_paths()) { #ifdef JUCI_USE_GREP_EXCLUDE - exclude += " --exclude=" + filesystem::escape_argument(filesystem::get_relative_path(build->get_default_path(), build->project_path).string()) + "/*"; - exclude += " --exclude=" + filesystem::escape_argument(filesystem::get_relative_path(build->get_debug_path(), build->project_path).string()) + "/*"; + exclude += " --exclude=" + filesystem::escape_argument(filesystem::get_relative_path(exclude_path, build->project_path).string()) + "/*"; #else - exclude += " --exclude-dir=" + filesystem::escape_argument(filesystem::get_relative_path(build->get_default_path(), build->project_path).string()); - exclude += " --exclude-dir=" + filesystem::escape_argument(filesystem::get_relative_path(build->get_debug_path(), build->project_path).string()); + exclude += " --exclude-dir=" + filesystem::escape_argument(filesystem::get_relative_path(exclude_path, build->project_path).string()); #endif + } } else project_path = path; diff --git a/src/project_build.cpp b/src/project_build.cpp index ee35548..39c3936 100644 --- a/src/project_build.cpp +++ b/src/project_build.cpp @@ -26,7 +26,8 @@ std::unique_ptr Project::Build::create(const boost::filesystem:: } if(boost::filesystem::exists(search_path / Config::get().project.default_build_path / "compile_commands.json", ec)) { - std::unique_ptr build(new CompileCommandsBuild(search_path)); + std::unique_ptr build(new CompileCommandsBuild()); + build->project_path = search_path; return build; } @@ -90,6 +91,12 @@ boost::filesystem::path Project::Build::get_debug_path() { return filesystem::get_normal_path(debug_build_path); } +std::vector Project::Build::get_exclude_paths() { + if(!project_path.empty()) + return {project_path / ".git"}; + return {}; +} + Project::CMakeBuild::CMakeBuild(const boost::filesystem::path &path) : Project::Build(), cmake(path) { project_path = cmake.project_path; } @@ -118,6 +125,13 @@ boost::filesystem::path Project::CMakeBuild::get_executable(const boost::filesys return executable; } +std::vector Project::CMakeBuild::get_exclude_paths() { + auto exclude_paths = Project::Build::get_exclude_paths(); + exclude_paths.emplace_back(get_default_path()); + exclude_paths.emplace_back(get_debug_path()); + return exclude_paths; +} + Project::MesonBuild::MesonBuild(const boost::filesystem::path &path) : Project::Build(), meson(path) { project_path = meson.project_path; } @@ -146,6 +160,35 @@ boost::filesystem::path Project::MesonBuild::get_executable(const boost::filesys return executable; } -Project::CompileCommandsBuild::CompileCommandsBuild(const boost::filesystem::path &path) { - project_path = path; +std::vector Project::MesonBuild::get_exclude_paths() { + auto exclude_paths = Project::Build::get_exclude_paths(); + exclude_paths.emplace_back(get_default_path()); + exclude_paths.emplace_back(get_debug_path()); + return exclude_paths; +} + +std::vector Project::CompileCommandsBuild::get_exclude_paths() { + auto exclude_paths = Project::Build::get_exclude_paths(); + exclude_paths.emplace_back(get_default_path()); + exclude_paths.emplace_back(get_debug_path()); + return exclude_paths; +} + +std::vector Project::CargoBuild::get_exclude_paths() { + auto exclude_paths = Project::Build::get_exclude_paths(); + exclude_paths.emplace_back(project_path / "target"); + return exclude_paths; +} + +std::vector Project::NpmBuild::get_exclude_paths() { + auto exclude_paths = Project::Build::get_exclude_paths(); + exclude_paths.emplace_back(project_path / "node_modules"); + return exclude_paths; +} + +std::vector Project::PythonMain::get_exclude_paths() { + auto exclude_paths = Project::Build::get_exclude_paths(); + exclude_paths.emplace_back(project_path / ".mypy_cache"); + exclude_paths.emplace_back(project_path / "__pycache__"); + return exclude_paths; } diff --git a/src/project_build.hpp b/src/project_build.hpp index 8b0ab7d..b6e7096 100644 --- a/src/project_build.hpp +++ b/src/project_build.hpp @@ -18,6 +18,8 @@ namespace Project { virtual std::string get_compile_command() { return std::string(); } virtual boost::filesystem::path get_executable(const boost::filesystem::path &path) { return boost::filesystem::path(); } + virtual std::vector get_exclude_paths(); + static std::unique_ptr create(const boost::filesystem::path &path); }; @@ -32,6 +34,8 @@ namespace Project { std::string get_compile_command() override; boost::filesystem::path get_executable(const boost::filesystem::path &path) override; + + std::vector get_exclude_paths() override; }; class MesonBuild : public Build { @@ -45,11 +49,13 @@ namespace Project { std::string get_compile_command() override; boost::filesystem::path get_executable(const boost::filesystem::path &path) override; + + std::vector get_exclude_paths() override; }; class CompileCommandsBuild : public Build { public: - CompileCommandsBuild(const boost::filesystem::path &path); + std::vector get_exclude_paths() override; }; class CargoBuild : public Build { @@ -61,9 +67,17 @@ namespace Project { std::string get_compile_command() override { return "cargo build"; } boost::filesystem::path get_executable(const boost::filesystem::path &path) override { return get_debug_path() / project_path.filename(); } + + std::vector get_exclude_paths() override; }; - class NpmBuild : public Build {}; + class NpmBuild : public Build { + public: + std::vector get_exclude_paths() override; + }; - class PythonMain : public Build {}; + class PythonMain : public Build { + public: + std::vector get_exclude_paths() override; + }; } // namespace Project diff --git a/src/window.cpp b/src/window.cpp index c9d80a6..ce10eda 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -925,12 +925,9 @@ void Window::set_menu_actions() { menu.add_action("source_find_file", []() { auto view_folder = Project::get_preferably_view_folder(); auto build = Project::Build::create(view_folder); - boost::filesystem::path default_path, debug_path; - if(!build->project_path.empty()) { + auto exclude_paths = build->get_exclude_paths(); + if(!build->project_path.empty()) view_folder = build->project_path; - default_path = build->get_default_path(); - debug_path = build->get_debug_path(); - } auto view = Notebook::get().get_current_view(); if(view) @@ -949,7 +946,9 @@ void Window::set_menu_actions() { auto path = iter->path(); // ignore folders if(!boost::filesystem::is_regular_file(path, ec)) { - if(path == default_path || path == debug_path || path.filename() == ".git") + if(std::any_of(exclude_paths.begin(), exclude_paths.end(), [&path](const boost::filesystem::path &exclude_path) { + return path == exclude_path; + })) iter.no_push(); continue; }