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

fix(lsp): not reuse lsp client for standalone file #189

Closed
wants to merge 1 commit into from

Conversation

Bacbia3696
Copy link

If I open first standalone rust file, all lsp function work as expected, but when I open the second file. It will reuse lsp client for this second file, so all the lsp function is not supported.

Because vim.lsp.start will reuse lsp client if we start the the same root_dir (which is nil in this case)

This PR will check if root_dir == nil, we not reuse lsp client

I also update ftplugin to prevent start function run twice.

Copy link
Contributor

github-actions bot commented Jan 27, 2024

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.
  • Updated CHANGELOG.md

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.

Hey 👋

Thanks for the PR!

I've tested this, and it will spawn a separate rust-analyzer process for every standalone rust file opened.

I'll think about this and see if I can come up with an alternate solution.

Update: We need to wait for rust-lang/rust-analyzer#14318 to be resolved, before we can implement a proper fix:

// FIXME: The primary limitation of this approach is that the set of detached files needs to be fixed at the beginning. 
// That's not the end user experience we should strive for. 

I don't think spawning a separate rust-analyzer process for each standalone file is a good workaround, because it could easily get out of hand.

What you can do as a workaround is run :RustAnalyzer restart, and it will pick up the new detached file (but not the old one).

Comment on lines +1 to +6
if vim.b.did_ftplugin_rustacean then
return
end

vim.b.did_ftplugin_rustacean = 1

Copy link
Owner

@mrcjkb mrcjkb Jan 27, 2024

Choose a reason for hiding this comment

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

I've implemented a fix for setting up the vim.lsp.commands for rust-analyzer only once in a24df27

and a fix for doing ftplugin stuff in a503d05

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