merge main

This commit is contained in:
Pedro Alves 2023-02-14 19:45:04 +00:00
parent cfc826546c
commit aa54bbcde3
12 changed files with 865 additions and 144 deletions

View file

@ -0,0 +1,186 @@
{
lib,
pkgs,
config,
...
}: let
helpers = import ../helpers.nix {inherit lib;};
in
with lib; let
borderOpt = let
bordersTy =
types.enum ["double" "rounded" "single" "shadow" "none"];
in
helpers.defaultNullOpts.mkNullable (types.either bordersTy (types.listOf bordersTy))
''"none"'' "";
in {
options.plugins.clangd-extensions = {
enable = mkEnableOption "clangd_extensions, plugin implementing clangd LSP extensions";
package =
helpers.mkPackageOption "clangd_extensions.nvim" pkgs.vimPlugins.clangd_extensions-nvim;
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"
'';
server = {
package = mkOption {
type = types.package;
default = pkgs.clang-tools;
description = "Package to use for clangd";
};
extraOptions = mkOption {
type = types.attrsOf types.anything;
default = {};
description = "Extra options to pass to nvim-lspconfig. You should not need to use this directly";
};
};
extensions = {
autoSetHints = helpers.defaultNullOpts.mkBool true "Automatically set inlay hints (type hints)";
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 = {
roleIcons = {
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
cfg = config.plugins.clangd-extensions;
setupOptions = {
server = cfg.server.extraOptions;
extensions = {
autoSetHints = cfg.extensions.autoSetHints;
inlay_hints = {
only_current_line = cfg.extensions.inlayHints.onlyCurrentLine;
only_current_line_autocmd = cfg.extensions.inlayHints.onlyCurrentLineAutocmd;
show_parameter_hints = cfg.extensions.inlayHints.showParameterHints;
parameter_hints_prefix = cfg.extensions.inlayHints.parameterHintsPrefix;
other_hints_prefix = cfg.extensions.inlayHints.otherHintsPrefix;
max_len_align = cfg.extensions.inlayHints.maxLenAlign;
max_len_align_padding = cfg.extensions.inlayHints.maxLenAlignPadding;
right_align = cfg.extensions.inlayHints.rightAlign;
right_align_padding = cfg.extensions.inlayHints.rightAlignPadding;
highlight = cfg.extensions.inlayHints.highlight;
priority = cfg.extensions.inlayHints.priority;
};
ast = {
role_icons = {
type = cfg.extensions.ast.roleIcons.type;
declaration = cfg.extensions.ast.roleIcons.declaration;
expression = cfg.extensions.ast.roleIcons.expression;
statement = cfg.extensions.ast.roleIcons.statement;
specifier = cfg.extensions.ast.roleIcons.specifier;
"template argument" = cfg.extensions.ast.roleIcons.templateArgument;
};
kind_icons = {
Compound = cfg.extensions.ast.kindIcons.compound;
Recovery = cfg.extensions.ast.kindIcons.recovery;
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 = {
detail = cfg.extensions.ast.highlights.detail;
};
};
memory_usage = {
border = cfg.extensions.memoryUsage.border;
};
symbol_info = {
border = cfg.extensions.symbolInfo.border;
};
};
};
in
mkIf cfg.enable {
extraPackages = [cfg.server.package];
extraPlugins = [cfg.package];
plugins.clangd-extensions.server.extraOptions = mkIf cfg.enableOffsetEncodingWorkaround {
capabilities = {__raw = "__clangdCaps";};
};
plugins.lsp.postConfig = let
extraCaps =
if cfg.enableOffsetEncodingWorkaround
then ''
local __clangdCaps = vim.lsp.protocol.make_client_capabilities()
__clangdCaps.offsetEncoding = { "utf-16" }
''
else "";
in ''
${extraCaps}
require("clangd_extensions").setup(${helpers.toLuaObject setupOptions})
'';
};
}

View file

@ -0,0 +1,121 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.plugins.markdown-preview;
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
plugins.markdown-preview = {
enable = mkEnableOption "markdown-preview";
package = helpers.mkPackageOption "markdown-preview" pkgs.vimPlugins.markdown-preview-nvim;
autoStart = helpers.defaultNullOpts.mkBool false ''
Open the preview window after entering the markdown buffer
'';
autoClose = helpers.defaultNullOpts.mkBool true ''
Auto close current preview window when change from markdown buffer to another buffer
'';
refreshSlow = helpers.defaultNullOpts.mkBool false ''
Refresh markdown when save the buffer or leave from insert mode, default false is auto refresh markdown as you edit or move the cursor
'';
commandForGlobal = helpers.defaultNullOpts.mkBool false ''
Enable markdown preview for all files (by default, the plugin is only enabled for markdown files)
'';
openToTheWorld = helpers.defaultNullOpts.mkBool false ''
Make the preview server available to others in your network. By default, the server listens on localhost (127.0.0.1).
'';
openIp = helpers.defaultNullOpts.mkStr "" ''
Custom IP used to open the preview page. This can be useful when you work in remote vim and preview on local browser.
For more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9.
'';
browser = helpers.defaultNullOpts.mkStr "" ''
The browser to open the preview page
'';
echoPreviewUrl = helpers.defaultNullOpts.mkBool false ''
Echo preview page url in command line when opening the preview page
'';
browserFunc = helpers.defaultNullOpts.mkStr "" ''
A custom vim function name to open preview page. This function will receive url as param.
'';
previewOptions = {
mkit = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "markdown-it options for render";
katex = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "katex options for math";
uml = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "markdown-it-plantuml options";
maid = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "mermaid options";
disable_sync_scroll = helpers.defaultNullOpts.mkBool false "Disable sync scroll";
sync_scroll_type = helpers.defaultNullOpts.mkNullable (types.enum [ "middle" "top" "relative" ]) "middle" ''
Scroll type:
- "middle": The cursor position is always shown at the middle of the preview page.
- "top": The vim top viewport is always shown at the top of the preview page.
- "relative": The cursor position is always shown at the relative positon of the preview page.
'';
hide_yaml_meta = helpers.defaultNullOpts.mkBool true "Hide yaml metadata.";
sequence_diagrams = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "js-sequence-diagrams options";
flowchart_diagrams = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "flowcharts diagrams options";
content_editable = helpers.defaultNullOpts.mkBool false "Content editable from the preview page";
disable_filename = helpers.defaultNullOpts.mkBool false "Disable filename header for the preview page";
toc = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "Toc options";
};
markdownCss = helpers.defaultNullOpts.mkStr "" ''
Custom markdown style. Must be an absolute path like '/Users/username/markdown.css' or expand('~/markdown.css').
'';
highlightCss = helpers.defaultNullOpts.mkStr "" ''
Custom highlight style. Must be an absolute path like '/Users/username/highlight.css' or expand('~/highlight.css').
'';
port = helpers.defaultNullOpts.mkStr "" "Custom port to start server or empty for random";
pageTitle = helpers.defaultNullOpts.mkStr "\${name}" ''
preview page title. $${name} will be replaced with the file name.
'';
fileTypes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "['markdown']" ''
Recognized filetypes. These filetypes will have MarkdownPreview... commands.
'';
theme = helpers.defaultNullOpts.mkNullable (types.enum [ "dark" "light" ]) "dark" ''
Default theme (dark or light). By default the theme is define according to the preferences of the system.
'';
};
};
config =
let
previewOptions = mapAttrs (name: value: cfg.previewOptions.${name}) cfg.previewOptions;
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
globals = {
mkdp_auto_start = mkIf (!isNull cfg.autoStart) cfg.autoStart;
mkdp_auto_close = mkIf (!isNull cfg.autoClose) cfg.autoClose;
mkdp_refresh_slow = mkIf (!isNull cfg.refreshSlow) cfg.refreshSlow;
mkdp_command_for_global = mkIf (!isNull cfg.commandForGlobal) cfg.commandForGlobal;
mkdp_open_to_the_world = mkIf (!isNull cfg.openToTheWorld) cfg.openToTheWorld;
mkdp_open_ip = mkIf (!isNull cfg.openIp) cfg.openIp;
mkdp_browser = mkIf (!isNull cfg.browser) cfg.browser;
mkdp_echo_preview_url = mkIf (!isNull cfg.echoPreviewUrl) cfg.echoPreviewUrl;
mkdp_browserfunc = mkIf (!isNull cfg.browserFunc) cfg.browserFunc;
mkdp_preview_options = mkIf (cfg.previewOptions != { }) previewOptions;
mkdp_markdown_css = mkIf (!isNull cfg.markdownCss) cfg.markdownCss;
mkdp_highlight_css = mkIf (!isNull cfg.highlightCss) cfg.highlightCss;
mkdp_port = mkIf (!isNull cfg.port) cfg.port;
mkdp_page_title = mkIf (!isNull cfg.pageTitle) cfg.pageTitle;
mkdp_filetypes = mkIf (!isNull cfg.fileTypes) cfg.fileTypes;
mkdp_theme = mkIf (!isNull cfg.theme) cfg.theme;
};
};
}