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

Conversation

hmajid2301
Copy link
Contributor

PR to add support for the [nvim-navbuddy](https://github.com/SmiteshP/nvim-navbuddy plugin

'';

# TODO: how to set mappings, like in nvim-cmp ?
mapping = {};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I set the typing for key maps ?
For example we have:

 mappings = {
        ["<esc>"] = actions.close(),        -- Close and cursor to original location
        ["q"] = actions.close(),

        ["j"] = actions.next_sibling(),     -- down
}

Copy link
Member

@GaetanLepage GaetanLepage Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would map the keys to some actions (i.e. strings: close; next_sibling) and then you create the mappings from that yourself.
See

mappings =
mapAttrs'
(motion: key: {
name = key;
value = {
action = "function() require('spider').motion('${motion}') end";
lua = true;
inherit (cfg.keymaps) silent;
desc = "Spider-${motion}";
};
})
cfg.keymaps.motions;
for inspiration.

@hmajid2301 hmajid2301 changed the title WIP: plugins/navic: init + tests WIP: plugins/navbuddy: init + tests Sep 22, 2023
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
hmajid2301 and others added 2 commits September 26, 2023 09:43
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
hmajid2301 and others added 2 commits September 26, 2023 11:15
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
hmajid2301 and others added 3 commits September 27, 2023 14:43
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Copy link
Member

@GaetanLepage GaetanLepage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I actually took the time to look at the plugin.
Actually, mappings is a plugin option itself.
We should not create the mappings using the nixvim maps option.
We should only provide the given mappings in the setupOptions attrs.

As for the option declaration, I would go for:

mappings =
  helpers.defaultNullOpts.mkNullable
  (with types;
    attrsOf
      (either
        str
        helpers.rawTypes
      )
    )
    ''
      {
        "<esc>" = "close";
        q = "close";
        ...
      }
    ''
    ''
      <Description>
      Mention that it can take either a `rawType` (for user liberty) or an action name.
    ''

Then, in the implementation,

setupOptions = with cfg; {
  ...
  mappings = ifNonNull' mappings
    (mapAttrs
      (key: action:
        if isString action
        then helpers.mkRaw "actions.${action}()"
        else action
    )
    mappings
  ...
} // cfg.extraOptions;

And, in extraConfigLua, add local actions = require("nvim-navbuddy.actions") before the call to setup().

Of course, you can get rid of the keymapsSilent option.

@hmajid2301
Copy link
Contributor Author

hmajid2301 commented Sep 28, 2023

Ok, I actually took the time to look at the plugin. Actually, mappings is a plugin option itself. We should not create the mappings using the nixvim maps option. We should only provide the given mappings in the setupOptions attrs.

As for the option declaration, I would go for:

mappings =
  helpers.defaultNullOpts.mkNullable
  (with types;
    attrsOf
      (either
        str
        helpers.rawTypes
      )
    )
    ''
      {
        "<esc>" = "close";
        q = "close";
        ...
      }
    ''
    ''
      <Description>
      Mention that it can take either a `rawType` (for user liberty) or an action name.
    ''

Then, in the implementation,

setupOptions = with cfg; {
  ...
  mappings = ifNonNull' mappings
    (mapAttrs
      (key: action:
        if isString action
        then helpers.mkRaw "actions.${action}()"
        else action
    )
    mappings
  ...
} // cfg.extraOptions;

And, in extraConfigLua, add local actions = require("nvim-navbuddy.actions") before the call to setup().

Of course, you can get rid of the keymapsSilent option.

Sorry for you needing to do that, im still trying to get my head around nix 😓.

@GaetanLepage
Copy link
Member

No worry !

And, in extraConfigLua, add local actions = require("nvim-navbuddy.actions") before the call to setup().

Don't forget this :)

Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Comment on lines 96 to 108
enabled = helpers.defaultNullOpts.mkBool true;
icons = {
leaf = helpers.defaultNullOpts.mkStr " " ''
The icon to use for leaf nodes.
'';

leaf_selected = helpers.defaultNullOpts.mkStr " → " ''
The icon to use for selected leaf node.
'';
branch = helpers.defaultNullOpts.mkStr "  " ''
The icon to use for branch nodes.
'';
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enabled = helpers.defaultNullOpts.mkBool true;
icons = {
leaf = helpers.defaultNullOpts.mkStr " " ''
The icon to use for leaf nodes.
'';
leaf_selected = helpers.defaultNullOpts.mkStr " → " ''
The icon to use for selected leaf node.
'';
branch = helpers.defaultNullOpts.mkStr "  " ''
The icon to use for branch nodes.
'';
};
enabled = helpers.defaultNullOpts.mkBool true "Enable node markers.";
icons = {
leaf = helpers.defaultNullOpts.mkStr " " ''
The icon to use for leaf nodes.
'';
leaf_selected = helpers.defaultNullOpts.mkStr " → " ''
The icon to use for selected leaf node.
'';
branch = helpers.defaultNullOpts.mkStr "  " ''
The icon to use for branch nodes.
'';
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, leaf_selected -> leafSelected. We use camelCase for all of our options.
Don't forget to write leaf_selected = leafSelected in the config section below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh yes ofc course will add this change then update in setup options

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And don't forget to change it in the test.

Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Comment on lines 22 to 25
border = helpers.defaultNullOpts.mkBorder "rounded" "double" "solid" "none" ''
"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: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mkBorder is wrongly called here and elsewhere as well.
It expects the default value for the option, the name of what the borders are for and an optional description for this option (you can simply provide "" if you don't want to provide it).

Function declaration:

mkBorder = default: name: desc:

Examples of how it is properly used: https://github.com/search?q=repo%3Anix-community%2Fnixvim%20mkBorder&type=code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahah yeh I just saw this error running the nix flake check locally.

Ahh I see I though it was like an enum, not sure why! Fixing now.

Comment on lines 245 to 251
node_markers = nodeMarkers;
icons = with icons; {
leaf_selected = leafSelected;
inherit leaf branch;
};

use_default_mapping = useDefaultMapping;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful, there are two icons options. The one with leafSelected is inside nodeMarkers.

@hmajid2301 hmajid2301 marked this pull request as ready for review October 3, 2023 10:07
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
@hmajid2301 hmajid2301 changed the title WIP: plugins/navbuddy: init + tests plugins/navbuddy: init + tests Oct 3, 2023
Copy link
Member

@GaetanLepage GaetanLepage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few last formatting changes.

plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
plugins/utils/navbuddy.nix Outdated Show resolved Hide resolved
hmajid2301 and others added 5 commits October 3, 2023 12:16
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
@hmajid2301
Copy link
Contributor Author

Thanks for all the help with this pR. I hope the next few I will be able to do mostly on my own!!! (ROI)

@GaetanLepage
Copy link
Member

Thanks for all the help with this pR. I hope the next few I will be able to do mostly on my own!!! (ROI)

Thank you for your contribution ! It is really welcomed.
I am sure that it will get easier and easier for you now :)

@GaetanLepage GaetanLepage merged commit 19680bb into nix-community:main Oct 3, 2023
1 check passed
@hmajid2301 hmajid2301 deleted the add-nav-buddy branch October 3, 2023 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants