From 544792e0b99229f7e8ed2e0674c2e9d3e58d78db Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 18 Apr 2023 00:55:27 +0300 Subject: [PATCH] feat: use mkGrammarOption --- extra.nix | 1 + lib/types/default.nix | 2 +- lib/types/languages.nix | 5 +++++ modules/languages/clang.nix | 12 ++---------- modules/languages/default.nix | 2 +- modules/languages/go.nix | 6 +----- modules/languages/markdown/config.nix | 5 +++++ modules/languages/markdown/markdown.nix | 9 +++++++++ modules/languages/nix.nix | 6 +----- modules/languages/python.nix | 6 +----- modules/languages/rust.nix | 6 +----- modules/languages/ts.nix | 12 ++---------- modules/languages/zig.nix | 6 +----- 13 files changed, 31 insertions(+), 47 deletions(-) diff --git a/extra.nix b/extra.nix index f7e48d58..2880d5bf 100644 --- a/extra.nix +++ b/extra.nix @@ -115,6 +115,7 @@ inputs: let vim.git = { enable = true; gitsigns.enable = true; + gitsigns.codeActions = true; }; vim.minimap = { diff --git a/lib/types/default.nix b/lib/types/default.nix index 63171603..6d5777d8 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -5,5 +5,5 @@ in { inherit (typesDag) dagOf; inherit (typesPlugin) pluginsOpt; - inherit (typesLanguage) diagnostics; + inherit (typesLanguage) diagnostics mkGrammarOption; } diff --git a/lib/types/languages.nix b/lib/types/languages.nix index 7dc57aff..577db505 100644 --- a/lib/types/languages.nix +++ b/lib/types/languages.nix @@ -23,4 +23,9 @@ in { type = with types; listOf (either (enum (attrNames diagnostics)) (submodule diagnosticSubmodule)); default = defaultDiagnostics; }; + + mkGrammarOption = pkgs: grammar: + mkPackageOption pkgs ["${grammar} treesitter"] { + default = ["vimPlugins" "nvim-treesitter" "builtGrammars" grammar]; + }; } diff --git a/modules/languages/clang.nix b/modules/languages/clang.nix index 4514329a..a9d11919 100644 --- a/modules/languages/clang.nix +++ b/modules/languages/clang.nix @@ -41,16 +41,8 @@ in { type = types.bool; default = config.vim.languages.enableTreesitter; }; - cPackage = mkOption { - description = "C treesitter grammar to use"; - type = types.package; - default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.c; - }; - cppPackage = mkOption { - description = "C++ treesitter grammar to use"; - type = types.package; - default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.cpp; - }; + cPackage = nvim.types.mkGrammarOption pkgs "c"; + cppPackage = nvim.types.mkGrammarOption pkgs "cpp"; }; lsp = { diff --git a/modules/languages/default.nix b/modules/languages/default.nix index 5e370cc7..ee7cb4cc 100644 --- a/modules/languages/default.nix +++ b/modules/languages/default.nix @@ -8,7 +8,7 @@ with lib; let }; in { imports = [ - ./markdown + ./markdown ./tidal ./clang.nix diff --git a/modules/languages/go.nix b/modules/languages/go.nix index 0ceb111f..f63a6f46 100644 --- a/modules/languages/go.nix +++ b/modules/languages/go.nix @@ -31,11 +31,7 @@ in { type = types.bool; default = config.vim.languages.enableTreesitter; }; - package = mkOption { - description = "Go treesitter grammar to use"; - type = types.package; - default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.go; - }; + package = nvim.types.mkGrammarOption pkgs "go"; }; lsp = { diff --git a/modules/languages/markdown/config.nix b/modules/languages/markdown/config.nix index 8f6e6263..bf0ef5a0 100644 --- a/modules/languages/markdown/config.nix +++ b/modules/languages/markdown/config.nix @@ -9,6 +9,11 @@ with builtins; let cfg = config.vim.languages.markdown; in { config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.package]; + }) + (mkIf cfg.glow.enable { vim.startPlugins = ["glow-nvim"]; diff --git a/modules/languages/markdown/markdown.nix b/modules/languages/markdown/markdown.nix index 706bf5da..41ab6533 100644 --- a/modules/languages/markdown/markdown.nix +++ b/modules/languages/markdown/markdown.nix @@ -16,5 +16,14 @@ in { default = true; description = "Enable markdown preview in neovim with glow"; }; + + treesitter = { + enable = mkOption { + description = "Enable Markdown treesitter"; + type = types.bool; + default = config.vim.languages.enableTreesitter; + }; + package = nvim.types.mkGrammarOption pkgs "markdown"; + }; }; } diff --git a/modules/languages/nix.nix b/modules/languages/nix.nix index f7273ac2..3313c349 100644 --- a/modules/languages/nix.nix +++ b/modules/languages/nix.nix @@ -92,11 +92,7 @@ in { type = types.bool; default = config.vim.languages.enableTreesitter; }; - package = mkOption { - description = "Nix treesitter grammar to use"; - type = types.package; - default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.nix; - }; + package = nvim.types.mkGrammarOption pkgs "nix"; }; lsp = { diff --git a/modules/languages/python.nix b/modules/languages/python.nix index c2cabda4..ab80ca67 100644 --- a/modules/languages/python.nix +++ b/modules/languages/python.nix @@ -64,11 +64,7 @@ in { type = with types; enum (attrNames servers); default = defaultServer; }; - package = mkOption { - description = "Python LSP server package"; - type = types.package; - default = servers.${cfg.lsp.server}.package; - }; + package = nvim.types.mkGrammarOption pkgs "python"; }; format = { diff --git a/modules/languages/rust.nix b/modules/languages/rust.nix index b58d8854..8c330b3b 100644 --- a/modules/languages/rust.nix +++ b/modules/languages/rust.nix @@ -17,11 +17,7 @@ in { type = types.bool; default = config.vim.languages.enableTreesitter; }; - package = mkOption { - description = "Rust treesitter grammar to use"; - type = types.package; - default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.rust; - }; + package = nvim.types.mkGrammarOption pkgs "rust"; }; crates = { diff --git a/modules/languages/ts.nix b/modules/languages/ts.nix index 318b623f..d1c97961 100644 --- a/modules/languages/ts.nix +++ b/modules/languages/ts.nix @@ -63,16 +63,8 @@ in { type = types.bool; default = config.vim.languages.enableTreesitter; }; - tsPackage = mkOption { - description = "Typescript treesitter grammar to use"; - type = types.package; - default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.tsx; - }; - jsPackage = mkOption { - description = "Javascript treesitter grammar to use"; - type = types.package; - default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.javascript; - }; + tsPackage = nvim.types.mkGrammarOption pkgs "tsx"; + jsPackage = nvim.types.mkGrammarOption pkgs "javascript"; }; lsp = { diff --git a/modules/languages/zig.nix b/modules/languages/zig.nix index 8dbcb7fc..0ce85db8 100644 --- a/modules/languages/zig.nix +++ b/modules/languages/zig.nix @@ -17,11 +17,7 @@ in { type = types.bool; default = config.vim.languages.enableTreesitter; }; - package = mkOption { - description = "Zig treesitter grammar to use"; - type = types.package; - default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.zig; - }; + package = nvim.types.mkGrammarOption pkgs "zig"; }; lsp = { enable = mkOption {