Skip to content

Conversation

@Uanela
Copy link

@Uanela Uanela commented Oct 30, 2025

fixes #2988

This PR is part of one of the Multi Instance tasks and aims to make a refactor moving the root actions change_dir and dir_up to the Explorer class.

PS: This is my first contribution to some nvim plugin, I've using nvim for almost 4-5 months now and become interested in getting involved into its Open source world.

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 looking great, really happy with your contributions and it's working as per current behaviour.

Please:

The ones marked with a * will just go away if we move further with this refactor; see incoming comment.

local M = {}

---@param node Node
function M.fn(node)
Copy link
Member

Choose a reason for hiding this comment

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

This function has been moved to Explorer:dir_up and it's working beautifully there.
This is great as this function is now unused, therefore we can delete this whole file.

Copy link
Member

@alex-courtis alex-courtis Nov 29, 2025

Choose a reason for hiding this comment

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

Looks like this file is still present.

You might have to git rm lua/nvim-tree/explorer/dir-up.lua

Edit: I am mistaken, I was thinking of the old file location.

Edit2: this stands: we really don't need this file and it should be removed.

end
end

Explorer.change_dir = change_dir
Copy link
Member

Choose a reason for hiding this comment

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

Explorer.change_dir is assigned to the Explorer class, instead of the instance. This isn't great as all Explorer instances will share the same change_dir.
It should be set to the instance during the constructor e.g. self.change_dir = ...

@alex-courtis
Copy link
Member

alex-courtis commented Nov 3, 2025

Testing with lua/nvim-tree/explorer/dir-up.lua deleted.

Success: Base Cases

Open /home/alex/src/keyd

:NvimTreeOpen

<C-]> data
:pwd
/home/alex/src/keyd/data

-
:pwd
/home/alex/src/keyd

-
:pwd
/home/alex/src

Fail: respect_buf_cwd = true

Open /home/alex/src/keyd

:NvimTreeOpen

-

q

:NvimTreeOpen

E5108: Error executing lua: ...ack/packer/start/nvim-tree.lua.dev/lua/nvim-tree/lib.lua:30: module 'lua.nvim-tree.explorer.change-dir' not found:
        no field package.preload['lua.nvim-tree.explorer.change-dir']
        no file '/usr/share/lua/5.4/lua/nvim-tree/explorer/change-dir.lua'
        ...
stack traceback:
        [C]: in function 'require'
        ...ack/packer/start/nvim-tree.lua.dev/lua/nvim-tree/lib.lua:30: in function 'handle_buf_cwd'
        ...ack/packer/start/nvim-tree.lua.dev/lua/nvim-tree/lib.lua:38: in function 'open_view_and_draw'
        ...ack/packer/start/nvim-tree.lua.dev/lua/nvim-tree/lib.lua:132: in function 'open'
        ...rt/nvim-tree.lua.dev/lua/nvim-tree/actions/tree/open.lua:32: in function 'open'
        /tmp/nd/config/nvim/nd.lua:52: in function </tmp/nd/config/nvim/nd.lua:52>

@alex-courtis
Copy link
Member

This is great, I'm happy to merge (following fixes) OR we can go further in this pull request OR go further in the next pull request.

You've refactored the dir_up functionality to be a method of Explorer which is the best case end state.

If you're keen we can do the same for ALL the change-dir.lua functionality: fn(input_cwd, with_open) can be changed to a method Explorer:change_dir. The local functions in change-dir.lua can be changed to ---@private explorer methods.

What's the advantage? The code will simplify greatly when they are part of the explorer class:

  • core.get_explorer() won't be necessary
  • config is available so we can remove setup
  • core.cwd() is unnecessary etc.
  • other code will just melt away as methods are moved

