Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor(#2988): multi instance change_dir and dir_up#3209

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Uanela wants to merge3 commits intonvim-tree:master
base:master
Choose a base branch
Loading
fromUanela:refactor-explorer-actions

Conversation

@Uanela
Copy link

@UanelaUanela commentedOct 30, 2025
edited by alex-courtis
Loading

fixes#2988

This PR is part of one of the Multi Instance tasks and aims to make a refactor moving the root actionschange_dir anddir_up to theExplorer 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.

gegoune reacted with heart emoji
Copy link
Member

@alex-courtisalex-courtis left a comment
edited
Loading

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.

localM= {}

---@paramnodeNode
functionM.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 toExplorer:dir_up and it's working beautifully there.
This is great as this function is now unused, therefore we can delete this whole file.


---@returnboolean
localfunctionshould_change_dir()
localexplorer=core.get_explorer()
Copy link
Member

Choose a reason for hiding this comment

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

This variableexplorer is unused and has been identified by the linter:https://github.com/nvim-tree/nvim-tree.lua/actions/runs/18935214550/job/54313031114?pr=3209

This line should be deleted.


Api.tree.change_root_to_parent=wrap_node(actions.root.dir_up.fn)

Api.tree.change_root_to_parent=wrap_node(Explorer.dir_up)
Copy link
Member

Choose a reason for hiding this comment

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

This change calls the newdir_up method. This isn't correct as the call is to the functionExplorer.dir_up rather than the methodExplorer:dir_up.
You can use

wrap_node(wrap_explorer("dir_up"))

instead.wrap_explorer will calldir_up as a method andwrap_node will pass the node.

Why is that a problem? Whendir_up is called,self is set to the node, notexplorer.
You can see this by adding some debug to the start ofExplorer:dir_up

require("nvim-tree.log").line("dev","self %s",selfandself.absolute_pathor"no self")require("nvim-tree.log").line("dev","node %s",nodeandnode.absolute_pathor"no node")

- on the data directory as per base test cases.

[2025-11-03 11:34:32] [dev] self /home/alex/src/keyd/data[2025-11-03 11:34:32] [dev] node no node

Expected:

[2025-11-03 11:32:34] [dev] self /home/alex/src/keyd[2025-11-03 11:32:34] [dev] node /home/alex/src/keyd/data

localfunctionhandle_buf_cwd(cwd)
ifM.respect_buf_cwdandcwd~=core.get_cwd()then
require("nvim-tree.actions.root.change-dir").fn(cwd)
require("lua.nvim-tree.explorer.change-dir").fn(cwd)
Copy link
Member

Choose a reason for hiding this comment

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

This change requires the movedchange-dir.lua module. It's throwing an exception as the module does not exist.
The require should berequire("nvim-tree.explorer.change-dir")

See the exception in section "Fail: respect_buf_cwd = true" in the test document.

Copy link
Member

Choose a reason for hiding this comment

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

Great work! Unnecessary code gone!

returnself:clone()
end

---@paramnodeNode
Copy link
Member

Choose a reason for hiding this comment

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

Annotations are necessary for linting and LSP integration. Thank you for adding them.

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 theExplorer class, instead of the instance. This isn't great as allExplorer instances will share the samechange_dir.
It should be set to the instance during the constructor e.g.self.change_dir = ...

end
localnewdir=vim.fn.fnamemodify(utils.path_remove_trailing(cwd),":h")
require("nvim-tree.explorer.change-dir").fn(newdir)
require("nvim-tree.actions.finders.find-file").fn(node.absolute_path)
Copy link
Member

Choose a reason for hiding this comment

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

The modulefind-file is required inline instead of at the start of the module. This isn't desirable: all modules should be required only once at startup and shared. Inline requires can result in problems appearing at runtime rather than startup, as they are lazily evaluated.

localfind_file=require("nvim-tree.actions.finders.find-file")

Why do we have some inline requires? There are circular dependencies that forced it. One of the goals of this refactoring work is to remove circular dependencies.

return
end
localnewdir=vim.fn.fnamemodify(utils.path_remove_trailing(cwd),":h")
require("nvim-tree.explorer.change-dir").fn(newdir)
Copy link
Member

Choose a reason for hiding this comment

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

Thechange-dir.lua module is required inline however we can use thechange_dir member ofExplorer. It could be simplified to:

M.change_dir.fn(newdir)

@alex-courtis
Copy link
Member

alex-courtis commentedNov 3, 2025
edited
Loading

Testing withlua/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 thedir_up functionality to be a method ofExplorer which is the best case end state.

If you're keen we can do the same for ALL thechange-dir.lua functionality:fn(input_cwd, with_open) can be changed to a methodExplorer:change_dir. The local functions inchange-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 removesetup
  • core.cwd() is unnecessary etc.
  • other code will just melt away as methods are moved

@alex-courtisalex-courtis changed the titleMoving root actionschange_dir anddir_up to theExplorer classrefactor(#2988): multi instance explore: change_dir and dir_upNov 3, 2025
@alex-courtisalex-courtis changed the titlerefactor(#2988): multi instance explore: change_dir and dir_uprefactor(#2988): multi instance change_dir and dir_upNov 3, 2025
@alex-courtis
Copy link
Member

FYI you canexecute 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

@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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@alex-courtisalex-courtisalex-courtis requested changes

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Multi Instance: Refactor: move root actions to Explorer

2 participants

@Uanela@alex-courtis

[8]ページ先頭

©2009-2025 Movatter.jp