Skip to content

feat: allow changing root to dir #2779

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

Closed
wants to merge 1 commit into from

Conversation

sarmong
Copy link
Collaborator

@sarmong sarmong commented May 21, 2024

No description provided.

@sarmong
Copy link
Collaborator Author

sarmong commented May 21, 2024

Also, is there a reason why it doesn't allow changing directory if it's under cwd? I kinda want to remove it

-- test if in cwd
if utils.path_relative(path, cwd) ~= path then
return
end

@gegoune
Copy link
Collaborator

gegoune commented May 21, 2024

Could you please describe what problem does it solve?

@sarmong
Copy link
Collaborator Author

sarmong commented May 22, 2024

Changing root to dir? Well, first of all, I think it simply makes sense and nowhere in the docs does it say that only providing filename is allowed. I am using this api method directly and want to set nvim-tree root to a directory.

Regarding setting path under cwd - my problem is following. I made my own command :Cd that sets project root based on custom heuristics. Example: my project root is in /foo/bar. Current directory is /foo/bar/baz. In nvim-tree I navigate to check something upwards and end up in /foo. Now I want to call my command to reset root to project root everywhere. Buy I can't for nvim-tree.

Yes, I know I can use sync_root_with_cwd, but it works on DirChanged. But it might happen so that my vim cwd is already /foo/bar, but I still want to call :Cd to reset root everywhere. However, it won't do anything for nvim-tree.

@sarmong sarmong requested review from alex-courtis and gegoune May 23, 2024 20:03
@alex-courtis
Copy link
Member

I have a similar use case: :CD changes to the initial directory however I do use sync_root_with_cwd.

I like the change, however we can't make it at this point: it will break open, find_file etc. which pass a file path.

Could you use the nvim-tree-api.tree.change_root() API? We could enhance it if we need to.

@sarmong
Copy link
Collaborator Author

sarmong commented May 25, 2024

I am not sure how it would break the existing API. It calls to fnamemodify and it will return dirname no matter if path is a dir or a file

https://github.com/sarmong/nvim-tree.lua/blob/e60118db9a072bb5cfb9353fab1d63f1a819848b/lua/nvim-tree.lua#L75-L75

@alex-courtis
Copy link
Member

Could you use the nvim-tree-api.tree.change_root() API? We could enhance it if we need to.

Firstly, please accept my apologies; I was confused and thought this method was private, not API.

I am not sure how it would break the existing API. It calls to fnamemodify and it will return dirname no matter if path is a dir or a file

Sorry mate, I'm not willing to take the risk. This area functionality is very fragile and has broken frequently in the past.

I'm still not quite sure what the issue is; I'm not experiencing any issues changing to a directory.

Please provide a replicator and instructions on how to reproduce problem behaviour as a bug report

@alex-courtis
Copy link
Member

I'm still keen to get this one in, however it's been inactive for a while.

Please reopen when you'd like to continue @sarmong

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.

3 participants