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

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

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

mamekoro
Copy link

@mamekoro mamekoro commented Nov 18, 2024

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 },
}

Copy link
Contributor

Review Checklist

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

Proper conventional commit scoping:

  • For example, fix(lsp): some lsp-related bugfix

  • Pull request title has the appropriate conventional commit prefix.

If applicable:

  • Tested
    • Tests have been added.
    • Tested manually (Steps to reproduce in PR description).
  • Updated documentation.

Copy link
Owner

@mrcjkb mrcjkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks 🙏

@mrcjkb mrcjkb changed the base branch from master to mj/push-psypykrzqtzp November 18, 2024 21:00
@mrcjkb mrcjkb merged commit 70edf15 into mrcjkb:mj/push-psypykrzqtzp Nov 18, 2024
1 check passed
mrcjkb added a commit that referenced this pull request Nov 18, 2024
feat(lsp): pass `client_id` to `on_initialized`

feat(lsp): pass client_id to on_initialized (#582) (#583)
mrcjkb added a commit that referenced this pull request Nov 18, 2024
feat(lsp): pass `client_id` to `on_initialized`

feat(lsp): pass client_id to on_initialized (#582) (#583)
mrcjkb added a commit that referenced this pull request Nov 18, 2024
feat(lsp): pass `client_id` to `on_initialized`

feat(lsp): pass client_id to on_initialized (#582) (#583)
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.

Pass client_id to on_initialized
2 participants