From 6c733505577c84ef4a7c6659a7118da874f144dd Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 26 Apr 2025 19:26:21 +0100 Subject: [PATCH] modules/diagnostic: rename `diagnostics` -> `diagnostic.config` Currently we represent `vim.diagnostic.config()` as a top-level `diagnostics` option. This means we have no clear namespace for (e.g.) `vim.diagnostic.` keymap functions. --- modules/default.nix | 2 +- modules/diagnostic.nix | 32 +++++++++++++++++++ modules/diagnostics.nix | 25 --------------- plugins/by-name/lsp-lines/default.nix | 5 +-- tests/test-sources/modules/diagnostics.nix | 2 +- .../plugins/by-name/lsp-lines/default.nix | 2 +- 6 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 modules/diagnostic.nix delete mode 100644 modules/diagnostics.nix diff --git a/modules/default.nix b/modules/default.nix index 91977e66..b0fa8f54 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -10,7 +10,7 @@ ./colorscheme.nix ./commands.nix ./dependencies.nix - ./diagnostics.nix + ./diagnostic.nix ./doc.nix ./editorconfig.nix ./files.nix diff --git a/modules/diagnostic.nix b/modules/diagnostic.nix new file mode 100644 index 00000000..b4a67a77 --- /dev/null +++ b/modules/diagnostic.nix @@ -0,0 +1,32 @@ +{ + lib, + config, + ... +}: +let + cfg = config.diagnostic; +in +{ + options.diagnostic = { + config = lib.mkOption { + type = with lib.types; attrsOf anything; + default = { }; + description = "The configuration diagnostic options, provided to `vim.diagnostic.config`."; + example = { + virtual_text = false; + virtual_lines.current_line = true; + }; + }; + }; + + imports = [ + # TODO: Added 2025-04-26; remove after 25.05 + (lib.mkRenamedOptionModule [ "diagnostics" ] [ "diagnostic" "config" ]) + ]; + + config = { + extraConfigLuaPre = lib.mkIf (cfg.config != { }) '' + vim.diagnostic.config(${lib.nixvim.toLuaObject cfg.config}) + ''; + }; +} diff --git a/modules/diagnostics.nix b/modules/diagnostics.nix deleted file mode 100644 index 332e3fa6..00000000 --- a/modules/diagnostics.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ - lib, - helpers, - config, - ... -}: -{ - options = { - diagnostics = lib.mkOption { - type = with lib.types; attrsOf anything; - default = { }; - description = "The configuration diagnostic options, provided to `vim.diagnostic.config`."; - example = { - virtual_text = false; - virtual_lines.current_line = true; - }; - }; - }; - - config = { - extraConfigLuaPre = lib.mkIf (config.diagnostics != { }) '' - vim.diagnostic.config(${lib.nixvim.toLuaObject config.diagnostics}) - ''; - }; -} diff --git a/plugins/by-name/lsp-lines/default.nix b/plugins/by-name/lsp-lines/default.nix index fa02e497..208565a5 100644 --- a/plugins/by-name/lsp-lines/default.nix +++ b/plugins/by-name/lsp-lines/default.nix @@ -24,7 +24,8 @@ lib.nixvim.plugins.mkNeovimPlugin { "currentLine" ] [ - "diagnostics" + "diagnostic" + "config" "virtual_lines" "only_current_line" ] @@ -33,6 +34,6 @@ lib.nixvim.plugins.mkNeovimPlugin { extraConfig = { # Strongly recommended by the plugin, to avoid duplication. - diagnostics.virtual_text = mkDefault false; + diagnostic.config.virtual_text = mkDefault false; }; } diff --git a/tests/test-sources/modules/diagnostics.nix b/tests/test-sources/modules/diagnostics.nix index 87a304ab..6709ab46 100644 --- a/tests/test-sources/modules/diagnostics.nix +++ b/tests/test-sources/modules/diagnostics.nix @@ -1,6 +1,6 @@ { example = { - diagnostics = { + diagnostic.config = { virtual_text = false; virtual_lines.current_line = true; }; diff --git a/tests/test-sources/plugins/by-name/lsp-lines/default.nix b/tests/test-sources/plugins/by-name/lsp-lines/default.nix index f3f26934..1390fb6a 100644 --- a/tests/test-sources/plugins/by-name/lsp-lines/default.nix +++ b/tests/test-sources/plugins/by-name/lsp-lines/default.nix @@ -6,7 +6,7 @@ example = { plugins.lsp-lines.enable = true; - diagnostics.virtual_lines = { + diagnostic.config.virtual_lines = { only_current_line = true; highlight_whole_line = false; };