Skip to content

Commit

Permalink
plugins/clangd-extensions: convert to mkNeovimPlugin
Browse files Browse the repository at this point in the history
Wrap code in backticks

Co-authored-by: Gaétan Lepage <[email protected]>

Surround right_aling with backticks

Co-authored-by: Gaétan Lepage <[email protected]>

Set default of `inline` to true since we are on nvim >= 0.10

Document `highlights`

Use `mkUnsignedInt`

Co-authored-by: Gaétan Lepage <[email protected]>

Improve warning

Co-authored-by: Gaétan Lepage <[email protected]>

Readd deprecated options

Document icons

Rename removed-options.nix to deprecations.nix

Reformat raw string

Co-authored-by: Gaétan Lepage <[email protected]>

Don't specify rawLua

Co-authored-by: Gaétan Lepage <[email protected]>

Use mkDefault and make utf-16 workaround leaner

Don't wrap warning

Co-authored-by: Matt Sturgeon <[email protected]>

Change by -> after

Co-authored-by: Matt Sturgeon <[email protected]>

Document border options
  • Loading branch information
jolars authored and nix-infra-bot committed Jan 12, 2025
1 parent 56877b8 commit 35d6c12
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 272 deletions.
363 changes: 128 additions & 235 deletions plugins/by-name/clangd-extensions/default.nix
Original file line number Diff line number Diff line change
@@ -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" = "";
};
};
};
}
Loading

0 comments on commit 35d6c12

Please sign in to comment.