plugins/project-nvim: add option descriptions and tests

This commit is contained in:
Gaetan Lepage 2023-11-28 00:01:49 +01:00 committed by Gaétan Lepage
parent a13638c0e8
commit ad5feeba7b
2 changed files with 94 additions and 66 deletions

View file

@ -15,72 +15,79 @@ in {
package = helpers.mkPackageOption "project-nvim" pkgs.vimPlugins.project-nvim; package = helpers.mkPackageOption "project-nvim" pkgs.vimPlugins.project-nvim;
manualMode = mkOption { manualMode = helpers.defaultNullOpts.mkBool false ''
type = types.nullOr types.bool; Manual mode doesn't automatically change your root directory, so you have the option to
default = null; manually do so using `:ProjectRoot` command.
};
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})
''; '';
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})
'';
};
} }

View file

@ -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')";
};
};
}