Skip to content

Commit 6865782

Browse files
authored
fix(lsp): support top level object + rust-analyzer key in rust-analyzer.json (#243)
1 parent ec3288d commit 6865782

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ 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.7.4] - 2024-02-19
10+
11+
### Fixed
12+
13+
- LSP: Support both top-level rust-analyzer object and object with
14+
`"rust-analyzer":` key when importing settings from `rust-analyzer.json`.
15+
The fix introduced in version 4.6.0 had accidentally broken
16+
backward compatibility. The new implementation is backward compatible again.
17+
918
## [4.7.3] - 2024-02-15
1019

1120
### Fixed

lua/rustaceanvim/config/server.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ function server.load_rust_analyzer_settings(project_root, opts)
5151
local config_json = results[1]
5252
local content = read_file(config_json)
5353
local success, rust_analyzer_settings = pcall(vim.json.decode, content)
54-
if not success then
54+
if not success or not rust_analyzer_settings then
5555
local msg = 'Could not decode ' .. config_json .. '. Falling back to default settings.'
5656
vim.notify('rustaceanvim: ' .. msg, vim.log.levels.ERROR)
5757
return default_settings
5858
end
59-
default_settings['rust-analyzer'] = rust_analyzer_settings
59+
local ra_key = 'rust-analyzer'
60+
if rust_analyzer_settings[ra_key] then
61+
-- Settings json with "rust-analyzer" key
62+
default_settings[ra_key] = rust_analyzer_settings[ra_key]
63+
else
64+
-- "rust-analyzer" settings are top level
65+
default_settings[ra_key] = rust_analyzer_settings
66+
end
6067
return default_settings
6168
end
6269

0 commit comments

Comments
 (0)