Skip to content

Conversation

@Chayanon-Ninyawee
Copy link
Contributor

Example Usage

require("my_module").setup({
  ...
  callback = {
    on_connect_success = function(host, mount_dir)
      print("Connected to", host, "and mounted at", mount_dir)
    end,
  },
})

So that is possible to use a remote lsp like this:

on_connect_success = function(host, mount_dir)
    local lsp_proxy_path = vim.fn.stdpath("config") .. "/lsp-proxy.py"

    local sshfs_prefix = mount_dir
    local remote_prefix = host["Path"] or ("/home/" .. host["User"])

    vim.lsp.config("remote-clangd", {
        cmd = {
            "python3",
            "-u",
            lsp_proxy_path,
            host["User"] .. "@" .. (host["HostName"] or host["Name"]),
            sshfs_prefix,
            remote_prefix,
            "clangd",
        },
    })
end

and it will change the lsp config cmd depending on which host is connected

since if I want to use an lsp from my raspi I need to swap the ~/.sshfs path with the actual path of the raspi

@Chayanon-Ninyawee Chayanon-Ninyawee changed the title Add on_connect_success callback to be used in config feat: add on_connect_success callback to be used in config Jul 31, 2025
@Chayanon-Ninyawee
Copy link
Contributor Author

I change it so that it can just be add like this:

require("remote-sshfs").callback.on_connect_success:add(function(host, mount_dir)
  vim.notify("Test 1")
end)
...
require("remote-sshfs").callback.on_connect_success:add(function(host, mount_dir)
  vim.notify("Test 2")
end)

and it will add more callback to the same event

@nosduco
Copy link
Owner

nosduco commented Aug 5, 2025

@Chayanon-Ninyawee Yeah I like this a lot. Could you potentially add to README how to use this and to example config? Or I can later. Thanks!

@nosduco nosduco merged commit a2f3f14 into nosduco:main Aug 7, 2025
3 checks passed
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