diff --git a/extra.nix b/extra.nix index 4d47099..63f0f0e 100644 --- a/extra.nix +++ b/extra.nix @@ -136,6 +136,10 @@ inputs: let nvim-notify.enable = true; }; + vim.projects = { + project-nvim.enable = true; + }; + vim.utility = { colorizer.enable = true; icon-picker.enable = true; diff --git a/flake.lock b/flake.lock index e888a0e..baa79ca 100644 --- a/flake.lock +++ b/flake.lock @@ -1246,6 +1246,22 @@ "type": "github" } }, + "project-nvim": { + "flake": false, + "locked": { + "lastModified": 1680567592, + "narHash": "sha256-avV3wMiDbraxW4mqlEsKy0oeewaRj9Q33K8NzWoaptU=", + "owner": "ahmedkhalf", + "repo": "project.nvim", + "rev": "8c6bad7d22eef1b71144b401c9f74ed01526a4fb", + "type": "github" + }, + "original": { + "owner": "ahmedkhalf", + "repo": "project.nvim", + "type": "github" + } + }, "registers": { "flake": false, "locked": { @@ -1349,6 +1365,7 @@ "orgmode-nvim": "orgmode-nvim", "plenary-nvim": "plenary-nvim", "presence-nvim": "presence-nvim", + "project-nvim": "project-nvim", "registers": "registers", "rnix-lsp": "rnix-lsp", "rust-tools": "rust-tools", diff --git a/flake.nix b/flake.nix index 06087f8..ea6eaac 100644 --- a/flake.nix +++ b/flake.nix @@ -292,6 +292,12 @@ flake = false; }; + # Project Management + project-nvim = { + url = "github:ahmedkhalf/project.nvim"; + flake = false; + }; + # Visuals nvim-cursorline = { url = "github:yamatsum/nvim-cursorline"; diff --git a/lib/default.nix b/lib/default.nix index bf12f0d..873f31b 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -2,8 +2,4 @@ dag = import ./dag.nix {inherit lib;}; booleans = import ./booleans.nix {inherit lib;}; types = import ./types {inherit lib;}; - - imports = [ - ./assertions.nix - ]; } diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 5bb53a8..3ff9dd1 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -78,6 +78,7 @@ with lib; let "modes-nvim" "vim-repeat" "smartcolumn" + "project-nvim" ]; # You can either use the name of the plugin or a package. pluginsType = with types; diff --git a/modules/modules.nix b/modules/modules.nix index 7efd9c9..47e9eb8 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -29,6 +29,7 @@ ./assistant ./session ./comments + ./projects ]; pkgsModule = {config, ...}: { diff --git a/modules/projects/default.nix b/modules/projects/default.nix new file mode 100644 index 0000000..aa04d03 --- /dev/null +++ b/modules/projects/default.nix @@ -0,0 +1,5 @@ +_: { + imports = [ + ./project-nvim + ]; +} diff --git a/modules/projects/project-nvim/config.nix b/modules/projects/project-nvim/config.nix new file mode 100644 index 0000000..c0faff4 --- /dev/null +++ b/modules/projects/project-nvim/config.nix @@ -0,0 +1,62 @@ +{ + config, + lib, + ... +}: +with lib; +with builtins; { + options.vim.projects.project-nvim = { + enable = mkEnableOption "Enable project-nvim for project management"; + + manualMode = mkOption { + type = types.bool; + default = true; + description = "don't automatically change the root directory so the user has the option to manually do so using `:ProjectRoot` command"; + }; + + # detection methods should accept one or more strings from a list + detectionMethods = mkOption { + type = types.listOf types.str; + default = ["lsp" "pattern"]; + description = "Detection methods to use"; + }; + + # patterns + patterns = mkOption { + type = types.listOf types.str; + default = [".git" "_darcs" ".hg" ".bzr" ".svn" "Makefile" "package.json" "flake.nix" "cargo.toml"]; + description = "Patterns to use for pattern detection method"; + }; + + # table of lsp servers to ignore by name + lspIgnored = mkOption { + type = types.listOf types.str; + default = []; + description = "LSP servers no ignore by name"; + }; + + excludeDirs = mkOption { + type = types.listOf types.str; + default = []; + description = "Directories to exclude from project root search"; + }; + + showHidden = mkOption { + type = types.bool; + default = false; + description = "Show hidden files in telescope picker"; + }; + + silentChdir = mkOption { + type = types.bool; + default = true; + description = "Silently change directory when changing project"; + }; + + scopeChdir = mkOption { + type = types.enum ["global" "tab" "win"]; + default = "global"; + description = "What scope to change the directory"; + }; + }; +} diff --git a/modules/projects/project-nvim/default.nix b/modules/projects/project-nvim/default.nix new file mode 100644 index 0000000..db404ae --- /dev/null +++ b/modules/projects/project-nvim/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./config.nix + ./project-nvim.nix + ]; +} diff --git a/modules/projects/project-nvim/project-nvim.nix b/modules/projects/project-nvim/project-nvim.nix new file mode 100644 index 0000000..d78e10f --- /dev/null +++ b/modules/projects/project-nvim/project-nvim.nix @@ -0,0 +1,51 @@ +{ + config, + lib, + ... +}: +with lib; +with builtins; let + cfg = config.vim.projects.project-nvim; +in { + config = mkIf cfg.enable { + vim.startPlugins = [ + "project-nvim" + ]; + + vim.luaConfigRC.project-nvim = nvim.dag.entryAnywhere '' + require('project_nvim').setup({ + manual_mode = ${boolToString cfg.manualMode}, + detection_methods = { ${concatStringsSep ", " (map (x: "\"" + x + "\"") cfg.detectionMethods)} }, + + -- All the patterns used to detect root dir, when **"pattern"** is in + -- detection_methods + patterns = { ${concatStringsSep ", " (map (x: "\"" + x + "\"") cfg.patterns)} }, + + -- Table of lsp clients to ignore by name + -- eg: { "efm", ... } + ignore_lsp = { ${concatStringsSep ", " (map (x: "\"" + x + "\"") cfg.lspIgnored)} }, + + -- Don't calculate root dir on specific directories + -- Ex: { "~/.cargo/*", ... } + exclude_dirs = { ${concatStringsSep ", " (map (x: "\"" + x + "\"") cfg.excludeDirs)} }, + + -- Show hidden files in telescope + show_hidden = ${boolToString cfg.showHidden}, + + -- When set to false, you will get a message when project.nvim changes your + -- directory. + silent_chdir = ${boolToString cfg.silentChdir}, + + -- What scope to change the directory, valid options are + -- * global (default) + -- * tab + -- * win + scope_chdir = '${toString cfg.scopeChdir}', + + -- Path where project.nvim will store the project history for use in + -- telescope + datapath = vim.fn.stdpath("data"), + }) + ''; + }; +} diff --git a/modules/utility/telescope/config.nix b/modules/utility/telescope/config.nix index 3caae1b..36b1823 100644 --- a/modules/utility/telescope/config.nix +++ b/modules/utility/telescope/config.nix @@ -109,6 +109,12 @@ in { then "telescope.load_extension('notify')" else "" } + + ${ + if config.vim.projects.project-nvim.enable + then "telescope.load_extension('projects')" + else "" + } ''; }; }