-
Notifications
You must be signed in to change notification settings - Fork 17
Dirrefresh (#1) #66
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
base: main
Are you sure you want to change the base?
Dirrefresh (#1) #66
Conversation
Added `vim.cmd('edit .')` to refresh the nvim UI current directory after the `pwd` is changed to the remote filessytem.
Not sure if this is the best way of doing it. I had the issue of the UI not being updated on two separate machines running Fedora42 and Ubuntu22.04
|
Sorry for making multiple PRs and closing them, but this is the first time I have created a PR for an open-source project. |
|
When I use I will write the fix for this in this PR as well The error was caused because |
…ways false with a check if the name parameter exists and commented another place where or nil exists for double-checking
…nd added param comment
nosduco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I appreciate it :) I've reviewed the changes and have some suggestions for more elegant solutions:
Directory Refresh Issue
Instead of always changing to $HOME on disconnect maybe we can do something like
-- Store original directory before connecting
local original_dir = vim.fn.getcwd()
-- On disconnect, restore it
if original_dir and vim.fn.isdirectory(original_dir) == 1 then
utils.change_directory(original_dir)
end
Or add a config option: on_disconnect.change_dir = "previous" | "home" | false
Telescope Cache Clearing
The current pcall approach is actually safer than direct access. If you want to remove it, at least check existence:
local ok, ext = pcall(require, "telescope._extensions.remote-sshfs")
if ok and ext.clear_cache then
ext.clear_cache()
end
The core issue seems to be that users lose their working directory context when disconnecting. Storing and restoring the original directory would be the cleanest fix.
lua/remote-sshfs/utils.lua
Outdated
| if not ok then | ||
| vim.notify("Failed to change directory: " .. tostring(err), vim.log.levels.ERROR) | ||
| else | ||
| vim.cmd("edit .") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think there might be a cleaner way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I will think of a better way of handling this and add it to this PR. I will also implement the Directory Refresh Issue suggestion as it is a better approach, as you said.
The fmt checks should now pass, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regrading this, from what I have searched, using "edit ." is the only way I have found to referesh Netrw as it does not listen to the DirChanged triggered by the API call. Extensions like nvim-tree, mini.files might listen to it and change it, but from what I have read this is not the case for netrw. I am not sure what would be a better way of doing this.
…sion with pcall()
…mory release is done in the same stage
| vim.notify("Failed to change directory: " .. tostring(err), vim.log.levels.ERROR) | ||
| else | ||
| vim.cmd "edit ." | ||
| vim.notify("Directory changed to " .. path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this notify does not show when disconnecting. It happens as far as I can tell, but disconnecting from the host overwrites it very quickly.
|
I will keep working on this but I have been a bit busy with university lately. One problem that I am facing and maybe there is a better way of doing it is, I find it quite obscure to find out how to refresh the UI for nvim. For example finding an alternative for "edit .". Do you have any recommandations for where to look? I have been so far looking into the Nvim docs, but did not really find anything, it might also be that I have not looked enough or I missed it. Tired LLMs as well, but did not find anything useful. |
Added
vim.cmd('edit .')to refresh the nvim UI current directory after thepwdis changed to the remote filessytem.Not sure if this is the best way of doing it. I had the issue of the UI not being updated on two separate machines running Fedora42 and Ubuntu22.04