Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins/navbuddy: init + tests #600

Merged
merged 41 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d5fa0ed
adding navbuddy in progress
Sep 21, 2023
dcabed5
Update
hmajid2301 Sep 21, 2023
7a55a7f
update for review
Sep 22, 2023
d5000c4
update mappings
hmajid2301 Sep 22, 2023
798d13b
update mappings
hmajid2301 Sep 22, 2023
518b641
update mappings
hmajid2301 Sep 23, 2023
ae00c3e
update mappings
hmajid2301 Sep 23, 2023
9b1d897
Update plugins/utils/navbuddy.nix
hmajid2301 Sep 26, 2023
89bde69
Update plugins/utils/navbuddy.nix
hmajid2301 Sep 26, 2023
d392c9d
Update plugins/utils/navbuddy.nix
hmajid2301 Sep 26, 2023
1e5d651
fix formatting
hmajid2301 Sep 26, 2023
8cda704
Update plugins/utils/navbuddy.nix
hmajid2301 Sep 27, 2023
1cd4dfe
Update plugins/utils/navbuddy.nix
hmajid2301 Sep 27, 2023
3781fc2
fix formatting
hmajid2301 Sep 27, 2023
9d5ee3a
fix mapping
Sep 28, 2023
63e5d5e
Add local actions
hmajid2301 Sep 29, 2023
cb858ee
fix formatting
hmajid2301 Sep 29, 2023
1340f3d
fix formatting
hmajid2301 Sep 29, 2023
20a3325
fix formatting
hmajid2301 Sep 29, 2023
74c6c96
Merge remote-tracking branch 'origin/main' into add-nav-buddy
hmajid2301 Sep 29, 2023
7a7627f
add tests
hmajid2301 Sep 29, 2023
6d304ad
work
hmajid2301 Sep 29, 2023
4021330
add tests
hmajid2301 Sep 29, 2023
fe69a0a
Update tests/test-sources/plugins/utils/navbuddy.nix
hmajid2301 Sep 30, 2023
59bf26a
Update tests/test-sources/plugins/utils/navbuddy.nix
hmajid2301 Oct 2, 2023
e93726a
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 2, 2023
3d30fac
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 2, 2023
6032950
fix missing plugiin
hmajid2301 Oct 2, 2023
4ddb98c
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 2, 2023
b423a1b
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 3, 2023
e7f3d34
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 3, 2023
e863d5a
some fixes
Oct 3, 2023
0cefcfa
some fixes tests
Oct 3, 2023
62fb5e2
some more fixes tests
Oct 3, 2023
f92c369
fix pre-commit
Oct 3, 2023
3c35cb3
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 3, 2023
a76bdf1
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 3, 2023
f7f59db
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 3, 2023
4157f65
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 3, 2023
c052ede
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 3, 2023
f56ed08
Update plugins/utils/navbuddy.nix
hmajid2301 Oct 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
./utils/mini.nix
./utils/mkdnflow.nix
./utils/multicursors.nix
./utils/navbuddy.nix
./utils/neorg.nix
./utils/neogen.nix
./utils/notify.nix
Expand Down
285 changes: 285 additions & 0 deletions plugins/utils/navbuddy.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
{
lib,
pkgs,
config,
...
}:
with lib; let
cfg = config.plugins.navbuddy;
helpers = import ../helpers.nix {inherit lib;};

