Skip to content

Commit

Permalink
fix(lsp): support top level object + rust-analyzer key in rust-analyz…
Browse files Browse the repository at this point in the history
…er.json (#243)
  • Loading branch information
mrcjkb authored Feb 19, 2024
1 parent ec3288d commit 6865782
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ 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.7.4] - 2024-02-19

### Fixed

- LSP: Support both top-level rust-analyzer object and object with
`"rust-analyzer":` key when importing settings from `rust-analyzer.json`.
The fix introduced in version 4.6.0 had accidentally broken
backward compatibility. The new implementation is backward compatible again.

## [4.7.3] - 2024-02-15

### Fixed
Expand Down
11 changes: 9 additions & 2 deletions lua/rustaceanvim/config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ function server.load_rust_analyzer_settings(project_root, opts)
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
if not success or not rust_analyzer_settings then
local msg = 'Could not decode ' .. config_json .. '. Falling back to default settings.'
vim.notify('rustaceanvim: ' .. msg, vim.log.levels.ERROR)
return default_settings
end
default_settings['rust-analyzer'] = rust_analyzer_settings
local ra_key = 'rust-analyzer'
if rust_analyzer_settings[ra_key] then
-- Settings json with "rust-analyzer" key
default_settings[ra_key] = rust_analyzer_settings[ra_key]
else
-- "rust-analyzer" settings are top level
default_settings[ra_key] = rust_analyzer_settings
end
return default_settings
end

Expand Down

0 comments on commit 6865782

Please sign in to comment.