@@ -4,73 +4,39 @@ local server = {}
4
4
5
5
--- @class rustaceanvim.LoadRASettingsOpts
6
6
---
7
- --- (deprecated) File name or pattern to search for. Defaults to 'rust-analyzer.json'
8
- --- @field settings_file_pattern string | nil
9
7
--- Default settings to merge the loaded settings into.
10
8
--- @field default_settings table | nil
11
9
12
10
--- Load rust-analyzer settings from a JSON file,
13
11
--- 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 )
15
13
--- @param opts rustaceanvim.LoadRASettingsOpts | nil
16
14
--- @return table server_settings
17
15
--- @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 )
19
17
local config = require (' rustaceanvim.config.internal' )
20
- local os = require (' rustaceanvim.os' )
21
18
22
19
local default_opts = { settings_file_pattern = ' rust-analyzer.json' }
23
20
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
25
22
local use_clippy = config .tools .enable_clippy and vim .fn .executable (' cargo-clippy' ) == 1
26
23
--- @diagnostic disable-next-line : undefined-field
27
24
if
28
- default_settings [' rust-analyzer' ].check == nil
25
+ settings [' rust-analyzer' ].check == nil
29
26
and use_clippy
30
- and type (default_settings [' rust-analyzer' ].checkOnSave ) ~= ' table'
27
+ and type (settings [' rust-analyzer' ].checkOnSave ) ~= ' table'
31
28
then
32
29
--- @diagnostic disable-next-line : inject-field
33
- default_settings [' rust-analyzer' ].check = {
30
+ settings [' rust-analyzer' ].check = {
34
31
command = ' clippy' ,
35
32
extraArgs = { ' --no-deps' },
36
33
}
37
- if type (default_settings [' rust-analyzer' ].checkOnSave ) ~= ' boolean' then
34
+ if type (settings [' rust-analyzer' ].checkOnSave ) ~= ' boolean' then
38
35
--- @diagnostic disable-next-line : inject-field
39
- default_settings [' rust-analyzer' ].checkOnSave = true
36
+ settings [' rust-analyzer' ].checkOnSave = true
40
37
end
41
38
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
74
40
end
75
41
76
42
--- @return lsp.ClientCapabilities
0 commit comments