From 6865782798bdca0d8f1b3a598fef878b001422d8 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Mon, 19 Feb 2024 08:45:58 +0100 Subject: [PATCH] fix(lsp): support top level object + rust-analyzer key in rust-analyzer.json (#243) --- CHANGELOG.md | 9 +++++++++ lua/rustaceanvim/config/server.lua | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c10a92..52f37172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lua/rustaceanvim/config/server.lua b/lua/rustaceanvim/config/server.lua index 21dd5d10..e90f4501 100644 --- a/lua/rustaceanvim/config/server.lua +++ b/lua/rustaceanvim/config/server.lua @@ -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