From 3065032ad2f19ea1a131b126dca92ae203371d48 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 7 Apr 2023 20:35:04 +0300 Subject: [PATCH] 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"), + }) + ''; + }; +}