percentageType = types.ints.between 0 100;
mkPercentageOpt = default: helpers.defaultNullOpts.mkNullable percentageType (toString default);
in {
options.plugins.navbuddy =
helpers.extraOptionsOptions
// {
enable = mkEnableOption "nvim-navbuddy";

package = helpers.mkPackageOption "nvim-navbuddy" pkgs.vimPlugins.nvim-navbuddy;

window = {
border = helpers.defaultNullOpts.mkBorder "rounded" "window border" ''
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';

size =
helpers.defaultNullOpts.mkNullable
(
with types;
either
percentageType
(submodule {
options = {
height = mkPercentageOpt 40 "The height size (in %).";

width = mkPercentageOpt 100 "The width size (in %).";
};
})
)
"60"
"The size of the window.";

position =
helpers.defaultNullOpts.mkNullable
(
with types;
either
percentageType
(submodule {
options = {
height = mkPercentageOpt 40 "The height size (in %).";

width = mkPercentageOpt 100 "The width size (in %).";
};
})
)
"50"
"The position of the window.";

scrolloff = helpers.mkNullOrOption types.int ''
scrolloff value within navbuddy window
'';

sections = {
left = {
size = mkPercentageOpt 20 "The height size (in %).";

border = helpers.defaultNullOpts.mkBorder "rounded" "left section border" ''
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';
};

mid = {
size = mkPercentageOpt 40 "The height size (in %).";

border = helpers.defaultNullOpts.mkBorder "rounded" "mid section border" ''
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';
};

right = {
border = helpers.defaultNullOpts.mkBorder "rounded" "right section border" ''
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';

preview = helpers.defaultNullOpts.mkEnum ["leaf" "always" "never"] "leaf" ''
Right section can show previews too.
Options: "leaf", "always" or "never"
'';
};
};
};

nodeMarkers = {
enabled = helpers.defaultNullOpts.mkBool true "Enable node markers.";

icons = {
leaf = helpers.defaultNullOpts.mkStr " " ''
The icon to use for leaf nodes.
'';

leafSelected = helpers.defaultNullOpts.mkStr " → " ''
The icon to use for selected leaf node.
'';

branch = helpers.defaultNullOpts.mkStr "  " ''
The icon to use for branch nodes.
'';
};
};

icons =
mapAttrs
(
name: default:
helpers.defaultNullOpts.mkStr default "icon for ${name}."
)
{
File = "󰈙 ";
Module = " ";
Namespace = "󰌗 ";
Package = " ";
Class = "󰌗 ";
Method = "󰆧 ";
Property = " ";
Field = " ";
Constructor = " ";
Enum = "󰕘";
Interface = "󰕘";
Function = "󰊕 ";
Variable = "󰆧 ";
Constant = "󰏿 ";
String = "󰀬 ";
Number = "󰎠 ";
Boolean = "◩ ";
Array = "󰅪 ";
Object = "󰅩 ";
Key = "󰌋 ";
Null = "󰟢 ";
EnumMember = " ";
Struct = "󰌗 ";
Event = " ";
Operator = "󰆕 ";
TypeParameter = "󰊄 ";
};

useDefaultMapping = helpers.defaultNullOpts.mkBool true ''
If set to false, only mappings set by user are set. Else default mappings are used for keys that are not set by user
'';

keymapsSilent = mkOption {
type = types.bool;
description = "Whether navbuddy keymaps should be silent";
default = false;
};

mappings =
helpers.defaultNullOpts.mkNullable
(
with types;
attrsOf
(
either
str
helpers.rawType
)
)
''
{
"<esc>" = "close";
"q" = "close";
"j" = "next_sibling";
"k" = "previous_sibling";

"h" = "parent";
"l" = "children";
"0" = "root";

"v" = "visual_name";
"V" = "visual_scope";

"y" = "yank_name";
"Y" = "yank_scope";

"i" = "insert_name";
"I" = "insert_scope";

"a" = "append_name";
"A" = "append_scope";

"r" = "rename";

"d" = "delete";

"f" = "fold_create";
"F" = "fold_delete";

"c" = "comment";

"<enter>" = "select";
"o" = "select";
"J" = "move_down";
"K" = "move_up";

"s" = "toggle_preview";

"<C-v>" = "vsplit";
"<C-s>" = "hsplit";
}
''
''
Actions to be triggered for specified keybindings. It can take either action name i.e `toggle_preview`
Or it can a `rawType`.
'';

lsp = {
autoAttach = helpers.defaultNullOpts.mkBool false ''
If set to true, you don't need to manually use attach function
'';

preference = helpers.mkNullOrOption (with types; listOf str) ''
list of lsp server names in order of preference
'';
};

sourceBuffer = {
followNode = helpers.defaultNullOpts.mkBool true "Keep the current node in focus on the source buffer";

highlight = helpers.defaultNullOpts.mkBool true "Highlight the currently focused node";

reorient = helpers.defaultNullOpts.mkEnum ["smart" "top" "mid" "none"] "smart" ''
Right section can show previews too.
Options: "leaf", "always" or "never"
'';

scrolloff = helpers.defaultNullOpts.mkInt null ''
scrolloff value when navbuddy is open.
'';
};
};

config = let
setupOptions = with cfg;
{
inherit window;
node_markers = with nodeMarkers; {
inherit enabled;
icons = with icons; {
GaetanLepage marked this conversation as resolved.
Show resolved Hide resolved
inherit leaf branch;
leaf_selected = leafSelected;
};
};
inherit icons;
use_default_mapping = useDefaultMapping;
lsp = with lsp; {
auto_attach = autoAttach;
inherit preference;
};
source_buffer = sourceBuffer;
mappings =
helpers.ifNonNull' cfg.mappings
(mapAttrs
(
key: action:
if isString action
then helpers.mkRaw "actions.${action}()"
else action
)
mappings);
}
// cfg.extraOptions;
in
mkIf cfg.enable {
extraPlugins = [cfg.package];

extraConfigLua = ''
local actions = require("nvim-navbuddy.actions")
require('nvim-navbuddy').setup(${helpers.toLuaObject setupOptions})
'';
};
}
Loading