Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lsp): support top level object + rust-analyzer key in rust-analyzer.json #243

Merged
merged 1 commit into from
Feb 19, 2024
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
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
Loading