@@ -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
7440end
7541
7642--- @return lsp.ClientCapabilities
0 commit comments