Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.16.0] - 2024-03-24

### Added

- Initialization: Warn if nvim-lspconfig.rust-analyzer setup is detected.

## [4.15.0] - 2024-03-24

### Added
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,15 +801,20 @@ For issues related to rust-analyzer
(e.g. LSP features not working), see also
[the rust-analyzer troubleshooting guide](https://rust-analyzer.github.io/manual.html#troubleshooting).

## FAQ
### FAQ

### Where are inlay hints?
#### Where are inlay hints?

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

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

#### mason.nvim and nvim-lspconfig

See [`:h rustaceanvim.mason`](./doc/mason.txt) for details about troubleshooting
mason.nvim and nvim-lspconfig issues.

## Related Projects

- [`rouge8/neotest-rust`](https://github.com/rouge8/neotest-rust)
Expand Down
39 changes: 39 additions & 0 deletions doc/mason.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
==============================================================================
mason-lspconfig troubleshooting *rustaceanvim.mason*

This plugin supports automatically detecting mason.nvim codelldb installations,
but not rust-analyzer.
The main reason for this choice is that it mason.nvim installations of rust-analyzer
will most likely have been built with a different toolchain than your project,
leading to inconsistencies and possibly subtle bugs.
If you want to use a mason.nvim installation anyway, you can do so by specifying
the `server.cmd` setting (see |rustaceanvim.config| and |RustaceanLspClientOpts|).

Note that mason-lspconfig.nvim, when configured to ensure rust-analyzer is installed,
assumes you are using the `nvim-lspconfig.rust_analyzer` client,
and will set it up for you, leading to conflicts with this plugin.
You can prevent this by telling mason.nvim not to do so.

General approach:

>lua
require('mason-lspconfig').setup_handlers {
['rust_analyzer'] = function() end,
}
<

Using LazyVim:

>lua
{
'neovim/nvim-lspconfig',
opts = {
setup = {
rust_analyzer = function()
return true
end,
},
},
}
<
vim:tw=78:ts=8:noet:ft=help:norl:
3 changes: 3 additions & 0 deletions ftplugin/rust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
local config = require('rustaceanvim.config.internal')

if not vim.g.did_rustaceanvim_initialize then
require('rustaceanvim.config.check').check_for_lspconfig_conflict(vim.schedule_wrap(function(warn)
vim.notify_once(warn, vim.log.levels.WARN)
end))
vim.lsp.commands['rust-analyzer.runSingle'] = function(command)
local runnables = require('rustaceanvim.runnables')
local cached_commands = require('rustaceanvim.cached_commands')
Expand Down
19 changes: 19 additions & 0 deletions lua/rustaceanvim/config/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,23 @@ function M.validate(cfg)
return true
end

---@param callback fun(msg: string)
function M.check_for_lspconfig_conflict(callback)
for _, autocmd in ipairs(vim.api.nvim_get_autocmds { event = 'FileType', pattern = 'rust' }) do
if
autocmd.group_name
and autocmd.group_name == 'lspconfig'
and autocmd.desc
and autocmd.desc:match('rust_analyzer')
then
callback([[
nvim-lspconfig.rust_analyzer has been setup.
This will likely lead to conflicts with the rustaceanvim LSP client.
See ':h rustaceanvim.mason'
]])
return
end
end
end

return M
14 changes: 1 addition & 13 deletions lua/rustaceanvim/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,7 @@ end

local function check_for_conflicts()
start('Checking for conflicting plugins')
for _, autocmd in ipairs(vim.api.nvim_get_autocmds { event = 'FileType', pattern = 'rust' }) do
if
autocmd.group_name
and autocmd.group_name == 'lspconfig'
and autocmd.desc
and autocmd.desc:match('rust_analyzer')
then
error(
'lspconfig.rust_analyzer has been setup. This will likely lead to conflicts with the rustaceanvim LSP client.'
)
return
end
end
require('rustaceanvim.config.check').check_for_lspconfig_conflict(error)
if package.loaded['rustaceanvim.neotest'] ~= nil and package.loaded['neotest-rust'] ~= nil then
error('rustaceanvim.neotest and neotest-rust are both loaded. This is likely a conflict.')
return
Expand Down