feat(breadcrumbs): custom setup opts

This commit is contained in:
Ching Pei Yang 2024-03-10 18:37:49 +00:00
parent daa10b508b
commit 4b79c50201
2 changed files with 342 additions and 392 deletions

View file

@ -5,7 +5,28 @@
}: let }: let
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) nullOr listOf enum bool str int; inherit (lib.types) nullOr listOf enum bool str int;
inherit (lib.modules) mkRenamedOptionModule;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
imports = let
renameSetupOpt = oldPath: newPath:
mkRenamedOptionModule
(["vim" "ui" "breadcrumbs" "navbuddy"] ++ oldPath)
(["vim" "ui" "breadcrumbs" "navbuddy" "setupOpts"] ++ newPath);
in [
(renameSetupOpt ["useDefaultMappings"] ["use_default_mappings"])
(renameSetupOpt ["window"] ["window"])
(renameSetupOpt ["nodeMarkers"] ["node_markers"])
(renameSetupOpt ["lsp" "autoAttach"] ["lsp" "auto_attach"])
(renameSetupOpt ["lsp" "preference"] ["lsp" "preference"])
(renameSetupOpt ["sourceBuffer" "followNode"] ["source_buffer" "follow_node"])
(renameSetupOpt ["sourceBuffer" "highlight"] ["source_buffer" "highlight"])
(renameSetupOpt ["sourceBuffer" "reorient"] ["source_buffer" "reorient"])
(renameSetupOpt ["sourceBuffer" "scrolloff"] ["source_buffer" "scrolloff"])
# TODO: every option under icon is renamed to first letter capitalized
(renameSetupOpt ["icon"] ["icon"])
];
options.vim.ui.breadcrumbs = { options.vim.ui.breadcrumbs = {
enable = mkEnableOption "breadcrumbs"; enable = mkEnableOption "breadcrumbs";
source = mkOption { source = mkOption {
@ -27,13 +48,6 @@ in {
navbuddy = { navbuddy = {
enable = mkEnableOption "navbuddy LSP helper UI. Enabling this option automatically loads and enables nvim-navic"; enable = mkEnableOption "navbuddy LSP helper UI. Enabling this option automatically loads and enables nvim-navic";
# this option is interpreted as null if mkEnableOption is used, and therefore cannot be converted to a string in config.nix
useDefaultMappings = mkOption {
type = bool;
default = true;
description = "use default Navbuddy keybindings (disables user-specified keybinds)";
};
mappings = { mappings = {
close = mkOption { close = mkOption {
type = str; type = str;
@ -61,7 +75,7 @@ in {
children = mkOption { children = mkOption {
type = str; type = str;
default = "h"; default = "l";
description = "keybinding to navigate to the child node"; description = "keybinding to navigate to the child node";
}; };
@ -180,6 +194,13 @@ in {
}; };
}; };
setupOpts = mkPluginSetupOption "navbuddy" {
useDefaultMappings = mkOption {
type = bool;
default = true;
description = "use default Navbuddy keybindings (disables user-specified keybinds)";
};
window = { window = {
# size = {} # size = {}
# position = {} # position = {}
@ -201,8 +222,8 @@ in {
# left section # left section
left = { left = {
/* /*
size = { size = mkOption {
type = with types; nullOr (intBetween 0 100); type = nullOr (intBetween 0 100);
default = null; default = null;
description = "size of the left section of Navbuddy UI in percentage (0-100)"; description = "size of the left section of Navbuddy UI in percentage (0-100)";
}; };
@ -220,7 +241,7 @@ in {
mid = { mid = {
/* /*
size = { size = {
type = with types; nullOr (intBetween 0 100); type = nullOr (intBetween 0 100);
default = null; default = null;
description = "size of the left section of Navbuddy UI in percentage (0-100)"; description = "size of the left section of Navbuddy UI in percentage (0-100)";
}; };
@ -253,7 +274,7 @@ in {
}; };
}; };
nodeMarkers = { node_markers = {
enable = mkEnableOption "node markers"; enable = mkEnableOption "node markers";
icons = { icons = {
leaf = mkOption { leaf = mkOption {
@ -262,7 +283,7 @@ in {
description = ""; description = "";
}; };
leafSelected = mkOption { leaf_selected = mkOption {
type = str; type = str;
default = " "; default = " ";
description = ""; description = "";
@ -277,7 +298,7 @@ in {
}; };
lsp = { lsp = {
autoAttach = mkOption { auto_attach = mkOption {
type = bool; type = bool;
default = true; default = true;
description = "Whether to attach to LSP server manually"; description = "Whether to attach to LSP server manually";
@ -290,7 +311,7 @@ in {
}; };
}; };
sourceBuffer = { source_buffer = {
followNode = mkOption { followNode = mkOption {
type = bool; type = bool;
default = true; default = true;
@ -316,165 +337,167 @@ in {
}; };
}; };
# there probably is a better way to do this
# alas, I am not a nix wizard
icons = { icons = {
file = mkOption { File = mkOption {
type = str; type = str;
default = "󰈙 "; default = "󰈙 ";
description = "File icon"; description = "";
}; };
module = mkOption { Module = mkOption {
type = str;
default = " ";
description = "Module icon";
};
namespace = mkOption {
type = str;
default = "󰌗 ";
description = "Namespace icon";
};
package = mkOption {
type = str; type = str;
default = " "; default = " ";
description = ""; description = "";
}; };
class = mkOption { Namespace = mkOption {
type = str; type = str;
default = "󰌗 "; default = "󰌗 ";
description = "Class icon"; description = "";
}; };
property = mkOption { Package = mkOption {
type = str;
default = " ";
description = "";
};
Class = mkOption {
type = str;
default = "󰌗 ";
description = "";
};
Property = mkOption {
type = str; type = str;
default = " "; default = " ";
description = ""; description = "";
}; };
field = mkOption { Field = mkOption {
type = str; type = str;
default = " "; default = " ";
description = "Field icon"; description = "";
}; };
constructor = mkOption { Constructor = mkOption {
type = str; type = str;
default = " "; default = " ";
description = "Constructor icon"; description = "";
}; };
enum = mkOption { Enum = mkOption {
type = str; type = str;
default = "󰕘"; default = "󰕘";
description = "Enum icon"; description = "";
}; };
interface = mkOption { Interface = mkOption {
type = str; type = str;
default = "󰕘"; default = "󰕘";
description = "Interface icon"; description = "";
}; };
function = mkOption { Function = mkOption {
type = str; type = str;
default = "󰊕 "; default = "󰊕 ";
description = "Function icon"; description = "";
}; };
variable = mkOption { Variable = mkOption {
type = str; type = str;
default = "󰆧 "; default = "󰆧 ";
description = ""; description = "";
}; };
constant = mkOption { Constant = mkOption {
type = str; type = str;
default = "󰏿 "; default = "󰏿 ";
description = "Constant icon"; description = "";
}; };
string = mkOption { String = mkOption {
type = str; type = str;
default = " "; default = " ";
description = ""; description = "";
}; };
number = mkOption { Number = mkOption {
type = str; type = str;
default = "󰎠 "; default = "󰎠 ";
description = "Number icon"; description = "";
}; };
boolean = mkOption { Boolean = mkOption {
type = str; type = str;
default = " "; default = " ";
description = ""; description = "";
}; };
array = mkOption { Array = mkOption {
type = str; type = str;
default = "󰅪 "; default = "󰅪 ";
description = "Array icon"; description = "";
}; };
object = mkOption { Object = mkOption {
type = str; type = str;
default = "󰅩 "; default = "󰅩 ";
description = "Object icon"; description = "";
}; };
method = mkOption { Method = mkOption {
type = str; type = str;
default = "󰆧 "; default = "󰆧 ";
description = "Method icon"; description = "";
}; };
key = mkOption { Key = mkOption {
type = str; type = str;
default = "󰌋 "; default = "󰌋 ";
description = "Key icon"; description = "";
}; };
null = mkOption { Null = mkOption {
type = str; type = str;
default = "󰟢 "; default = "󰟢 ";
description = "Null icon"; description = "";
}; };
enumMember = mkOption { EnumMember = mkOption {
type = str; type = str;
default = "󰕘 "; default = "󰕘 ";
description = "Enum member icon"; description = "";
}; };
struct = mkOption { Struct = mkOption {
type = str; type = str;
default = "󰌗 "; default = "󰌗 ";
description = "Struct icon"; description = "";
}; };
event = mkOption { Event = mkOption {
type = str; type = str;
default = " "; default = " ";
description = "Event icon"; description = "";
}; };
operator = mkOption { Operator = mkOption {
type = str; type = str;
default = "󰆕 "; default = "󰆕 ";
description = "Operator icon"; description = "";
}; };
typeParameter = mkOption { TypeParameter = mkOption {
type = str; type = str;
default = "󰊄 "; default = "󰊄 ";
description = "Type parameter icon"; description = "";
}; };
}; };
}; };
# there probably is a better way to do this
# alas, I am not a nix wizard
};
}; };
} }

View file

@ -4,14 +4,13 @@
... ...
}: let }: let
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.lists) optionals; inherit (lib.lists) optionals;
inherit (lib.nvim.lua) nullString;
inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.dag) entryAfter;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.ui.breadcrumbs; cfg = config.vim.ui.breadcrumbs;
nbcfg = cfg.navbuddy; mkRawLua = code: {__raw = code;};
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = vim.startPlugins =
@ -30,6 +29,55 @@ in {
"nvim-navic" "nvim-navic"
]; ];
vim.ui.breadcrumbs.navbuddy.setupOpts = {
mappings = {
${cfg.navbuddy.mappings.close} = mkRawLua "actions.close()";
${cfg.navbuddy.mappings.nextSibling} = mkRawLua "actions.next_sibling()";
${cfg.navbuddy.mappings.previousSibling} = mkRawLua "actions.previous_sibling()";
${cfg.navbuddy.mappings.parent} = mkRawLua "actions.parent()";
${cfg.navbuddy.mappings.children} = mkRawLua "actions.children()";
${cfg.navbuddy.mappings.root} = mkRawLua "actions.root()";
${cfg.navbuddy.mappings.visualName} = mkRawLua "actions.visual_name()";
${cfg.navbuddy.mappings.visualScope} = mkRawLua "actions.visual_scope()";
${cfg.navbuddy.mappings.yankName} = mkRawLua "actions.yank_name()";
${cfg.navbuddy.mappings.yankScope} = mkRawLua "actions.yank_scope()";
${cfg.navbuddy.mappings.insertName} = mkRawLua "actions.insert_name()";
${cfg.navbuddy.mappings.insertScope} = mkRawLua "actions.insert_scope()";
${cfg.navbuddy.mappings.appendName} = mkRawLua "actions.append_name()";
${cfg.navbuddy.mappings.appendScope} = mkRawLua "actions.append_scope()";
${cfg.navbuddy.mappings.rename} = mkRawLua "actions.rename()";
${cfg.navbuddy.mappings.delete} = mkRawLua "actions.delete()";
${cfg.navbuddy.mappings.foldCreate} = mkRawLua "actions.fold_create()";
${cfg.navbuddy.mappings.foldDelete} = mkRawLua "actions.fold_delete()";
${cfg.navbuddy.mappings.comment} = mkRawLua "actions.comment()";
${cfg.navbuddy.mappings.select} = mkRawLua "actions.select()";
${cfg.navbuddy.mappings.moveDown} = mkRawLua "actions.move_down()";
${cfg.navbuddy.mappings.moveUp} = mkRawLua "actions.move_up()";
${cfg.navbuddy.mappings.telescope} = mkRawLua ''
actions.telescope({
layout_strategy = "horizontal",
layout_config = {
height = 0.60,
width = 0.75,
prompt_position = "top",
preview_width = 0.50
},
})'';
${cfg.navbuddy.mappings.help} = mkRawLua "actions.help()";
};
};
vim.luaConfigRC.breadcrumbs = entryAfter ["lspconfig"] '' vim.luaConfigRC.breadcrumbs = entryAfter ["lspconfig"] ''
${optionalString (cfg.source == "nvim-navic") '' ${optionalString (cfg.source == "nvim-navic") ''
@ -42,128 +90,7 @@ in {
${optionalString cfg.navbuddy.enable '' ${optionalString cfg.navbuddy.enable ''
local navbuddy = require("nvim-navbuddy") local navbuddy = require("nvim-navbuddy")
local actions = require("nvim-navbuddy.actions") local actions = require("nvim-navbuddy.actions")
navbuddy.setup { navbuddy.setup ${toLuaObject cfg.navbuddy.setupOpts}
window = {
border = "${nbcfg.window.border}", -- "rounded", "double", "solid", "none"
size = "60%",
position = "50%",
scrolloff = ${(nullString nbcfg.window.scrolloff)},
sections = {
left = {
size = "20%",
border = ${(nullString nbcfg.window.sections.left.border)},
},
mid = {
size = "40%",
border = ${(nullString nbcfg.window.sections.mid.border)},
},
right = {
border = ${(nullString nbcfg.window.sections.right.border)},
preview = "leaf",
}
},
},
node_markers = {
enabled = ${boolToString nbcfg.nodeMarkers.enable},
icons = {
leaf = "${nbcfg.nodeMarkers.icons.leaf}",
leaf_selected = "${nbcfg.nodeMarkers.icons.leafSelected}",
branch = "${nbcfg.nodeMarkers.icons.branch}",
},
},
lsp = {
auto_attach = ${boolToString nbcfg.lsp.autoAttach},
-- preference = nil, -- TODO: convert list to lua table if not null
},
source_buffer = {
follow_node = ${boolToString nbcfg.sourceBuffer.followNode},
highlight = ${boolToString nbcfg.sourceBuffer.highlight},
reorient = "${nbcfg.sourceBuffer.reorient}",
scrolloff = ${nullString nbcfg.sourceBuffer.scrolloff}
},
icons = {
File = "${cfg.navbuddy.icons.file}",
Module = "${cfg.navbuddy.icons.module}",
Namespace = "${cfg.navbuddy.icons.namespace}",
Package = "${cfg.navbuddy.icons.package}",
Class = "${cfg.navbuddy.icons.class}",
Method = "${cfg.navbuddy.icons.method}",
Property = "${cfg.navbuddy.icons.property}",
Field = "${cfg.navbuddy.icons.field}",
Constructor = "${cfg.navbuddy.icons.constructor}",
Enum = "${cfg.navbuddy.icons.enum}",
Interface = "${cfg.navbuddy.icons.interface}",
Function = "${cfg.navbuddy.icons.function}",
Variable = "${cfg.navbuddy.icons.variable}",
Constant = "${cfg.navbuddy.icons.constant}",
String = "${cfg.navbuddy.icons.string}",
Number = "${cfg.navbuddy.icons.number}",
Boolean = "${cfg.navbuddy.icons.boolean}",
Array = "${cfg.navbuddy.icons.array}",
Object = "${cfg.navbuddy.icons.object}",
Key = "${cfg.navbuddy.icons.key}",
Null = "${cfg.navbuddy.icons.null}",
EnumMember = "${cfg.navbuddy.icons.enumMember}",
Struct = "${cfg.navbuddy.icons.struct}",
Event = "${cfg.navbuddy.icons.event}",
Operator = "${cfg.navbuddy.icons.operator}",
TypeParameter = "${cfg.navbuddy.icons.typeParameter}"
},
-- make those configurable
use_default_mappings = ${boolToString cfg.navbuddy.useDefaultMappings},
mappings = {
["${cfg.navbuddy.mappings.close}"] = actions.close(),
["${cfg.navbuddy.mappings.nextSibling}"] = actions.next_sibling(),
["${cfg.navbuddy.mappings.previousSibling}"] = actions.previous_sibling(),
["${cfg.navbuddy.mappings.close}"] = actions.parent(),
["${cfg.navbuddy.mappings.children}"] = actions.children(),
["${cfg.navbuddy.mappings.root}"] = actions.root(),
["${cfg.navbuddy.mappings.visualName}"] = actions.visual_name(),
["${cfg.navbuddy.mappings.visualScope}"] = actions.visual_scope(),
["${cfg.navbuddy.mappings.yankName}"] = actions.yank_name(),
["${cfg.navbuddy.mappings.yankScope}"] = actions.yank_scope(),
["${cfg.navbuddy.mappings.insertName}"] = actions.insert_name(),
["${cfg.navbuddy.mappings.insertScope}"] = actions.insert_scope(),
["${cfg.navbuddy.mappings.appendName}"] = actions.append_name(),
["${cfg.navbuddy.mappings.appendScope}"] = actions.append_scope(),
["${cfg.navbuddy.mappings.rename}"] = actions.rename(),
["${cfg.navbuddy.mappings.delete}"] = actions.delete(),
["${cfg.navbuddy.mappings.foldCreate}"] = actions.fold_create(),
["${cfg.navbuddy.mappings.foldDelete}"] = actions.fold_delete(),
["${cfg.navbuddy.mappings.comment}"] = actions.comment(),
["${cfg.navbuddy.mappings.select}"] = actions.select(),
["${cfg.navbuddy.mappings.moveDown}"] = actions.move_down(),
["${cfg.navbuddy.mappings.moveUp}"] = actions.move_up(),
["${cfg.navbuddy.mappings.telescope}"] = actions.telescope({
layout_strategy = "horizontal",
layout_config = {
height = 0.60,
width = 0.75,
prompt_position = "top",
preview_width = 0.50
},
}),
["${cfg.navbuddy.mappings.help}"] = actions.help(), -- Open mappings help window
},
}
''} ''}
''; '';
}; };