Skip to content
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

Add support for ra-multiplex #631

Closed
mralj opened this issue Dec 24, 2024 · 3 comments · Fixed by #632
Closed

Add support for ra-multiplex #631

mralj opened this issue Dec 24, 2024 · 3 comments · Fixed by #632
Labels
enhancement New feature or request

Comments

@mralj
Copy link

mralj commented Dec 24, 2024

Hi!

I cannot figure out how to make rustaceanvim work with ra-multiplex, and I'm not sure if something like this is even supported by rustaceanvim.

The way this is set up via regular LSP is as follows:

require("lspconfig").rust_analyzer.setup {
  cmd = vim.lsp.rpc.connect("127.0.0.1", 27631),
  -- When using unix domain sockets, use something like:
  --cmd = vim.lsp.rpc.connect("/path/to/ra-multiplex.sock"),
  settings = {
    ["rust-analyzer"] = {
      lspMux = {
        version = "1",
        method = "connect",
        server = "rust-analyzer",
      },
    },
  },
}

So I tried to mimic this using rustaceanvim:

local M = {}

M.init = function()
  vim.g.rustaceanvim = {
    server = {
      cmd = vim.lsp.rpc.connect("127.0.0.1", 27631),
      on_attach = function(client, bufnr)
        local lsp_map = function(mode, keys, func, desc)
          vim.keymap.set(mode, keys, func, { buffer = bufnr, desc = desc })
        end
        -- some key mappings here 
      end,
      default_settings = {
        -- rust-analyzer language server configuration
        ["rust-analyzer"] = {
          lspMux = {
            version = "1",
            method = "connect",
            server = "rust-analyzer",
          },
        },
      },
    },
  }
end

return M

But no luck; Even syntax isn't highlighted, and this is, I guess because I'm using vim.lsp.rpc.connect?
I see in the ra-multiplex log that a connection is established, but apart from that, nothing.
The checkhealth marks everything as OK.

My question is, is it possible to use the ra-multiplex with rustaceanvim at the moment, and if so, how?
And if not, would you consider adding this in the future?

One of the most obvious benefits is the "startup time," i.e., when I'm working on my project, it takes even a couple of minutes (on my MBP M1 16GB RAM) to get "everything going" (i.e., I get syntax highlighting and output of cargo check immediately, but for "show definition" or "go to references" to work, it takes even minutes).

@mralj
Copy link
Author

mralj commented Dec 24, 2024

@mrcjkb Wow, this was quick, thank you so much <3

I don't want to bother you with this further, but when I tested it on my machine, it works, but has this strange behaviour.
Whenever I try to switch to another file (for the first time for that file) via e.g. "go to definition" I'm greeted with this screen:

image

I've noticed following in output in ra-multiplex server:
[ WARN instance{pid=64414}: server responded with error res={"jsonrpc":"2.0","error":{"code":-32801,"message":"content modified"},"id":"client_id:0:n:8"}

I haven't noticed this error when using ra-multiplex with the LSP.
Here is my whole rustecaceanvim config:

local M = {}

M.init = function()
  vim.g.rustaceanvim = {
    server = {
      on_attach = function(client, bufnr)
        local lsp_map = function(mode, keys, func, desc)
          vim.keymap.set(mode, keys, func, { buffer = bufnr, desc = desc })
        end

        -- rust-lsp mappings
        lsp_map("n", "K", function()
          vim.cmd.RustLsp { "hover", "actions" }
        end, "Rust hover docs")
        lsp_map("n", "J", function()
          vim.cmd.RustLsp "joinLines"
        end, "Rust join lines")
        lsp_map("n", "<Leader>ca", function()
          vim.cmd.RustLsp "codeAction"
        end, "Rust Code action")
        lsp_map("n", "<Leader>rca", function()
          vim.cmd.RustLsp "explainError"
        end, "Rust error explain")
        lsp_map("n", "<Leader>ree", function()
          vim.cmd.RustLsp "openDocs"
        end, "Rust docs")
        lsp_map("n", "<Leader>rem", function()
          vim.cmd.RustLsp "expandMacro"
        end, "Rust expand macro")

        -- copy from lsp_config
        lsp_map("n", "gd", vim.lsp.buf.definition, "Goto definition")
        lsp_map("n", "gD", vim.lsp.buf.declaration, "Goto declaration")
        lsp_map("n", "gI", vim.lsp.buf.implementation, "Goto implementation")
        lsp_map("n", "go", vim.lsp.buf.type_definition, "Goto type definition")
        lsp_map("n", "gr", vim.lsp.buf.references, "Goto references")
        lsp_map("n", "ra", vim.lsp.buf.rename, "Rename")
      end,
    },
  }
end

return M

@mrcjkb
Copy link
Owner

mrcjkb commented Dec 24, 2024

oops 😅

I've noticed following in output in ra-multiplex server:
[ WARN instance{pid=64414}: server responded with error res={"jsonrpc":"2.0","error":{"code":-32801,"message":"content modified"},"id":"client_id:0:n:8"}

I don't think that's anything to worry about.
It seems to work fine in my tests and it works fine on my end.

thanks for reminding me about that project btw 🙏
It's pretty cool!

@mralj
Copy link
Author

mralj commented Dec 25, 2024

oops 😅
Yeah, it happens 🙈

Once again, thank you for jumping on this so quickly it works perfectly now 🥳
Merry Christmas, if you are celebrating, and if not have a great weekend :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants