diff --git a/modules/projects/project-nvim/config.nix b/modules/projects/project-nvim/config.nix index 5c036ef..435476d 100644 --- a/modules/projects/project-nvim/config.nix +++ b/modules/projects/project-nvim/config.nix @@ -3,10 +3,7 @@ lib, ... }: let - inherit (lib.modules) mkIf; - inherit (lib.trivial) boolToString; - inherit (lib.strings) concatStringsSep; - inherit (lib.nvim.dag) entryAnywhere; + inherit (lib) mkIf nvim; cfg = config.vim.projects.project-nvim; in { @@ -15,40 +12,8 @@ in { "project-nvim" ]; - vim.luaConfigRC.project-nvim = 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"), - }) + vim.luaConfigRC.project-nvim = nvim.dag.entryAnywhere '' + require('project_nvim').setup(${nvim.lua.toLuaObject cfg.setupOpts}) ''; }; } diff --git a/modules/projects/project-nvim/project-nvim.nix b/modules/projects/project-nvim/project-nvim.nix index 9331f37..234e4f0 100644 --- a/modules/projects/project-nvim/project-nvim.nix +++ b/modules/projects/project-nvim/project-nvim.nix @@ -1,59 +1,80 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) enum bool listOf str; +{ + config, + lib, + ... +}: let + inherit (lib) mkEnableOption mkOption types mkRenamedOptionModule; in { + imports = let + renamedSetupOption = oldPath: newPath: + mkRenamedOptionModule + (["vim" "projects" "project-nvim"] ++ oldPath) + (["vim" "projects" "project-nvim" "setupOpts"] ++ newPath); + in [ + (renamedSetupOption ["manualMode"] ["manual_mode"]) + (renamedSetupOption ["detectionMethods"] ["detection_methods"]) + (renamedSetupOption ["patterns"] ["patterns"]) + (renamedSetupOption ["lspIgnored"] ["lsp_ignored"]) + (renamedSetupOption ["excludeDirs"] ["exclude_dirs"]) + (renamedSetupOption ["showHidden"] ["show_hidden"]) + (renamedSetupOption ["silentChdir"] ["silent_chdir"]) + (renamedSetupOption ["scopeChdir"] ["scope_chdir"]) + ]; + options.vim.projects.project-nvim = { enable = mkEnableOption "project-nvim for project management"; - manualMode = mkOption { - type = bool; - default = true; - description = "don't automatically change the root directory so the user has the option to manually do so using `:ProjectRoot` command"; - }; + setupOpts = lib.nvim.types.mkPluginSetupOption "Project.nvim" { + manual_mode = 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 = listOf str; - default = ["lsp" "pattern"]; - description = "Detection methods to use"; - }; + # detection methods should accept one or more strings from a list + detection_methods = mkOption { + type = types.listOf types.str; + default = ["lsp" "pattern"]; + description = "Detection methods to use"; + }; - # patterns - patterns = mkOption { - type = listOf str; - default = [".git" "_darcs" ".hg" ".bzr" ".svn" "Makefile" "package.json" "flake.nix" "cargo.toml"]; - description = "Patterns to use for pattern detection method"; - }; + # 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 = listOf str; - default = []; - description = "LSP servers no ignore by name"; - }; + # table of lsp servers to ignore by name + lsp_ignored = mkOption { + type = types.listOf types.str; + default = []; + description = "LSP servers no ignore by name"; + }; - excludeDirs = mkOption { - type = listOf str; - default = []; - description = "Directories to exclude from project root search"; - }; + exclude_dirs = mkOption { + type = types.listOf types.str; + default = []; + description = "Directories to exclude from project root search"; + }; - showHidden = mkOption { - type = bool; - default = false; - description = "Show hidden files in telescope picker"; - }; + show_hidden = mkOption { + type = types.bool; + default = false; + description = "Show hidden files in telescope picker"; + }; - silentChdir = mkOption { - type = bool; - default = true; - description = "Silently change directory when changing project"; - }; + silent_chdir = mkOption { + type = types.bool; + default = true; + description = "Silently change directory when changing project"; + }; - scopeChdir = mkOption { - type = enum ["global" "tab" "win"]; - default = "global"; - description = "What scope to change the directory"; + scope_chdir = mkOption { + type = types.enum ["global" "tab" "win"]; + default = "global"; + description = "What scope to change the directory"; + }; }; }; }