diff --git a/plugins/by-name/clangd-extensions/default.nix b/plugins/by-name/clangd-extensions/default.nix index 8299e5fabb..abed68b46a 100644 --- a/plugins/by-name/clangd-extensions/default.nix +++ b/plugins/by-name/clangd-extensions/default.nix @@ -1,271 +1,164 @@ -{ - lib, - helpers, - config, - pkgs, - ... -}: -with lib; +{ config, lib, ... }: let - cfg = config.plugins.clangd-extensions; + inherit (lib.nixvim) defaultNullOpts; + inherit (lib) types mapAttrs; +in +lib.nixvim.plugins.mkNeovimPlugin { + name = "clangd-extensions"; + moduleName = "clangd_extensions"; + packPathName = "clangd_extensions.nvim"; + package = "clangd_extensions-nvim"; + description = '' + Clangd's off-spec features for neovim's LSP client. + ''; - basePluginPath = [ - "plugins" - "clangd-extensions" - ]; + maintainers = [ lib.maintainers.jolars ]; - borderOpt = helpers.defaultNullOpts.mkBorder "none" "clangd-extensions" ""; -in -{ # All of those warnings were introduced on 08/22/2023. # TODO: Remove them in ~2 months (Oct. 2023). - imports = - [ - (mkRemovedOptionModule (basePluginPath ++ [ "server" ]) '' - To configure the `clangd` language server options, please use - `plugins.lsp.servers.clangd.extraSettings`. - '') - (mkRemovedOptionModule ( - basePluginPath - ++ [ - "extensions" - "autoSetHints" - ] - ) "") - ] - ++ (map - ( - optionPath: - mkRenamedOptionModule (basePluginPath ++ [ "extensions" ] ++ optionPath) ( - basePluginPath ++ optionPath - ) - ) - [ - [ - "inlayHints" - "inline" - ] - [ - "inlayHints" - "onlyCurrentLine" - ] - [ - "inlayHints" - "onlyCurrentLineAutocmd" - ] - [ - "inlayHints" - "showParameterHints" - ] - [ - "inlayHints" - "parameterHintsPrefix" - ] - [ - "inlayHints" - "otherHintsPrefix" - ] - [ - "inlayHints" - "maxLenAlign" - ] - [ - "inlayHints" - "maxLenAlignPadding" - ] - [ - "inlayHints" - "rightAlign" - ] - [ - "inlayHints" - "rightAlignPadding" - ] - [ - "inlayHints" - "highlight" - ] - [ - "inlayHints" - "priority" - ] - [ "ast" ] - [ "memoryUsage" ] - [ "symbolInfo" ] - ] - ); + imports = [ ./deprecations.nix ]; - options.plugins.clangd-extensions = lib.nixvim.plugins.neovim.extraOptionsOptions // { - enable = mkEnableOption "clangd_extensions, plugins implementing clangd LSP extensions"; + # TODO: introduced 2025-01-08: remove after 25.05 + optionsRenamedToSettings = import ./renamed-options.nix; - package = lib.mkPackageOption pkgs "clangd_extensions.nvim" { - default = [ - "vimPlugins" - "clangd_extensions-nvim" - ]; - }; + settingsOptions = + let + mkBorderOpt = defaultNullOpts.mkBorder "none" "clangd-extensions"; + in + { + inlay_hints = { + inline = defaultNullOpts.mkBool true '' + Show hints inline. + ''; - enableOffsetEncodingWorkaround = mkEnableOption '' - utf-16 offset encoding. This is used to work around the warning: - "multiple different client offset_encodings detected for buffer, this is not supported yet" - ''; + only_current_line = defaultNullOpts.mkBool false '' + Only show inlay hints for the current line. + ''; - inlayHints = { - inline = helpers.defaultNullOpts.mkLua ''vim.fn.has("nvim-0.10") == 1'' '' - Show hints inline. - ''; + only_current_line_autocmd = defaultNullOpts.mkListOf types.str [ "CursorHold" ] '' + Event which triggers a refresh of the inlay hints. You can make this + `[ "CursorMoved" ]` or `[ "CursorMoved" "CursorMovedI" ]` but not that this may cause + higher CPU usage. This option is only respected when `only_current_line` + is true. + ''; - onlyCurrentLine = helpers.defaultNullOpts.mkBool false "Only show inlay hints for the current line"; + show_parameter_hints = defaultNullOpts.mkBool true '' + Whether to show parameter hints with the inlay hints or not. + ''; - onlyCurrentLineAutocmd = helpers.defaultNullOpts.mkStr "CursorHold" '' - Event which triggers a refersh of the inlay hints. - You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but - not that this may cause higher CPU usage. - This option is only respected when `onlyCurrentLine` is true. - ''; + parameter_hints_prefix = defaultNullOpts.mkStr "<- " "Prefix for parameter hints."; - showParameterHints = helpers.defaultNullOpts.mkBool true '' - Whether to show parameter hints with the inlay hints or not. - ''; + other_hints_prefix = defaultNullOpts.mkStr "=> " '' + Prefix for all the other hints (type, chaining). + ''; - parameterHintsPrefix = helpers.defaultNullOpts.mkStr "<- " "Prefix for parameter hints."; + max_len_align = defaultNullOpts.mkBool false '' + Whether to align to the length of the longest line in the file. + ''; - otherHintsPrefix = helpers.defaultNullOpts.mkStr "=> " "Prefix for all the other hints (type, chaining)."; + max_len_align_padding = defaultNullOpts.mkPositiveInt 1 '' + Padding from the left if max_len_align is true. + ''; - maxLenAlign = helpers.defaultNullOpts.mkBool false '' - Whether to align to the length of the longest line in the file. - ''; + right_align = defaultNullOpts.mkBool false '' + Whether to align to the extreme right or not. + ''; - maxLenAlignPadding = helpers.defaultNullOpts.mkInt 1 '' - Padding from the left if max_len_align is true. - ''; + right_align_padding = defaultNullOpts.mkPositiveInt 7 '' + Padding from the right if `right_align` is true. + ''; - rightAlign = helpers.defaultNullOpts.mkBool false '' - Whether to align to the extreme right or not. - ''; + highlight = defaultNullOpts.mkStr "Comment" "The color of the hints."; - rightAlignPadding = helpers.defaultNullOpts.mkInt 7 '' - Padding from the right if right_align is true. - ''; + priority = defaultNullOpts.mkUnsignedInt 100 "The highlight group priority for extmark."; + }; - highlight = helpers.defaultNullOpts.mkStr "Comment" "The color of the hints."; + ast = { + role_icons = + mapAttrs (name: default: defaultNullOpts.mkStr default "Icon for the `${name}` role.") + { + type = "🄣"; + declaration = "🄓"; + expression = "🄔"; + statement = ";"; + specifier = "🄱"; + "template argument" = "🆃"; + }; - priority = helpers.defaultNullOpts.mkInt 100 "The highlight group priority for extmark."; - }; + kind_icons = mapAttrs (name: default: defaultNullOpts.mkStr default "`${name}` icon.") { + Compound = "đŸ„Č"; + Cecovery = "🅁"; + TranslationUnit = "🅄"; + PackExpansion = "🄿"; + TemplateTypeParm = "🅃"; + TemplateTemplateParm = "🅃"; + TemplateParamObject = "🅃"; + }; - ast = { - roleIcons = mapAttrs (name: default: helpers.defaultNullOpts.mkStr default "") { - type = "🄣"; - declaration = "🄓"; - expression = "🄔"; - statement = ";"; - specifier = "🄱"; - templateArgument = "🆃"; + highlights = { + detail = defaultNullOpts.mkStr "Comment" "The color of the hints."; + }; }; - kindIcons = mapAttrs (name: default: helpers.defaultNullOpts.mkStr default "") { - compound = "đŸ„Č"; - recovery = "🅁"; - translationUnit = "🅄"; - packExpansion = "🄿"; - templateTypeParm = "🅃"; - templateTemplateParm = "🅃"; - templateParamObject = "🅃"; + memory_usage = { + border = mkBorderOpt '' + Border character for memory usage window. + ''; }; - highlights = { - detail = helpers.defaultNullOpts.mkStr "Comment" ""; + symbol_info = { + border = mkBorderOpt '' + Border character for symbol info window. + ''; }; }; - memoryUsage = { - border = borderOpt; - }; - - symbolInfo = { - border = borderOpt; - }; + extraOptions = { + enableOffsetEncodingWorkaround = lib.mkEnableOption '' + UTF-16 offset encoding. This is used to work around the warning: + "multiple different client offset_encodings detected for buffer, this is + not supported yet". + ''; }; - config = - let - setupOptions = - with cfg; - { - inlay_hints = with inlayHints; { - inherit inline; - only_current_line = onlyCurrentLine; - only_current_line_autocmd = onlyCurrentLineAutocmd; - show_parameter_hints = showParameterHints; - parameter_hints_prefix = parameterHintsPrefix; - other_hints_prefix = otherHintsPrefix; - max_len_align = maxLenAlign; - max_len_align_padding = maxLenAlignPadding; - right_align = rightAlign; - right_align_padding = rightAlignPadding; - inherit highlight priority; - }; - ast = with ast; { - role_icons = with roleIcons; { - inherit - type - declaration - expression - statement - specifier - ; - "template argument" = templateArgument; - }; - kind_icons = with kindIcons; { - Compound = compound; - Recovery = recovery; - TranslationUnit = translationUnit; - PackExpansion = packExpansion; - TemplateTypeParm = templateTypeParm; - TemplateTemplateParm = templateTemplateParm; - TemplateParamObject = templateParamObject; - }; - highlights = with highlights; { - inherit detail; - }; - }; - memory_usage = with memoryUsage; { - inherit border; - }; - symbol_info = with symbolInfo; { - inherit border; - }; - } - // cfg.extraOptions; - in - mkIf cfg.enable { - warnings = optional (!config.plugins.lsp.enable) '' - You have enabled `clangd-extensions` but not the lsp (`plugins.lsp`). - You should set `plugins.lsp.enable = true` to make use of the clangd-extensions' features. - ''; - - plugins.lsp = { - servers.clangd = { - # Enable the clangd language server - enable = true; + extraConfig = cfg: { + warnings = lib.optionals (!config.plugins.lsp.enable) '' + Nixvim (plugins.clangd-extensions): You have enabled `clangd-extensions` but not the lsp (`plugins.lsp`). + You should set `plugins.lsp.enable = true` to make use of the clangd-extensions' features. + ''; - extraOptions = mkIf cfg.enableOffsetEncodingWorkaround { - capabilities = { - __raw = "__clangdCaps"; - }; - }; + plugins.lsp = { + servers.clangd = { + enable = lib.mkDefault true; + + extraOptions = lib.mkIf cfg.enableOffsetEncodingWorkaround { + capabilities.__raw = '' + vim.tbl_deep_extend( + "force", + vim.lsp.protocol.make_client_capabilities(), + { + offsetEncoding = { "utf-16" } + } + ) + ''; }; - - preConfig = optionalString cfg.enableOffsetEncodingWorkaround '' - local __clangdCaps = vim.lsp.protocol.make_client_capabilities() - __clangdCaps.offsetEncoding = { "utf-16" } - ''; }; + }; + }; - extraPlugins = [ cfg.package ]; - - plugins.lsp.postConfig = '' - require("clangd_extensions").setup(${lib.nixvim.toLuaObject setupOptions}) - ''; + settingsExample = { + inlay_hints = { + inline = true; }; + ast = { + role_icons = { + type = "î­Ł"; + declaration = "îȘŒ"; + expression = ""; + specifier = ""; + statement = "îȘ†"; + "template argument" = "îȘ’"; + }; + }; + }; } diff --git a/plugins/by-name/clangd-extensions/deprecations.nix b/plugins/by-name/clangd-extensions/deprecations.nix new file mode 100644 index 0000000000..1bf5e8699c --- /dev/null +++ b/plugins/by-name/clangd-extensions/deprecations.nix @@ -0,0 +1,85 @@ +{ lib, ... }: +let + inherit (lib) mkRemovedOptionModule mkRenamedOptionModule; + basePluginPath = [ + "plugins" + "clangd-extensions" + ]; +in +{ + imports = + [ + (mkRemovedOptionModule (basePluginPath ++ [ "server" ]) '' + To configure the `clangd` language server options, please use + `plugins.lsp.servers.clangd.extraSettings`. + '') + (mkRemovedOptionModule ( + basePluginPath + ++ [ + "extensions" + "autoSetHints" + ] + ) "") + ] + ++ (map + ( + optionPath: + mkRenamedOptionModule (basePluginPath ++ [ "extensions" ] ++ optionPath) ( + basePluginPath ++ optionPath + ) + ) + [ + [ + "inlayHints" + "inline" + ] + [ + "inlayHints" + "onlyCurrentLine" + ] + [ + "inlayHints" + "onlyCurrentLineAutocmd" + ] + [ + "inlayHints" + "showParameterHints" + ] + [ + "inlayHints" + "parameterHintsPrefix" + ] + [ + "inlayHints" + "otherHintsPrefix" + ] + [ + "inlayHints" + "maxLenAlign" + ] + [ + "inlayHints" + "maxLenAlignPadding" + ] + [ + "inlayHints" + "rightAlign" + ] + [ + "inlayHints" + "rightAlignPadding" + ] + [ + "inlayHints" + "highlight" + ] + [ + "inlayHints" + "priority" + ] + [ "ast" ] + [ "memoryUsage" ] + [ "symbolInfo" ] + ] + ); +} diff --git a/plugins/by-name/clangd-extensions/renamed-options.nix b/plugins/by-name/clangd-extensions/renamed-options.nix new file mode 100644 index 0000000000..856bbc7e70 --- /dev/null +++ b/plugins/by-name/clangd-extensions/renamed-options.nix @@ -0,0 +1,33 @@ +let + inlayHintsOptions = [ + "inline" + "onlyCurrentLine" + "onlyCurrentLineAutocmd" + "showParameterHints" + "parameterHintsPrefix" + "otherHintsPrefix" + "maxLenAlign" + "maxLenAlignPadding" + "rightAlign" + "rightAlignPadding" + "highlight" + "priority" + ]; + astOptions = [ + "roleIcons" + "kindIcons" + "highlights" + ]; +in +[ + "memoryUsage" + "symbolInfo" +] +++ map (oldOption: [ + "inlayHints" + oldOption +]) inlayHintsOptions +++ map (oldOption: [ + "ast" + oldOption +]) astOptions diff --git a/tests/test-sources/plugins/by-name/clangd-extensions/default.nix b/tests/test-sources/plugins/by-name/clangd-extensions/default.nix index fac34ef3d0..b5ac89945e 100644 --- a/tests/test-sources/plugins/by-name/clangd-extensions/default.nix +++ b/tests/test-sources/plugins/by-name/clangd-extensions/default.nix @@ -14,47 +14,79 @@ enable = true; enableOffsetEncodingWorkaround = true; - inlayHints = { - inline = ''vim.fn.has("nvim-0.10") == 1''; - onlyCurrentLine = false; - onlyCurrentLineAutocmd = "CursorHold"; - showParameterHints = true; - parameterHintsPrefix = "<- "; - otherHintsPrefix = "=> "; - maxLenAlign = false; - maxLenAlignPadding = 1; - rightAlign = false; - rightAlignPadding = 7; - highlight = "Comment"; - priority = 100; - }; - ast = { - roleIcons = { - type = "🄣"; - declaration = "🄓"; - expression = "🄔"; - statement = ";"; - specifier = "🄱"; - templateArgument = "🆃"; + + settings = { + inlay_hints = { + inline = true; + only_current_line = false; + only_current_line_autocmd = [ "CursorHold" ]; + show_parameter_hints = true; + parameter_hints_prefix = "<- "; + other_hints_prefix = "=> "; + max_len_align = false; + max_len_align_padding = 1; + right_align = false; + right_align_padding = 7; + highlight = "Comment"; + priority = 100; }; - kindIcons = { - compound = "đŸ„Č"; - recovery = "🅁"; - translationUnit = "🅄"; - packExpansion = "🄿"; - templateTypeParm = "🅃"; - templateTemplateParm = "🅃"; - templateParamObject = "🅃"; + ast = { + role_icons = { + type = "🄣"; + declaration = "🄓"; + expression = "🄔"; + statement = ";"; + specifier = "🄱"; + "template argument" = "🆃"; + }; + kind_icons = { + Compound = "đŸ„Č"; + Recovery = "🅁"; + TranslationUnit = "🅄"; + PackExpansion = "🄿"; + TemplateTypeParm = "🅃"; + TemplateTemplateParm = "🅃"; + TemplateParamObject = "🅃"; + }; + highlights = { + detail = "Comment"; + }; }; - highlights = { - detail = "Comment"; + memory_usage = { + border = "none"; + }; + symbol_info = { + border = "none"; }; }; - memoryUsage = { - border = "none"; - }; - symbolInfo = { - border = "none"; + }; + }; + }; + + example = { + plugins = { + lsp.enable = true; + clangd-extensions = { + enable = true; + + settings = { + inlay_hints = { + inline = false; + only_current_line_autocmd = [ + "CursorMoved" + "CursorMovedI" + ]; + }; + ast = { + role_icons = { + type = "î­Ł"; + declaration = "îȘŒ"; + expression = ""; + specifier = ""; + statement = "îȘ†"; + "template argument" = "îȘ’"; + }; + }; }; }; };