Skip to content

Conversation

@davidoroian
Copy link

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

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
@davidoroian
Copy link
Author

Sorry for making multiple PRs and closing them, but this is the first time I have created a PR for an open-source project.

@davidoroian
Copy link
Author

davidoroian commented Sep 29, 2025

When I use api.disconnect I get:

E5108: Error executing lua: .../lazy/remote-sshfs.nvim/lua/remote-sshfs/connections.lua:303: attempt to index a boolean value                                                              
stack traceback:                                                                                                                                                                           
        .../lazy/remote-sshfs.nvim/lua/remote-sshfs/connections.lua:303: in function 'unmount_host'                                                                                        
        ...are/nvim/lazy/remote-sshfs.nvim/lua/remote-sshfs/api.lua:12: in function <...are/nvim/lazy/remote-sshfs.nvim/lua/remote-sshfs/api.lua:11>

I will write the fix for this in this PR as well

The error was caused because pcall returns two values: a boolean (true, false) and what would be the module. But, in the telescope extension register_extension returns a boolean as well. That is why there is the attempt to index a boolean.

@davidoroian davidoroian marked this pull request as draft September 29, 2025 05:08
…ways false with a check if the name parameter exists and commented another place where or nil exists for double-checking
@davidoroian davidoroian marked this pull request as ready for review September 29, 2025 06:51
Copy link
Owner

@nosduco nosduco left a 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.

if not ok then
vim.notify("Failed to change directory: " .. tostring(err), vim.log.levels.ERROR)
else
vim.cmd("edit .")
Copy link
Owner

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.

Copy link
Author

@davidoroian davidoroian Sep 30, 2025

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.

Copy link
Author

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.

vim.notify("Failed to change directory: " .. tostring(err), vim.log.levels.ERROR)
else
vim.cmd "edit ."
vim.notify("Directory changed to " .. path)
Copy link
Author

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.

@davidoroian davidoroian requested a review from nosduco October 5, 2025 11:40
@davidoroian
Copy link
Author

davidoroian commented Nov 1, 2025

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.

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