Skip to content

Commit a522e53

Browse files
authored
feat(lsp)!: remove .vscode/settings.json support in favour of codesettings.nvim (#938)
1 parent 6637583 commit a522e53

File tree

7 files changed

+13
-230
lines changed

7 files changed

+13
-230
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,14 +906,13 @@ end
906906

907907
### How to dynamically load different `rust-analyzer` settings per project
908908

909-
By default, this plugin will look for a `.vscode/settings.json`[^2]
910-
file and attempt to load it.
911-
If the file does not exist, or it can't be decoded,
912-
the `server.default_settings` will be used.
909+
You can use the [codesettings.nvim](https://github.com/mrjones2014/codesettings.nvim),
910+
which supports loading project-local LSP from `.vscode/settings.json`[^2],
911+
among others.
912+
If it is installed, rustaceanvim will try to invoke it automatically.
913913

914914
[^2]: See [this example](https://github.com/rust-analyzer/rust-project.json-example/blob/master/.vscode/settings.json)
915915
and the rust-analyzer [configuration manual](https://rust-analyzer.github.io/book/configuration).
916-
Note that JSON5 is currently not supported by Neovim.
917916

918917
Another option is to use `:h exrc`.
919918

doc/rustaceanvim.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ vim.g.rustaceanvim = {
169169
Notes:
170170

171171
- `vim.g.rustaceanvim` can also be a function that returns a |rustaceanvim.Opts| table.
172-
- You can also configure the rust-analyzer LSP client using a `.vscode/settings.json` file
173-
or via |vim.lsp.config()| (using the `'rust-analyzer'` key).
172+
- You can also configure the rust-analyzer LSP client via |vim.lsp.config()|
173+
(using the `'*'` or `'rust-analyzer'` key).
174174

175175

176176
rustaceanvim.Opts *rustaceanvim.Opts*

lua/rustaceanvim/config/init.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
---Notes:
4040
---
4141
--- - `vim.g.rustaceanvim` can also be a function that returns a |rustaceanvim.Opts| table.
42-
--- - You can also configure the rust-analyzer LSP client using a `.vscode/settings.json` file
43-
--- or via |vim.lsp.config()| (using the `'rust-analyzer'` key).
42+
--- - You can also configure the rust-analyzer LSP client via |vim.lsp.config()|
43+
--- (using the `'*'` or `'rust-analyzer'` key).
4444
---
4545
---@brief ]]
4646

@@ -219,11 +219,6 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
219219
---The path to the rust-analyzer log file.
220220
---@field logfile? string
221221
---
222-
---Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json.
223-
---If found, loaded settings will override configured options.
224-
---Default: `true`
225-
---@field load_vscode_settings? boolean
226-
---
227222
---Server status warning level to notify at.
228223
---Default: 'error'
229224
---@field status_notify_level? rustaceanvim.server.status_notify_level

lua/rustaceanvim/config/internal.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,6 @@ local RustaceanDefaultConfig = {
317317
--- @type table
318318
['rust-analyzer'] = {},
319319
},
320-
---@type boolean Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json.
321-
load_vscode_settings = true,
322320
---@type rustaceanvim.server.status_notify_level
323321
status_notify_level = 'error',
324322
},

lua/rustaceanvim/config/json.lua

Lines changed: 0 additions & 96 deletions
This file was deleted.

lua/rustaceanvim/lsp/init.lua

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,16 @@ local function is_in_workspace(client, root_dir)
3737
return false
3838
end
3939

40-
---Searches upward for a .vscode/settings.json that contains rust-analyzer
41-
---settings and returns them.
42-
---@param bufname string
43-
---@return table server_settings or an empty table if no settings were found
44-
local function find_vscode_settings(bufname)
45-
local settings = {}
46-
local found_dirs = vim.fs.find({ '.vscode' }, { upward = true, path = vim.fs.dirname(bufname), type = 'directory' })
47-
if vim.tbl_isempty(found_dirs) then
48-
return settings
49-
end
50-
local vscode_dir = found_dirs[1]
51-
local results = vim.fn.glob(vim.fs.joinpath(vscode_dir, 'settings.json'), true, true)
52-
if vim.tbl_isempty(results) then
53-
return settings
54-
end
55-
local content = os.read_file(results[1])
56-
return content and require('rustaceanvim.config.json').silent_decode(content) or {}
57-
end
58-
5940
---Generate the settings from config and vscode settings if found.
6041
---settings and returns them.
61-
---@param bufname string
6242
---@param root_dir string | nil
6343
---@param client_config table
6444
---@return table server_settings or an empty table if no settings were found
65-
local function get_start_settings(bufname, root_dir, client_config)
45+
local function get_start_settings(root_dir, client_config)
6646
local settings = client_config.settings
6747
local evaluated_settings = type(settings) == 'function' and settings(root_dir, client_config.default_settings)
6848
or settings
6949

70-
if config.server.load_vscode_settings then
71-
local json_settings = find_vscode_settings(bufname)
72-
require('rustaceanvim.config.json').override_with_rust_analyzer_json_keys(evaluated_settings, json_settings)
73-
end
74-
7550
return evaluated_settings
7651
end
7752

@@ -199,7 +174,7 @@ Starting rust-analyzer client in detached/standalone mode (with reduced function
199174
root_dir = os.normalize_path_on_windows(root_dir)
200175
lsp_start_config.root_dir = root_dir
201176

202-
lsp_start_config.settings = get_start_settings(bufname, root_dir, client_config)
177+
lsp_start_config.settings = get_start_settings(root_dir, client_config)
203178
configure_file_watcher(lsp_start_config)
204179

205180
-- Check if a client is already running and add the workspace folder if necessary.
@@ -244,7 +219,7 @@ Starting rust-analyzer client in detached/standalone mode (with reduced function
244219
end
245220

246221
-- special case: rust-analyzer has a `rust-analyzer.server.path` config option
247-
-- that allows you to override the path via .vscode/settings.json
222+
-- that allows you to override the path.
248223
local server_path = vim.tbl_get(lsp_start_config.settings, 'rust-analyzer', 'server', 'path')
249224
if type(server_path) == 'string' then
250225
if type(rust_analyzer_cmd) == 'table' then
@@ -361,7 +336,7 @@ M.reload_settings = function(bufnr)
361336
local clients = rust_analyzer.get_active_rustaceanvim_clients(bufnr)
362337
---@cast clients vim.lsp.Client[]
363338
for _, client in ipairs(clients) do
364-
local settings = get_start_settings(vim.api.nvim_buf_get_name(bufnr), client.config.root_dir, config.server)
339+
local settings = get_start_settings(client.config.root_dir, config.server)
365340
---@diagnostic disable-next-line: inject-field
366341
client.settings = settings
367342
client:notify('workspace/didChangeConfiguration', {
@@ -403,7 +378,7 @@ function M.set_config(bufnr, ra_settings)
403378
local clients = rust_analyzer.get_active_rustaceanvim_clients(bufnr)
404379
---@cast clients vim.lsp.Client[]
405380
for _, client in ipairs(clients) do
406-
local settings = get_start_settings(vim.api.nvim_buf_get_name(bufnr), client.config.root_dir, config.server)
381+
local settings = get_start_settings(client.config.root_dir, config.server)
407382
---@diagnostic disable-next-line: inject-field
408383
settings['rust-analyzer'] = vim.tbl_deep_extend('force', settings['rust-analyzer'], ra_settings)
409384
client.settings = settings

spec/json_spec.lua

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)