From 6eba2a5585e3cb479a85cac0cd0c125d19fe28a9 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 6 May 2024 22:57:27 +0300 Subject: [PATCH] languages: move bash & dart configurations to standalone files --- modules/plugins/languages/{bash => }/bash.nix | 33 +++++++- modules/plugins/languages/bash/config.nix | 83 ------------------- modules/plugins/languages/bash/default.nix | 6 -- modules/plugins/languages/{dart => }/dart.nix | 74 ++++++++++++++--- modules/plugins/languages/dart/config.nix | 76 ----------------- modules/plugins/languages/dart/default.nix | 6 -- 6 files changed, 94 insertions(+), 184 deletions(-) rename modules/plugins/languages/{bash => }/bash.nix (78%) delete mode 100644 modules/plugins/languages/bash/config.nix delete mode 100644 modules/plugins/languages/bash/default.nix rename modules/plugins/languages/{dart => }/dart.nix (61%) delete mode 100644 modules/plugins/languages/dart/config.nix delete mode 100644 modules/plugins/languages/dart/default.nix diff --git a/modules/plugins/languages/bash/bash.nix b/modules/plugins/languages/bash.nix similarity index 78% rename from modules/plugins/languages/bash/bash.nix rename to modules/plugins/languages/bash.nix index 7b5de0f..1d7e1ce 100644 --- a/modules/plugins/languages/bash/bash.nix +++ b/modules/plugins/languages/bash.nix @@ -1,15 +1,17 @@ { - pkgs, config, + pkgs, lib, ... }: let inherit (builtins) attrNames; inherit (lib.options) mkOption mkEnableOption literalExpression; + inherit (lib.modules) mkIf mkMerge; inherit (lib.lists) isList; inherit (lib.types) enum either package listOf str bool; - inherit (lib.nvim.lua) expToLua; + inherit (lib.nvim.languages) diagnosticsToLua; inherit (lib.nvim.types) diagnostics mkGrammarOption; + inherit (lib.nvim.lua) expToLua; cfg = config.vim.languages.bash; @@ -55,6 +57,7 @@ ls_sources, null_ls.builtins.diagnostics.shellcheck.with({ command = "${pkg}/bin/shellcheck", + diagnostics_format = "#{m} [#{c}]" }) ) ''; @@ -114,4 +117,30 @@ in { }; }; }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.package]; + }) + + (mkIf cfg.lsp.enable { + vim.lsp.lspconfig.enable = true; + vim.lsp.lspconfig.sources.bash-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + + (mkIf cfg.format.enable { + vim.lsp.null-ls.enable = true; + vim.lsp.null-ls.sources.bash-format = formats.${cfg.format.type}.nullConfig; + }) + + (mkIf cfg.extraDiagnostics.enable { + vim.lsp.null-ls.enable = true; + vim.lsp.null-ls.sources = diagnosticsToLua { + lang = "bash"; + config = cfg.extraDiagnostics.types; + inherit diagnosticsProviders; + }; + }) + ]); } diff --git a/modules/plugins/languages/bash/config.nix b/modules/plugins/languages/bash/config.nix deleted file mode 100644 index 7f2a70a..0000000 --- a/modules/plugins/languages/bash/config.nix +++ /dev/null @@ -1,83 +0,0 @@ -{ - pkgs, - config, - lib, - ... -}: let - inherit (lib.lists) isList; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.lua) expToLua; - inherit (lib.nvim.languages) diagnosticsToLua; - - cfg = config.vim.languages.bash; - diagnosticsProviders = { - shellcheck = { - package = pkgs.shellcheck; - nullConfig = pkg: '' - table.insert( - ls_sources, - null_ls.builtins.diagnostics.shellcheck.with({ - command = "${pkg}/bin/shellcheck", - }) - ) - ''; - }; - }; - - formats = { - shfmt = { - package = pkgs.shfmt; - nullConfig = '' - table.insert( - ls_sources, - null_ls.builtins.formatting.shfmt.with({ - command = "${pkgs.shfmt}/bin/shfmt", - }) - ) - ''; - }; - }; - - servers = { - bash-ls = { - package = pkgs.nodePackages.bash-language-server; - lspConfig = '' - lspconfig.bashls.setup{ - capabilities = capabilities; - on_attach = default_on_attach; - cmd = ${ - if isList cfg.lsp.package - then expToLua cfg.lsp.package - else ''{"${cfg.lsp.package}/bin/bash-language-server", "start"}'' - }; - } - ''; - }; - }; -in { - config = mkIf cfg.enable (mkMerge [ - (mkIf cfg.treesitter.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.package]; - }) - - (mkIf cfg.lsp.enable { - vim.lsp.lspconfig.enable = true; - vim.lsp.lspconfig.sources.bash-lsp = servers.${cfg.lsp.server}.lspConfig; - }) - - (mkIf cfg.format.enable { - vim.lsp.null-ls.enable = true; - vim.lsp.null-ls.sources.bash-format = formats.${cfg.format.type}.nullConfig; - }) - - (mkIf cfg.extraDiagnostics.enable { - vim.lsp.null-ls.enable = true; - vim.lsp.null-ls.sources = diagnosticsToLua { - lang = "bash"; - config = cfg.extraDiagnostics.types; - inherit diagnosticsProviders; - }; - }) - ]); -} diff --git a/modules/plugins/languages/bash/default.nix b/modules/plugins/languages/bash/default.nix deleted file mode 100644 index 7bb1ea2..0000000 --- a/modules/plugins/languages/bash/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - imports = [ - ./bash.nix - ./config.nix - ]; -} diff --git a/modules/plugins/languages/dart/dart.nix b/modules/plugins/languages/dart.nix similarity index 61% rename from modules/plugins/languages/dart/dart.nix rename to modules/plugins/languages/dart.nix index 13ce3d9..8f957c9 100644 --- a/modules/plugins/languages/dart/dart.nix +++ b/modules/plugins/languages/dart.nix @@ -1,18 +1,23 @@ { config, - lib, pkgs, + lib, ... }: let inherit (builtins) attrNames; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.trivial) boolToString; inherit (lib.lists) isList; inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) enum either listOf package nullOr str bool; inherit (lib.strings) optionalString; inherit (lib.nvim.lua) expToLua; inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.languages.dart; + ftcfg = cfg.flutter-tools; + defaultServer = "dart"; servers = { dart = { @@ -48,15 +53,16 @@ in { default = defaultServer; }; package = mkOption { - description = "Dart 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 = either package (listOf str); default = servers.${cfg.lsp.server}.package; + example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]''; + description = "Dart LSP server package, or the command to run as a list of strings"; }; + opts = mkOption { - description = "Options to pass to Dart LSP server"; type = nullOr str; default = null; + description = "Options to pass to Dart LSP server"; }; }; @@ -70,23 +76,26 @@ in { flutter-tools = { enable = mkOption { - description = "Enable flutter-tools for flutter support"; type = bool; default = config.vim.languages.enableLSP; + description = "Enable flutter-tools for flutter support"; }; enableNoResolvePatch = mkOption { - description = '' - Patch flutter-tools so that it doesn't resolve symlinks when detecting flutter path. - This is required if you want to use a flutter package built with nix. - If you are using a flutter SDK installed from a different source and encounter the error "`dart` missing from PATH", disable this option. - ''; type = bool; default = true; + description = '' + Whether to patch flutter-tools so that it doesn't resolve + symlinks when detecting flutter path. + + This is required if you want to use a flutter package built with nix. + If you are using a flutter SDK installed from a different source + and encounter the error "`dart` missing from PATH", disable this option. + ''; }; color = { - enable = mkEnableOption "Whether or mot to highlight color variables at all"; + enable = mkEnableOption "highlighting color variables"; highlightBackground = mkOption { type = bool; @@ -112,4 +121,47 @@ in { }; }; }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.package]; + }) + + (mkIf cfg.lsp.enable { + vim.lsp.lspconfig.enable = true; + + vim.lsp.lspconfig.sources.dart-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + + (mkIf ftcfg.enable { + vim.startPlugins = + if ftcfg.enableNoResolvePatch + then ["flutter-tools-patched"] + else ["flutter-tools"]; + + vim.luaConfigRC.flutter-tools = entryAnywhere '' + require('flutter-tools').setup { + lsp = { + color = { -- show the derived colours for dart variables + enabled = ${boolToString ftcfg.color.enable}, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10 + background = ${boolToString ftcfg.color.highlightBackground}, -- highlight the background + foreground = ${boolToString ftcfg.color.highlightForeground}, -- highlight the foreground + virtual_text = ${boolToString ftcfg.color.virtualText.enable}, -- show the highlight using virtual text + virtual_text_str = ${ftcfg.color.virtualText.character} -- the virtual text character to highlight + }, + + capabilities = capabilities, + on_attach = default_on_attach; + flags = lsp_flags, + }, + ${optionalString cfg.dap.enable '' + debugger = { + enabled = true, + }, + ''} + } + ''; + }) + ]); } diff --git a/modules/plugins/languages/dart/config.nix b/modules/plugins/languages/dart/config.nix deleted file mode 100644 index be7c111..0000000 --- a/modules/plugins/languages/dart/config.nix +++ /dev/null @@ -1,76 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: let - inherit (lib.lists) isList; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.strings) optionalString; - inherit (lib.trivial) boolToString; - inherit (lib.nvim.lua) expToLua; - inherit (lib.nvim.dag) entryAnywhere; - - cfg = config.vim.languages.dart; - ftcfg = cfg.flutter-tools; - servers = { - dart = { - package = pkgs.dart; - lspConfig = '' - lspconfig.dartls.setup{ - capabilities = capabilities; - on_attach=default_on_attach; - cmd = ${ - if isList cfg.lsp.package - then expToLua cfg.lsp.package - else ''{"${cfg.lsp.package}/bin/dart", "language-server", "--protocol=lsp"}'' - }; - ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.dartOpts}"} - } - ''; - }; - }; -in { - config = mkIf cfg.enable (mkMerge [ - (mkIf cfg.treesitter.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.package]; - }) - - (mkIf cfg.lsp.enable { - vim.lsp.lspconfig.enable = true; - - vim.lsp.lspconfig.sources.dart-lsp = servers.${cfg.lsp.server}.lspConfig; - }) - - (mkIf ftcfg.enable { - vim.startPlugins = - if ftcfg.enableNoResolvePatch - then ["flutter-tools-patched"] - else ["flutter-tools"]; - - vim.luaConfigRC.flutter-tools = entryAnywhere '' - require('flutter-tools').setup { - lsp = { - color = { -- show the derived colours for dart variables - enabled = ${boolToString ftcfg.color.enable}, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10 - background = ${boolToString ftcfg.color.highlightBackground}, -- highlight the background - foreground = ${boolToString ftcfg.color.highlightForeground}, -- highlight the foreground - virtual_text = ${boolToString ftcfg.color.virtualText.enable}, -- show the highlight using virtual text - virtual_text_str = ${ftcfg.color.virtualText.character} -- the virtual text character to highlight - }, - - capabilities = capabilities, - on_attach = default_on_attach; - flags = lsp_flags, - }, - ${optionalString cfg.dap.enable '' - debugger = { - enabled = true, - }, - ''} - } - ''; - }) - ]); -} diff --git a/modules/plugins/languages/dart/default.nix b/modules/plugins/languages/dart/default.nix deleted file mode 100644 index 2ad34f3..0000000 --- a/modules/plugins/languages/dart/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - imports = [ - ./dart.nix - ./config.nix - ]; -}