From ad5feeba7b49e3a0d3c2fd5f07884eb8f3f4e537 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Tue, 28 Nov 2023 00:01:49 +0100 Subject: [PATCH] plugins/project-nvim: add option descriptions and tests --- plugins/utils/project-nvim.nix | 139 +++++++++--------- .../plugins/utils/project-nvim.nix | 21 +++ 2 files changed, 94 insertions(+), 66 deletions(-) create mode 100644 tests/test-sources/plugins/utils/project-nvim.nix diff --git a/plugins/utils/project-nvim.nix b/plugins/utils/project-nvim.nix index 7d906fcf..514f41e2 100644 --- a/plugins/utils/project-nvim.nix +++ b/plugins/utils/project-nvim.nix @@ -15,72 +15,79 @@ in { package = helpers.mkPackageOption "project-nvim" pkgs.vimPlugins.project-nvim; - manualMode = mkOption { - type = types.nullOr types.bool; - default = null; - }; - - detectionMethods = mkOption { - type = types.nullOr (types.listOf types.str); - default = null; - }; - - patterns = mkOption { - type = types.nullOr (types.listOf types.str); - default = null; - }; - - ignoreLsp = mkOption { - type = types.nullOr (types.listOf types.str); - default = null; - }; - - excludeDirs = mkOption { - type = types.nullOr (types.listOf types.str); - default = null; - }; - - showHidden = mkOption { - type = types.nullOr types.bool; - default = null; - }; - - silentChdir = mkOption { - type = types.nullOr types.bool; - default = null; - }; - - scopeChdir = mkOption { - type = types.nullOr (types.enum ["global" "tab" "win"]); - default = null; - }; - - dataPath = mkOption { - type = types.nullOr (types.either types.str helpers.rawType); - default = null; - }; - }; - - config = let - options = - { - manual_mode = cfg.manualMode; - detection_methods = cfg.detectionMethods; - inherit (cfg) patterns; - ignore_lsp = cfg.ignoreLsp; - exclude_dirs = cfg.excludeDirs; - show_hidden = cfg.showHidden; - silent_chdir = cfg.silentChdir; - scope_schdir = cfg.scopeChdir; - data_path = cfg.dataPath; - } - // cfg.extraOptions; - in - mkIf cfg.enable { - extraPlugins = [cfg.package]; - - extraConfigLua = '' - require('project_nvim').setup(${helpers.toLuaObject options}) + manualMode = helpers.defaultNullOpts.mkBool false '' + Manual mode doesn't automatically change your root directory, so you have the option to + manually do so using `:ProjectRoot` command. ''; + + detectionMethods = + helpers.defaultNullOpts.mkNullable + (with types; listOf str) + ''["lsp" "pattern"]'' + '' + Methods of detecting the root directory. + **"lsp"** uses the native neovim lsp, while **"pattern"** uses vim-rooter like glob pattern + matching. + Here order matters: if one is not detected, the other is used as fallback. + You can also delete or rearangne the detection methods. + ''; + + patterns = + helpers.defaultNullOpts.mkNullable + (with types; listOf str) + ''[".git" "_darcs" ".hg" ".bzr" ".svn" "Makefile" "package.json"]'' + '' + All the patterns used to detect root dir, when **"pattern"** is in `detectionMethods`. + ''; + + ignoreLsp = + helpers.defaultNullOpts.mkNullable + (with types; listOf str) + "[]" + "Table of lsp clients to ignore by name."; + + excludeDirs = + helpers.defaultNullOpts.mkNullable + (with types; listOf str) + "[]" + "Don't calculate root dir on specific directories."; + + showHidden = helpers.defaultNullOpts.mkBool false "Show hidden files in telescope."; + + silentChdir = helpers.defaultNullOpts.mkBool true '' + When set to false, you will get a message when `project.nvim` changes your directory. + ''; + + scopeChdir = helpers.defaultNullOpts.mkEnumFirstDefault ["global" "tab" "win"] '' + What scope to change the directory. + ''; + + dataPath = + helpers.defaultNullOpts.mkNullable + (with types; either str helpers.rawType) + ''{__raw = "vim.fn.stdpath('data')";}'' + "Path where project.nvim will store the project history for use in telescope."; }; + + config = mkIf cfg.enable { + extraPlugins = [cfg.package]; + + extraConfigLua = let + setupOptions = with cfg; + { + manual_mode = manualMode; + detection_methods = detectionMethods; + inherit patterns; + ignore_lsp = ignoreLsp; + exclude_dirs = excludeDirs; + show_hidden = showHidden; + silent_chdir = silentChdir; + scope_schdir = scopeChdir; + data_path = dataPath; + } + // cfg.extraOptions; + in '' + require('project_nvim').setup(${helpers.toLuaObject setupOptions}) + ''; + }; } diff --git a/tests/test-sources/plugins/utils/project-nvim.nix b/tests/test-sources/plugins/utils/project-nvim.nix new file mode 100644 index 00000000..60aa6ee8 --- /dev/null +++ b/tests/test-sources/plugins/utils/project-nvim.nix @@ -0,0 +1,21 @@ +{ + empty = { + plugins.project-nvim.enable = true; + }; + + defaults = { + plugins.project-nvim = { + enable = true; + + manualMode = false; + detectionMethods = ["lsp" "pattern"]; + patterns = [".git" "_darcs" ".hg" ".bzr" ".svn" "Makefile" "package.json"]; + ignoreLsp = []; + excludeDirs = []; + showHidden = false; + silentChdir = true; + scopeChdir = "global"; + dataPath.__raw = "vim.fn.stdpath('data')"; + }; + }; +}