@alex-courtis alex-courtis changed the title Moving root actions change_dir and dir_up to the Explorer class refactor(#2988): multi instance explore: change_dir and dir_up Nov 3, 2025
@alex-courtis alex-courtis changed the title refactor(#2988): multi instance explore: change_dir and dir_up refactor(#2988): multi instance change_dir and dir_up Nov 3, 2025
@alex-courtis
Copy link
Member

FYI you can execute all the CI checks locally so that you don't have to wait for CI.

Once you've merged this PR I can add you as a repo member so that you can run CI checks yourself.

@Uanela
Copy link
Author

Uanela commented Nov 5, 2025

@alex-courtis hope you doing well, thanks for your time, I will be making this changes by saturday and also following all other instructions and comments you left.

@alex-courtis
Copy link
Member

@alex-courtis hope you doing well, thanks for your time, I will be making this changes by saturday and also following all other instructions and comments you left.

There's no rush; we can take all the time we want.

@Uanela
Copy link
Author

Uanela commented Nov 14, 2025

@alex-courtis how is it hanging? sorry for disappearing, I just have been through some personal problems that's why I was unable to proceed on the they I mentioned.

On the weekend I will spending some time on it.

@Uanela Uanela requested a review from alex-courtis November 21, 2025 00:06
@Uanela
Copy link
Author

Uanela commented Nov 21, 2025

@Uanela
Copy link
Author

Uanela commented Nov 23, 2025

@alex-courtis are you there?

@alex-courtis
Copy link
Member

This PR was updated to meet the required changes of the last review:

Fantastic! I've run CI and there are a couple of issues requiring attention: https://github.com/nvim-tree/nvim-tree.lua/actions/runs/19577377412/job/56496916252?pr=3209

@alex-courtis are you there?

I should get to this review on the weekend.
Please note that the nvim-tree.lua project team are volunteers who have limited time available.

- Use wrap_explorer for change_root_to_parent to match other API methods
- Fix incorrect require paths in dir-up.lua (remove "lua." prefix)
- Remove unused explorer variable in change-dir.lua
- Move change_dir assignment in Explorer:new before _load call
- Add find_file require to explorer/init.lua for dir_up method
@Uanela
Copy link
Author

Uanela commented Nov 27, 2025

This PR was updated to meet the required changes of the last review:

Fantastic! I've run CI and there are a couple of issues requiring attention: https://github.com/nvim-tree/nvim-tree.lua/actions/runs/19577377412/job/56496916252?pr=3209

@alex-courtis are you there?

I should get to this review on the weekend. Please note that the nvim-tree.lua project team are volunteers who have limited time available.

I Just solved this but pre commit checks wouldn't let em commit, and I didn't noticed that I just ended up committing it right now successfully.

I yes I know the nvim-tree contributors a volunteers my bad be a little be annoying for yourselves.

@alex-courtis
Copy link
Member

Test Cases

Change Dir Down

Open /home/alex/src/keyd

:NvimTreeOpen

<C-]> data

Exception thrown:

E5108: Error executing lua: ...ack/packer/start/nvim-tree.lua.dev/lua/nvim-tree/api.lua:167: attempt to index field 'change_dir' (a nil value)

@alex-courtis
Copy link
Member

I Just solved this but pre commit checks wouldn't let em commit, and I didn't noticed that I just ended up committing it right now successfully.

That occurs for github security reasons. You will be able to run checks after you have merged your first PR.

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 looking good, your style has visibly improved since last review.

Please:

Copy link
Member

Choose a reason for hiding this comment

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

Please don't make unnecessary changes.

---@field opts table user options
---@field augroup_id integer
---@field renderer Renderer
---@field change_dir any
Copy link
Member

@alex-courtis alex-courtis Nov 29, 2025

Choose a reason for hiding this comment

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

This still isn't quite right: we're assigning the static change_dir module to a member field on the Explorer class. In this class we are directly calling the module change_dir directly, instead of via the member, which is the right way to use a static module.

We're stuck at a half way point in the refactor of change dir. The outcome of this issue is to have all of change dir moved into the Explorer class as methods. You've achieved this nicely for Explorer:dir_up.

Decision time:

Option 1:

  • complete both refactors, moving everything from change-dir.lua into Explorer

Option 2:

  • revert the change-dir changes
  • merge the dir-up changes
  • create a follow up PR for change-dir

This is my fault: I said "It might be easiest to split into two PRs." where I should have said "complete these changes in two PRs"

I strongly recommend option 2.
The first few multiinstance refactor PRs were done in single PRs; we started doing many refactors in one PR only after we were practiced.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your review once again, I quickly follow instructions and update the PR.

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.

Multi Instance: Refactor: move root actions to Explorer

2 participants