mrcjkb / rustaceanvim

🦀 Supercharge your Rust experience in Neovim! A heavily modified fork of rust-tools.nvim
GNU General Public License v2.0
1.8k stars 69 forks source link

feat(lsp): pass client_id to on_initialized (#582) #583

Closed mamekoro closed 1 week ago

mamekoro commented 1 week ago

Fixes #582 .

This PR allows us to safely define and execute buffer-local commands in the on_initialized function by querying the buffers used by the LSP client identified by the newly added client_id parameter.

This is backward compatible, since the client_id was added after the existing parameter, not before.

Testing

I did the following tests.

--[[
1. Open two Rust projects in a single Neovim instance.
cd project
nvim -o src/main.rs ~/another_rust_project/src/main.rs

2. Wait for the two LSP clients to finish indexing.

3. Run `:messages`.
I got the following output. It's working as expected.

{
  client_id = 1,
  status = {
    health = "ok",
    quiescent = true
  }
}
{
  client_id = 2,
  status = {
    health = "ok",
    quiescent = true
  }
}
]]
local function on_initialized(status, client_id)
    vim.print({ status = status, client_id = client_id })
end

--[[
1. Perform the same steps as above.

I got the following output.
It's working without the `client_id` parameter.
This is expected and backward compatible.

{
  status = {
    health = "ok",
    quiescent = true
  }
}
{
  status = {
    health = "ok",
    quiescent = true
  }
}
]]
local function backward_compatibility(status)
    vim.print({ status = status })
end

vim.g.rustaceanvim = {
    -- Please uncomment the one you want to test.
    -- tools = { on_initialized = on_initialized },
    -- tools = { on_initialized = backward_compatibility },
}
github-actions[bot] commented 1 week ago

Review Checklist

Does this PR follow the Contribution Guidelines? Following is a partial checklist:

Proper conventional commit scoping:

If applicable: