Skip to content

Commit 1e9ae23

Browse files
Marc Jakobimrcjkb
authored andcommitted
fix(lsp): load rust-analyzer.json into correct config field
1 parent 08ddf66 commit 1e9ae23

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [4.6.0] - 2024-02-07
1010

11+
### Added
12+
13+
- LSP: New `tools.enable_clippy` option (defaults to `true`).
14+
Enable clippy lints on save if a `cargo-clippy` installation
15+
is detected.
16+
1117
### Fixed
1218

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

1523
## [4.5.2] - 2024-02-06
1624

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ vim.g.rustaceanvim = {
664664
on_attach = function(client, bufnr)
665665
-- you can also put keymaps in here
666666
end,
667-
settings = {
667+
default_settings = {
668668
-- rust-analyzer language server configuration
669669
['rust-analyzer'] = {
670670
},
@@ -735,7 +735,7 @@ end
735735
By default, this plugin will look for a `rust-analyzer.json`[^2]
736736
file in the project root directory, and attempt to load it.
737737
If the file does not exist, or it can't be decoded,
738-
the default settings will be used.
738+
the `server.default_settings` will be used.
739739

740740
[^2]: See [this example](https://github.com/rust-analyzer/rust-project.json-example/blob/master/.vscode/settings.json)
741741
and the rust-analyzer [configuration manual](https://rust-analyzer.github.io/manual.html#configuration).

lua/rustaceanvim/config/server.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ function server.load_rust_analyzer_settings(project_root, opts)
3838
if #results == 0 then
3939
return default_settings
4040
end
41-
local settings_json = results[1]
42-
local content = read_file(settings_json)
43-
local success, settings = pcall(vim.json.decode, content)
41+
local config_json = results[1]
42+
local content = read_file(config_json)
43+
local success, rust_analyzer_settings = pcall(vim.json.decode, content)
4444
if not success then
45-
local msg = 'Could not decode ' .. settings_json .. '. Falling back to default settings.'
45+
local msg = 'Could not decode ' .. config_json .. '. Falling back to default settings.'
4646
vim.notify('rustaceanvim: ' .. msg, vim.log.levels.ERROR)
4747
return default_settings
4848
end
49-
return settings or default_settings
49+
default_settings['rust-analyzer'] = rust_analyzer_settings
50+
return default_settings
5051
end
5152

5253
return server

0 commit comments

Comments
 (0)