From 6d3f28283fc1b36ae39772c221976fde1dfbb90e Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 8 Mar 2024 20:34:19 +0300 Subject: [PATCH] modules/languages: switch to explicit lib calls --- modules/languages/clang.nix | 30 +++++++++++++++---------- modules/languages/markdown/config.nix | 8 +++---- modules/languages/markdown/markdown.nix | 20 ++++++++++------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/modules/languages/clang.nix b/modules/languages/clang.nix index ee40edf..16cf337 100644 --- a/modules/languages/clang.nix +++ b/modules/languages/clang.nix @@ -1,19 +1,25 @@ { - pkgs, config, + pkgs, lib, ... }: let inherit (builtins) attrNames; - inherit (lib) isList nvim optionalString mkEnableOption mkOption types mkIf mkMerge; + inherit (lib.lists) isList; + inherit (lib) nvim; + inherit (lib.strings) optionalString; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) bool enum package either listOf str nullOr; + inherit (lib.modules) mkIf mkMerge; - cfg = config.vim.languages.clang; - - defaultServer = "ccls"; packageToCmd = package: defaultCmd: if isList cfg.lsp.package then nvim.lua.expToLua cfg.lsp.package else ''{ "${cfg.lsp.package}/bin/${defaultCmd}" }''; + + cfg = config.vim.languages.clang; + + defaultServer = "ccls"; servers = { ccls = { package = pkgs.ccls; @@ -79,7 +85,7 @@ in { C syntax for headers. Can fix treesitter errors, see: https://www.reddit.com/r/neovim/comments/orfpcd/question_does_the_c_parser_from_nvimtreesitter/ ''; - type = types.bool; + type = bool; default = false; }; @@ -94,20 +100,20 @@ in { server = mkOption { description = "The clang LSP server to use"; - type = with types; enum (attrNames servers); + type = enum (attrNames servers); default = defaultServer; }; package = mkOption { description = "clang LSP server package, or the command to run as a list of strings"; example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; - type = with types; either package (listOf str); + type = either package (listOf str); default = servers.${cfg.lsp.server}.package; }; opts = mkOption { description = "Options to pass to clang LSP server"; - type = with types; nullOr str; + type = nullOr str; default = null; }; }; @@ -115,17 +121,17 @@ in { dap = { enable = mkOption { description = "Enable clang Debug Adapter"; - type = types.bool; + type = bool; default = config.vim.languages.enableDAP; }; debugger = mkOption { description = "clang debugger to use"; - type = with types; enum (attrNames debuggers); + type = enum (attrNames debuggers); default = defaultDebugger; }; package = mkOption { description = "clang debugger package."; - type = types.package; + type = package; default = debuggers.${cfg.dap.debugger}.package; }; }; diff --git a/modules/languages/markdown/config.nix b/modules/languages/markdown/config.nix index 964bb69..ccc8836 100644 --- a/modules/languages/markdown/config.nix +++ b/modules/languages/markdown/config.nix @@ -4,7 +4,9 @@ lib, ... }: let - inherit (lib) nvim mkIf mkMerge isList; + inherit (lib.nvim.lua) expToLua; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.lists) isList; cfg = config.vim.languages.markdown; servers = { @@ -16,7 +18,7 @@ on_attach = default_on_attach; cmd = ${ if isList cfg.lsp.package - then nvim.lua.expToLua cfg.lsp.package + then expToLua cfg.lsp.package else ''{"${cfg.lsp.package}/bin/marksman", "server"}'' }, } @@ -27,13 +29,11 @@ in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.mdPackage cfg.treesitter.mdInlinePackage]; }) (mkIf cfg.lsp.enable { vim.lsp.lspconfig.enable = true; - vim.lsp.lspconfig.sources.markdown-lsp = servers.${cfg.lsp.server}.lspConfig; }) ]); diff --git a/modules/languages/markdown/markdown.nix b/modules/languages/markdown/markdown.nix index fe272c1..a58be2a 100644 --- a/modules/languages/markdown/markdown.nix +++ b/modules/languages/markdown/markdown.nix @@ -1,11 +1,15 @@ { - pkgs, config, + pkgs, lib, ... }: let inherit (builtins) attrNames; - inherit (lib) mkEnableOption mkOption types nvim isList; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.lists) isList; + inherit (lib.types) bool enum either package listOf str; + inherit (lib.nvim.lua) expToLua; + inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.markdown; defaultServer = "marksman"; @@ -18,7 +22,7 @@ on_attach = default_on_attach; cmd = ${ if isList cfg.lsp.package - then nvim.lua.expToLua cfg.lsp.package + then expToLua cfg.lsp.package else ''{"${cfg.lsp.package}/bin/marksman", "server"}'' }, } @@ -32,11 +36,11 @@ in { treesitter = { enable = mkOption { description = "Enable Markdown treesitter"; - type = types.bool; + type = bool; default = config.vim.languages.enableTreesitter; }; - mdPackage = nvim.types.mkGrammarOption pkgs "markdown"; - mdInlinePackage = nvim.types.mkGrammarOption pkgs "markdown-inline"; + mdPackage = mkGrammarOption pkgs "markdown"; + mdInlinePackage = mkGrammarOption pkgs "markdown-inline"; }; lsp = { @@ -44,14 +48,14 @@ in { server = mkOption { description = "Markdown LSP server to use"; - type = with types; enum (attrNames servers); + type = enum (attrNames servers); default = defaultServer; }; package = mkOption { description = "Markdown LSP server package, or the command to run as a list of strings"; example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; - type = with types; either package (listOf str); + type = either package (listOf str); default = servers.${cfg.lsp.server}.package; }; };