Skip to content

Commit 3dca79e

Browse files
author
Marc Jakobi
committed
feat(init): warn if nvim-lspconfig.rust_analyzer setup detected
1 parent 2484653 commit 3dca79e

File tree

6 files changed

+75
-15
lines changed

6 files changed

+75
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [4.16.0] - 2024-03-24
10+
11+
### Added
12+
13+
- Initialization: Warn if nvim-lspconfig.rust-analyzer setup is detected.
14+
915
## [4.15.0] - 2024-03-24
1016

1117
### Added

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,15 +801,20 @@ For issues related to rust-analyzer
801801
(e.g. LSP features not working), see also
802802
[the rust-analyzer troubleshooting guide](https://rust-analyzer.github.io/manual.html#troubleshooting).
803803

804-
## FAQ
804+
### FAQ
805805

806-
### Where are inlay hints?
806+
#### Where are inlay hints?
807807

808808
As Neovim >= 0.10 supports inlay hints natively, I have removed the
809809
code from this plugin.
810810

811811
To enable inlay hints in Neovim < 0.10, see [this discussion](https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822).
812812

813+
#### mason.nvim and nvim-lspconfig
814+
815+
See [`:h rustaceanvim.mason`](./doc/mason.txt) for details about troubleshooting
816+
mason.nvim and nvim-lspconfig issues.
817+
813818
## Related Projects
814819

815820
- [`rouge8/neotest-rust`](https://github.com/rouge8/neotest-rust)

doc/mason.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
==============================================================================
2+
mason-lspconfig troubleshooting *rustaceanvim.mason*
3+
4+
This plugin supports automatically detecting mason.nvim codelldb installations,
5+
but not rust-analyzer.
6+
The main reason for this choice is that it mason.nvim installations of rust-analyzer
7+
will most likely have been built with a different toolchain than your project,
8+
leading to inconsistencies and possibly subtle bugs.
9+
If you want to use a mason.nvim installation anyway, you can do so by specifying
10+
the `server.cmd` setting (see |rustaceanvim.config| and |RustaceanLspClientOpts|).
11+
12+
Note that mason-lspconfig.nvim, when configured to ensure rust-analyzer is installed,
13+
assumes you are using the `nvim-lspconfig.rust_analyzer` client,
14+
and will set it up for you, leading to conflicts with this plugin.
15+
You can prevent this by telling mason.nvim not to do so.
16+
17+
General approach:
18+
19+
>lua
20+
require('mason-lspconfig').setup_handlers {
21+
['rust_analyzer'] = function() end,
22+
}
23+
<
24+
25+
Using LazyVim:
26+
27+
>lua
28+
{
29+
'neovim/nvim-lspconfig',
30+
opts = {
31+
setup = {
32+
rust_analyzer = function()
33+
return true
34+
end,
35+
},
36+
},
37+
}
38+
<
39+
vim:tw=78:ts=8:noet:ft=help:norl:

ftplugin/rust.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
local config = require('rustaceanvim.config.internal')
33

44
if not vim.g.did_rustaceanvim_initialize then
5+
require('rustaceanvim.config.check').check_for_lspconfig_conflict(vim.schedule_wrap(function(warn)
6+
vim.notify_once(warn, vim.log.levels.WARN)
7+
end))
58
vim.lsp.commands['rust-analyzer.runSingle'] = function(command)
69
local runnables = require('rustaceanvim.runnables')
710
local cached_commands = require('rustaceanvim.cached_commands')

lua/rustaceanvim/config/check.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,23 @@ function M.validate(cfg)
137137
return true
138138
end
139139

140+
---@param callback fun(msg: string)
141+
function M.check_for_lspconfig_conflict(callback)
142+
for _, autocmd in ipairs(vim.api.nvim_get_autocmds { event = 'FileType', pattern = 'rust' }) do
143+
if
144+
autocmd.group_name
145+
and autocmd.group_name == 'lspconfig'
146+
and autocmd.desc
147+
and autocmd.desc:match('rust_analyzer')
148+
then
149+
callback([[
150+
nvim-lspconfig.rust_analyzer has been setup.
151+
This will likely lead to conflicts with the rustaceanvim LSP client.
152+
See ':h rustaceanvim.mason'
153+
]])
154+
return
155+
end
156+
end
157+
end
158+
140159
return M

lua/rustaceanvim/health.lua

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,7 @@ end
125125

126126
local function check_for_conflicts()
127127
start('Checking for conflicting plugins')
128-
for _, autocmd in ipairs(vim.api.nvim_get_autocmds { event = 'FileType', pattern = 'rust' }) do
129-
if
130-
autocmd.group_name
131-
and autocmd.group_name == 'lspconfig'
132-
and autocmd.desc
133-
and autocmd.desc:match('rust_analyzer')
134-
then
135-
error(
136-
'lspconfig.rust_analyzer has been setup. This will likely lead to conflicts with the rustaceanvim LSP client.'
137-
)
138-
return
139-
end
140-
end
128+
require('rustaceanvim.config.check').check_for_lspconfig_conflict(error)
141129
if package.loaded['rustaceanvim.neotest'] ~= nil and package.loaded['neotest-rust'] ~= nil then
142130
error('rustaceanvim.neotest and neotest-rust are both loaded. This is likely a conflict.')
143131
return

0 commit comments

Comments
 (0)