mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-03 13:54:29 +02:00
plugins/clangd-extensions: fix options following upstream changes + test
This commit is contained in:
parent
ebb8e479d2
commit
00016841c9
2 changed files with 267 additions and 144 deletions
|
@ -3,13 +3,61 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}: let
|
}:
|
||||||
|
with lib; let
|
||||||
|
cfg = config.plugins.clangd-extensions;
|
||||||
helpers = import ../helpers.nix {inherit lib;};
|
helpers = import ../helpers.nix {inherit lib;};
|
||||||
in
|
|
||||||
with lib; let
|
basePluginPath = ["plugins" "clangd-extensions"];
|
||||||
borderOpt = helpers.defaultNullOpts.mkBorder "none" "clangd-extensions" "";
|
|
||||||
in {
|
borderOpt = helpers.defaultNullOpts.mkBorder "none" "clangd-extensions" "";
|
||||||
options.plugins.clangd-extensions = {
|
in {
|
||||||
|
# All of those warnings were introduced on 08/22/2023.
|
||||||
|
# TODO: Remove them in ~2 monts (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"]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
options.plugins.clangd-extensions =
|
||||||
|
helpers.extraOptionsOptions
|
||||||
|
// {
|
||||||
enable = mkEnableOption "clangd_extensions, plugin implementing clangd LSP extensions";
|
enable = mkEnableOption "clangd_extensions, plugin implementing clangd LSP extensions";
|
||||||
|
|
||||||
package =
|
package =
|
||||||
|
@ -20,157 +68,170 @@ in
|
||||||
"multiple different client offset_encodings detected for buffer, this is not supported yet"
|
"multiple different client offset_encodings detected for buffer, this is not supported yet"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
server = {
|
inlayHints = {
|
||||||
package = mkOption {
|
inline = helpers.defaultNullOpts.mkStr ''vim.fn.has("nvim-0.10") == 1'' ''
|
||||||
type = types.package;
|
Show hints inline.
|
||||||
default = pkgs.clang-tools;
|
'';
|
||||||
description = "Package to use for clangd";
|
|
||||||
};
|
|
||||||
|
|
||||||
extraOptions = mkOption {
|
onlyCurrentLine =
|
||||||
type = types.attrsOf types.anything;
|
helpers.defaultNullOpts.mkBool false
|
||||||
default = {};
|
"Only show inlay hints for the current line";
|
||||||
description = "Extra options to pass to nvim-lspconfig. You should not need to use this directly";
|
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
|
||||||
|
showParameterHints = helpers.defaultNullOpts.mkBool true ''
|
||||||
|
Whether to show parameter hints with the inlay hints or not.
|
||||||
|
'';
|
||||||
|
|
||||||
|
parameterHintsPrefix = helpers.defaultNullOpts.mkStr "<- " "Prefix for parameter hints.";
|
||||||
|
|
||||||
|
otherHintsPrefix =
|
||||||
|
helpers.defaultNullOpts.mkStr "=> "
|
||||||
|
"Prefix for all the other hints (type, chaining).";
|
||||||
|
|
||||||
|
maxLenAlign = helpers.defaultNullOpts.mkBool false ''
|
||||||
|
Whether to align to the length of the longest line in the file.
|
||||||
|
'';
|
||||||
|
|
||||||
|
maxLenAlignPadding = helpers.defaultNullOpts.mkInt 1 ''
|
||||||
|
Padding from the left if max_len_align is true.
|
||||||
|
'';
|
||||||
|
|
||||||
|
rightAlign = helpers.defaultNullOpts.mkBool false ''
|
||||||
|
Whether to align to the extreme right or not.
|
||||||
|
'';
|
||||||
|
|
||||||
|
rightAlignPadding = helpers.defaultNullOpts.mkInt 7 ''
|
||||||
|
Padding from the right if right_align is true.
|
||||||
|
'';
|
||||||
|
|
||||||
|
highlight = helpers.defaultNullOpts.mkStr "Comment" "The color of the hints.";
|
||||||
|
|
||||||
|
priority = helpers.defaultNullOpts.mkInt 100 "The highlight group priority for extmark.";
|
||||||
|
};
|
||||||
|
|
||||||
|
ast = {
|
||||||
|
roleIcons =
|
||||||
|
mapAttrs
|
||||||
|
(name: default: helpers.defaultNullOpts.mkStr default "")
|
||||||
|
{
|
||||||
|
type = "🄣";
|
||||||
|
declaration = "🄓";
|
||||||
|
expression = "🄔";
|
||||||
|
statement = ";";
|
||||||
|
specifier = "🄢";
|
||||||
|
templateArgument = "🆃";
|
||||||
|
};
|
||||||
|
|
||||||
|
kindIcons =
|
||||||
|
mapAttrs
|
||||||
|
(name: default: helpers.defaultNullOpts.mkStr default "")
|
||||||
|
{
|
||||||
|
compound = "🄲";
|
||||||
|
recovery = "🅁";
|
||||||
|
translationUnit = "🅄";
|
||||||
|
packExpansion = "🄿";
|
||||||
|
templateTypeParm = "🅃";
|
||||||
|
templateTemplateParm = "🅃";
|
||||||
|
templateParamObject = "🅃";
|
||||||
|
};
|
||||||
|
|
||||||
|
highlights = {
|
||||||
|
detail = helpers.defaultNullOpts.mkStr "Comment" "";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
extensions = {
|
memoryUsage = {
|
||||||
autoSetHints = helpers.defaultNullOpts.mkBool true "Automatically set inlay hints (type hints)";
|
border = borderOpt;
|
||||||
inlayHints = {
|
};
|
||||||
onlyCurrentLine =
|
|
||||||
helpers.defaultNullOpts.mkBool false
|
|
||||||
"Only show inlay hints for the current line";
|
|
||||||
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 only_current_line and
|
|
||||||
autoSetHints both are true.
|
|
||||||
'';
|
|
||||||
showParameterHints =
|
|
||||||
helpers.defaultNullOpts.mkBool true
|
|
||||||
"whether to show parameter hints with the inlay hints or not";
|
|
||||||
parameterHintsPrefix = helpers.defaultNullOpts.mkStr "<- " "prefix for parameter hints";
|
|
||||||
otherHintsPrefix =
|
|
||||||
helpers.defaultNullOpts.mkStr "=> "
|
|
||||||
"prefix for all the other hints (type, chaining)";
|
|
||||||
maxLenAlign =
|
|
||||||
helpers.defaultNullOpts.mkBool false
|
|
||||||
"whether to align to the length of the longest line in the file";
|
|
||||||
maxLenAlignPadding =
|
|
||||||
helpers.defaultNullOpts.mkInt 1
|
|
||||||
"padding from the left if max_len_align is true";
|
|
||||||
rightAlign =
|
|
||||||
helpers.defaultNullOpts.mkBool false
|
|
||||||
"whether to align to the extreme right or not";
|
|
||||||
rightAlignPadding =
|
|
||||||
helpers.defaultNullOpts.mkInt 7
|
|
||||||
"padding from the right if right_align is true";
|
|
||||||
highlight =
|
|
||||||
helpers.defaultNullOpts.mkStr "Comment"
|
|
||||||
"The color of the hints";
|
|
||||||
priority = helpers.defaultNullOpts.mkInt 100 "The highlight group priority for extmark";
|
|
||||||
};
|
|
||||||
|
|
||||||
ast = {
|
symbolInfo = {
|
||||||
roleIcons = {
|
border = borderOpt;
|
||||||
type = helpers.defaultNullOpts.mkStr "🄣" "";
|
|
||||||
declaration = helpers.defaultNullOpts.mkStr "🄓" "";
|
|
||||||
expression = helpers.defaultNullOpts.mkStr "🄔" "";
|
|
||||||
statement = helpers.defaultNullOpts.mkStr ";" "";
|
|
||||||
specifier = helpers.defaultNullOpts.mkStr "🄢" "";
|
|
||||||
templateArgument = helpers.defaultNullOpts.mkStr "🆃" "";
|
|
||||||
};
|
|
||||||
|
|
||||||
kindIcons = {
|
|
||||||
compound = helpers.defaultNullOpts.mkStr "🄲" "";
|
|
||||||
recovery = helpers.defaultNullOpts.mkStr "🅁" "";
|
|
||||||
translationUnit = helpers.defaultNullOpts.mkStr "🅄" "";
|
|
||||||
packExpansion = helpers.defaultNullOpts.mkStr "🄿" "";
|
|
||||||
templateTypeParm = helpers.defaultNullOpts.mkStr "🅃" "";
|
|
||||||
templateTemplateParm = helpers.defaultNullOpts.mkStr "🅃" "";
|
|
||||||
templateParamObject = helpers.defaultNullOpts.mkStr "🅃" "";
|
|
||||||
};
|
|
||||||
|
|
||||||
highlights = {
|
|
||||||
detail = helpers.defaultNullOpts.mkStr "Comment" "";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
memoryUsage = {
|
|
||||||
border = borderOpt;
|
|
||||||
};
|
|
||||||
|
|
||||||
symbolInfo = {
|
|
||||||
border = borderOpt;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let
|
config = let
|
||||||
cfg = config.plugins.clangd-extensions;
|
setupOptions = with cfg;
|
||||||
setupOptions = {
|
{
|
||||||
server = cfg.server.extraOptions;
|
inlay_hints = with inlayHints; {
|
||||||
extensions = {
|
inline = helpers.ifNonNull' inline (helpers.mkRaw inline);
|
||||||
inherit (cfg.extensions) autoSetHints;
|
only_current_line = onlyCurrentLine;
|
||||||
inlay_hints = {
|
only_current_line_autocmd = onlyCurrentLineAutocmd;
|
||||||
only_current_line = cfg.extensions.inlayHints.onlyCurrentLine;
|
show_parameter_hints = showParameterHints;
|
||||||
only_current_line_autocmd = cfg.extensions.inlayHints.onlyCurrentLineAutocmd;
|
parameter_hints_prefix = parameterHintsPrefix;
|
||||||
show_parameter_hints = cfg.extensions.inlayHints.showParameterHints;
|
other_hints_prefix = otherHintsPrefix;
|
||||||
parameter_hints_prefix = cfg.extensions.inlayHints.parameterHintsPrefix;
|
max_len_align = maxLenAlign;
|
||||||
other_hints_prefix = cfg.extensions.inlayHints.otherHintsPrefix;
|
max_len_align_padding = maxLenAlignPadding;
|
||||||
max_len_align = cfg.extensions.inlayHints.maxLenAlign;
|
right_align = rightAlign;
|
||||||
max_len_align_padding = cfg.extensions.inlayHints.maxLenAlignPadding;
|
right_align_padding = rightAlignPadding;
|
||||||
right_align = cfg.extensions.inlayHints.rightAlign;
|
inherit
|
||||||
right_align_padding = cfg.extensions.inlayHints.rightAlignPadding;
|
highlight
|
||||||
inherit (cfg.extensions.inlayHints) highlight priority;
|
priority
|
||||||
|
;
|
||||||
|
};
|
||||||
|
ast = with ast; {
|
||||||
|
role_icons = with roleIcons; {
|
||||||
|
inherit
|
||||||
|
type
|
||||||
|
declaration
|
||||||
|
expression
|
||||||
|
statement
|
||||||
|
specifier
|
||||||
|
;
|
||||||
|
"template argument" = templateArgument;
|
||||||
};
|
};
|
||||||
ast = {
|
kind_icons = with kindIcons; {
|
||||||
role_icons = {
|
Compound = compound;
|
||||||
inherit (cfg.extensions.ast.roleIcons) type declaration expression statement specifier;
|
Recovery = recovery;
|
||||||
"template argument" = cfg.extensions.ast.roleIcons.templateArgument;
|
TranslationUnit = translationUnit;
|
||||||
};
|
PackExpansion = packExpansion;
|
||||||
kind_icons = {
|
TemplateTypeParm = templateTypeParm;
|
||||||
Compound = cfg.extensions.ast.kindIcons.compound;
|
TemplateTemplateParm = templateTemplateParm;
|
||||||
Recovery = cfg.extensions.ast.kindIcons.recovery;
|
TemplateParamObject = templateParamObject;
|
||||||
TranslationUnit = cfg.extensions.ast.kindIcons.translationUnit;
|
|
||||||
PackExpansion = cfg.extensions.ast.kindIcons.packExpansion;
|
|
||||||
TemplateTypeParm = cfg.extensions.ast.kindIcons.templateTypeParm;
|
|
||||||
TemplateTemplateParm = cfg.extensions.ast.kindIcons.templateTemplateParm;
|
|
||||||
TemplateParamObject = cfg.extensions.ast.kindIcons.templateParamObject;
|
|
||||||
};
|
|
||||||
highlights = {
|
|
||||||
inherit (cfg.extensions.ast.highlights) detail;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
memory_usage = {
|
highlights = with highlights; {
|
||||||
inherit (cfg.extensions.memoryUsage) border;
|
inherit detail;
|
||||||
};
|
|
||||||
symbol_info = {
|
|
||||||
inherit (cfg.extensions.symbolInfo) border;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
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.extraOptions = mkIf cfg.enableOffsetEncodingWorkaround {
|
||||||
|
capabilities = {__raw = "__clangdCaps";};
|
||||||
};
|
};
|
||||||
in
|
|
||||||
mkIf cfg.enable {
|
|
||||||
extraPackages = [cfg.server.package];
|
|
||||||
extraPlugins = [cfg.package];
|
|
||||||
|
|
||||||
plugins.clangd-extensions.server.extraOptions = mkIf cfg.enableOffsetEncodingWorkaround {
|
extraPlugins = [cfg.package];
|
||||||
capabilities = {__raw = "__clangdCaps";};
|
|
||||||
};
|
|
||||||
|
|
||||||
plugins.lsp.postConfig = let
|
# Enable the clangd language server
|
||||||
extraCaps =
|
plugins.lsp.servers.clangd.enable = true;
|
||||||
if cfg.enableOffsetEncodingWorkaround
|
|
||||||
then ''
|
plugins.lsp.preConfig =
|
||||||
local __clangdCaps = vim.lsp.protocol.make_client_capabilities()
|
optionalString
|
||||||
__clangdCaps.offsetEncoding = { "utf-16" }
|
cfg.enableOffsetEncodingWorkaround
|
||||||
''
|
''
|
||||||
else "";
|
local __clangdCaps = vim.lsp.protocol.make_client_capabilities()
|
||||||
in ''
|
__clangdCaps.offsetEncoding = { "utf-16" }
|
||||||
${extraCaps}
|
|
||||||
require("clangd_extensions").setup(${helpers.toLuaObject setupOptions})
|
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
}
|
plugins.lsp.postConfig = ''
|
||||||
|
require("clangd_extensions").setup(${helpers.toLuaObject setupOptions})
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
62
tests/test-sources/plugins/languages/clangd-extensions.nix
Normal file
62
tests/test-sources/plugins/languages/clangd-extensions.nix
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
{
|
||||||
|
empty = {
|
||||||
|
plugins = {
|
||||||
|
lsp.enable = true;
|
||||||
|
clangd-extensions.enable = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
default = {
|
||||||
|
plugins = {
|
||||||
|
lsp.enable = true;
|
||||||
|
|
||||||
|
clangd-extensions = {
|
||||||
|
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 = "🆃";
|
||||||
|
};
|
||||||
|
kindIcons = {
|
||||||
|
compound = "🄲";
|
||||||
|
recovery = "🅁";
|
||||||
|
translationUnit = "🅄";
|
||||||
|
packExpansion = "🄿";
|
||||||
|
templateTypeParm = "🅃";
|
||||||
|
templateTemplateParm = "🅃";
|
||||||
|
templateParamObject = "🅃";
|
||||||
|
};
|
||||||
|
highlights = {
|
||||||
|
detail = "Comment";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
memoryUsage = {
|
||||||
|
border = "none";
|
||||||
|
};
|
||||||
|
symbolInfo = {
|
||||||
|
border = "none";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue