Skip to content

Commit

Permalink
fix(lsp): load rust-analyzer.json into correct config field
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Feb 7, 2024
1 parent 08ddf66 commit 1e9ae23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [4.6.0] - 2024-02-07

### Added

- LSP: New `tools.enable_clippy` option (defaults to `true`).
Enable clippy lints on save if a `cargo-clippy` installation
is detected.

### Fixed

- testables/neotest: Don't use nextest if disabled in the config.
- LSP: load project-local rust-analyzer.json configs into
`server['rust-analyzer']`, instead of replacing the `server` config.

## [4.5.2] - 2024-02-06

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ vim.g.rustaceanvim = {
on_attach = function(client, bufnr)
-- you can also put keymaps in here
end,
settings = {
default_settings = {
-- rust-analyzer language server configuration
['rust-analyzer'] = {
},
Expand Down Expand Up @@ -735,7 +735,7 @@ end
By default, this plugin will look for a `rust-analyzer.json`[^2]
file in the project root directory, and attempt to load it.
If the file does not exist, or it can't be decoded,
the default settings will be used.
the `server.default_settings` will be used.

[^2]: See [this example](https://github.com/rust-analyzer/rust-project.json-example/blob/master/.vscode/settings.json)
and the rust-analyzer [configuration manual](https://rust-analyzer.github.io/manual.html#configuration).
Expand Down
11 changes: 6 additions & 5 deletions lua/rustaceanvim/config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ function server.load_rust_analyzer_settings(project_root, opts)
if #results == 0 then
return default_settings
end
local settings_json = results[1]
local content = read_file(settings_json)
local success, settings = pcall(vim.json.decode, content)
local config_json = results[1]
local content = read_file(config_json)
local success, rust_analyzer_settings = pcall(vim.json.decode, content)
if not success then
local msg = 'Could not decode ' .. settings_json .. '. Falling back to default settings.'
local msg = 'Could not decode ' .. config_json .. '. Falling back to default settings.'
vim.notify('rustaceanvim: ' .. msg, vim.log.levels.ERROR)
return default_settings
end
return settings or default_settings
default_settings['rust-analyzer'] = rust_analyzer_settings
return default_settings
end

return server

0 comments on commit 1e9ae23

Please sign in to comment.