From e00ad1f653e8d4ec22e2ae84958a3e9bfd9391ca Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 7 Apr 2023 20:31:43 +0300 Subject: [PATCH 1/7] feat: add project-nvim to plugin imports --- flake.lock | 17 +++++++++++++++++ flake.nix | 6 ++++++ lib/default.nix | 4 ---- lib/types/plugins.nix | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) 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; From 3065032ad2f19ea1a131b126dca92ae203371d48 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 7 Apr 2023 20:35:04 +0300 Subject: [PATCH 2/7] feat: add project-nvim --- modules/projects/default.nix | 5 ++ modules/projects/project-nvim/config.nix | 63 +++++++++++++++++++ modules/projects/project-nvim/default.nix | 6 ++ .../projects/project-nvim/project-nvim.nix | 51 +++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 modules/projects/project-nvim/config.nix create mode 100644 modules/projects/project-nvim/default.nix create mode 100644 modules/projects/project-nvim/project-nvim.nix diff --git a/modules/projects/default.nix b/modules/projects/default.nix index e69de29..aa04d03 100644 --- a/modules/projects/default.nix +++ 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..1a4dc63 --- /dev/null +++ b/modules/projects/project-nvim/config.nix @@ -0,0 +1,63 @@ +{ + 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"), + }) + ''; + }; +} From 9651e35f3ec429a7642d4e3ef434aa19af307890 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 7 Apr 2023 20:36:03 +0300 Subject: [PATCH 3/7] feat: add telescope extension for project-nvim --- modules/utility/telescope/config.nix | 6 ++++++ 1 file changed, 6 insertions(+) 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 "" + } ''; }; } From 170eccea99041c55e3e10e7f653118bc45cf5034 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 7 Apr 2023 20:36:16 +0300 Subject: [PATCH 4/7] feat: import project-nvim module --- modules/modules.nix | 1 + 1 file changed, 1 insertion(+) 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, ...}: { From e0e0015d1dd6d2c4b975f00e881bf73c6aeecfe2 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 7 Apr 2023 20:36:27 +0300 Subject: [PATCH 5/7] feat: project-nvim config option --- extra.nix | 4 ++++ 1 file changed, 4 insertions(+) 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; From ff04cd8a6f0910ff856214bb9487d17d16d3eed6 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 7 Apr 2023 20:47:51 +0300 Subject: [PATCH 6/7] CI: also check for formatting --- .github/workflows/check.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1620a7c..9dc71b3 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,4 +1,4 @@ -name: "Check validity of flakes" +name: "Validate flake & check formatting" on: pull_request: workflow_dispatch: @@ -11,6 +11,7 @@ on: - .gitignore jobs: nix-flake-check: + name: Validate Flake runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -19,3 +20,16 @@ jobs: extra_nix_config: | access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - run: nix flake check + format-with-alejandra: + name: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v18 + with: + install_url: https://nixos.org/nix/install + extra_nix_config: | + auto-optimise-store = true + experimental-features = nix-command flakes + - run: nix run nixpkgs#alejandra -- -c . + From f9543ea800c5475d9205a778116264a2ac66fe91 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 7 Apr 2023 20:54:51 +0300 Subject: [PATCH 7/7] style: formatting --- modules/projects/project-nvim/config.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/projects/project-nvim/config.nix b/modules/projects/project-nvim/config.nix index 1a4dc63..c0faff4 100644 --- a/modules/projects/project-nvim/config.nix +++ b/modules/projects/project-nvim/config.nix @@ -60,4 +60,3 @@ with builtins; { }; }; } -