Skip to content

Commit 1fcb991

Browse files
committed
feat!: drop support for rust-analyzer.json
in favour of `.vscode/settings.json` in the project root
1 parent 161360c commit 1fcb991

File tree

4 files changed

+16
-68
lines changed

4 files changed

+16
-68
lines changed

doc/rustaceanvim.txt

+5-6
Original file line numberDiff line numberDiff line change
@@ -494,19 +494,18 @@ LSP configuration utility *rustaceanvim.config.server*
494494
rustaceanvim.LoadRASettingsOpts *rustaceanvim.LoadRASettingsOpts*
495495

496496
Fields: ~
497-
{settings_file_pattern} (string|nil)
498-
(deprecated) File name or pattern to search for. Defaults to 'rust-analyzer.json'
499-
{default_settings} (table|nil) Default settings to merge the loaded settings into.
497+
{default_settings} (table|nil)
498+
Default settings to merge the loaded settings into.
500499

501500

502501
*server.load_rust_analyzer_settings*
503-
server.load_rust_analyzer_settings({project_root}, {opts})
502+
server.load_rust_analyzer_settings({_}, {opts})
504503
Load rust-analyzer settings from a JSON file,
505504
falling back to the default settings if none is found or if it cannot be decoded.
506505

507506
Parameters: ~
508-
{project_root} (string|nil) The project root
509-
{opts} (rustaceanvim.LoadRASettingsOpts|nil)
507+
{_} (string|nil) The project root (ignored)
508+
{opts} (rustaceanvim.LoadRASettingsOpts|nil)
510509

511510
Returns: ~
512511
(table) server_settings

lua/rustaceanvim/config/internal.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ local RustaceanDefaultConfig = {
306306
logfile = vim.fn.tempname() .. '-rust-analyzer.log',
307307

308308
---@type table | (fun(project_root:string|nil, default_settings: table|nil):table) -- The rust-analyzer settings or a function that creates them.
309-
settings = function(project_root, default_settings)
310-
return server_config.load_rust_analyzer_settings(project_root, { default_settings = default_settings })
309+
settings = function(_, default_settings)
310+
return server_config.load_rust_analyzer_settings(_, { default_settings = default_settings })
311311
end,
312312

313313
--- @type table

lua/rustaceanvim/config/server.lua

+9-43
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,39 @@ local server = {}
44

55
---@class rustaceanvim.LoadRASettingsOpts
66
---
7-
---(deprecated) File name or pattern to search for. Defaults to 'rust-analyzer.json'
8-
---@field settings_file_pattern string|nil
97
---Default settings to merge the loaded settings into.
108
---@field default_settings table|nil
119

1210
--- Load rust-analyzer settings from a JSON file,
1311
--- falling back to the default settings if none is found or if it cannot be decoded.
14-
---@param project_root string|nil The project root
12+
---@param _ string|nil The project root (ignored)
1513
---@param opts rustaceanvim.LoadRASettingsOpts|nil
1614
---@return table server_settings
1715
---@see https://rust-analyzer.github.io/book/configuration
18-
function server.load_rust_analyzer_settings(project_root, opts)
16+
function server.load_rust_analyzer_settings(_, opts)
1917
local config = require('rustaceanvim.config.internal')
20-
local os = require('rustaceanvim.os')
2118

2219
local default_opts = { settings_file_pattern = 'rust-analyzer.json' }
2320
opts = vim.tbl_deep_extend('force', {}, default_opts, opts or {})
24-
local default_settings = opts.default_settings or config.server.default_settings
21+
local settings = opts.default_settings or config.server.default_settings
2522
local use_clippy = config.tools.enable_clippy and vim.fn.executable('cargo-clippy') == 1
2623
---@diagnostic disable-next-line: undefined-field
2724
if
28-
default_settings['rust-analyzer'].check == nil
25+
settings['rust-analyzer'].check == nil
2926
and use_clippy
30-
and type(default_settings['rust-analyzer'].checkOnSave) ~= 'table'
27+
and type(settings['rust-analyzer'].checkOnSave) ~= 'table'
3128
then
3229
---@diagnostic disable-next-line: inject-field
33-
default_settings['rust-analyzer'].check = {
30+
settings['rust-analyzer'].check = {
3431
command = 'clippy',
3532
extraArgs = { '--no-deps' },
3633
}
37-
if type(default_settings['rust-analyzer'].checkOnSave) ~= 'boolean' then
34+
if type(settings['rust-analyzer'].checkOnSave) ~= 'boolean' then
3835
---@diagnostic disable-next-line: inject-field
39-
default_settings['rust-analyzer'].checkOnSave = true
36+
settings['rust-analyzer'].checkOnSave = true
4037
end
4138
end
42-
if not project_root then
43-
return default_settings
44-
end
45-
local results = vim.fn.glob(vim.fs.joinpath(project_root, opts.settings_file_pattern), true, true)
46-
if #results == 0 then
47-
return default_settings
48-
end
49-
vim.deprecate('rust-analyzer.json', "'.vscode/settings.json' or ':h exrc'", '6.0.0', 'rustaceanvim')
50-
local config_json = results[1]
51-
local content = os.read_file(config_json)
52-
if not content then
53-
vim.notify('Could not read ' .. config_json, vim.log.levels.WARN)
54-
return default_settings
55-
end
56-
local json = require('rustaceanvim.config.json')
57-
local rust_analyzer_settings = json.silent_decode(content)
58-
local ra_key = 'rust-analyzer'
59-
local has_ra_key = false
60-
for key, _ in pairs(rust_analyzer_settings) do
61-
if key:find(ra_key) ~= nil then
62-
has_ra_key = true
63-
break
64-
end
65-
end
66-
if has_ra_key then
67-
-- Settings json with "rust-analyzer" key
68-
json.override_with_rust_analyzer_json_keys(default_settings, rust_analyzer_settings)
69-
else
70-
-- "rust-analyzer" settings are top level
71-
json.override_with_json_keys(default_settings, rust_analyzer_settings)
72-
end
73-
return default_settings
39+
return settings
7440
end
7541

7642
---@return lsp.ClientCapabilities

spec/config_server_spec.lua

-17
This file was deleted.

0 commit comments

Comments
 (0)