Skip to content

refactor: tidy actions submodules and improve API readability #2593

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

Merged
merged 4 commits into from
Dec 31, 2023

Conversation

Akmadan23
Copy link
Collaborator

Discussed in #2583

Copy link
Collaborator Author

@Akmadan23 Akmadan23 left a comment

Choose a reason for hiding this comment

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

The move of actions/tree-modifiers to actions/tree/modifiers is just a proposal, I think it makes sense to put it there but I can revert this change if it's better not to do that.
I would also move actions/reloaders/reloaders.lua to actions/reloaders/init.lua or even actions/reloaders.lua, as long as it's not a problem...

local marks_navigation = require "nvim-tree.marks.navigation"
local marks_bulk_delete = require "nvim-tree.marks.bulk-delete"
local marks_bulk_trash = require "nvim-tree.marks.bulk-trash"
local marks_bulk_move = require "nvim-tree.marks.bulk-move"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried to add the various init.luas in the marks module but dependency loops start to come up, so this is best solution I could find.

Copy link
Member

Choose a reason for hiding this comment

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

Marks are not quite like the other actions. They need a refactor / tidy but not today.

@alex-courtis
Copy link
Member

The move of actions/tree-modifiers to actions/tree/modifiers is just a proposal, I think it makes sense to put it there but I can revert this change if it's better not to do that. I would also move actions/reloaders/reloaders.lua to actions/reloaders/init.lua or even actions/reloaders.lua, as long as it's not a problem...

That's great - it is a hierarchy which makes sense.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

This is incredible! Api is finally readable. There's very little more we can do for now...

Now you have me thinking of ways we could get rid of wrap...


local events = require "nvim-tree.events"

Api.events.subscribe = wrap(events.subscribe)
Copy link
Member

Choose a reason for hiding this comment

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

We can't wrap this one - we alllow users to subscribe before setup is called.


Api.config.mappings.get_keymap = wrap(keymap.get_keymap)
Api.config.mappings.get_keymap_default = wrap(keymap.get_keymap_default)
Api.config.mappings.default_on_attach = wrap(keymap.default_on_attach)
Copy link
Member

Choose a reason for hiding this comment

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

No wrap for this one either; we let the users call this for before setup, even though it's an odd use case.

Api.marks.navigate.prev = wrap(marks_navigation.prev)
Api.marks.navigate.select = wrap(marks_navigation.select)

local keymap = require "nvim-tree.keymap"
Copy link
Member

Choose a reason for hiding this comment

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

Could we move these requires to the top, or is order important here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I put the definitions just before the references to easily trace back which module each variable refers to, of course we can move them to the top.

local marks_navigation = require "nvim-tree.marks.navigation"
local marks_bulk_delete = require "nvim-tree.marks.bulk-delete"
local marks_bulk_trash = require "nvim-tree.marks.bulk-trash"
local marks_bulk_move = require "nvim-tree.marks.bulk-move"
Copy link
Member

Choose a reason for hiding this comment

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

Marks are not quite like the other actions. They need a refactor / tidy but not today.

@Akmadan23 Akmadan23 marked this pull request as ready for review December 27, 2023 14:19
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Love your work. Let's get this in!

@@ -5,7 +5,7 @@ local core = require "nvim-tree.core"
local events = require "nvim-tree.events"
local notify = require "nvim-tree.notify"
local renderer = require "nvim-tree.renderer"
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
local reloaders = require "nvim-tree.actions.reloaders"
Copy link
Member

Choose a reason for hiding this comment

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

Nice

M.fs.setup(opts)
M.node.setup(opts)
M.root.setup(opts)
M.tree.setup(opts)
Copy link
Member

Choose a reason for hiding this comment

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

This @PostConstruct style is an unfortunate necessity for lua's "dependency injection".

I'll be mindful to add more of this as I touch files with odd instantiation mechanisms.

@alex-courtis alex-courtis merged commit f779aba into master Dec 31, 2023
@alex-courtis alex-courtis deleted the refactor-api branch December 31, 2023 04:52
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