Skip to content

Commit 581d7a4

Browse files
committed
feat(lsp)!: remove .vscode/settings.json support
1 parent 8490d5f commit 581d7a4

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
@@ -888,14 +888,13 @@ end
888888

889889
### How to dynamically load different `rust-analyzer` settings per project
890890

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

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

900899
Another option is to use `:h exrc`.
901900

doc/rustaceanvim.txt

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

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

174174

175175
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

@@ -188,7 +163,7 @@ Starting rust-analyzer client in detached/standalone mode (with reduced function
188163
root_dir = os.normalize_path_on_windows(root_dir)
189164
lsp_start_config.root_dir = root_dir
190165

191-
lsp_start_config.settings = get_start_settings(bufname, root_dir, client_config)
166+
lsp_start_config.settings = get_start_settings(root_dir, client_config)
192167
configure_file_watcher(lsp_start_config)
193168

194169
-- Check if a client is already running and add the workspace folder if necessary.
@@ -233,7 +208,7 @@ Starting rust-analyzer client in detached/standalone mode (with reduced function
233208
end
234209

235210
-- special case: rust-analyzer has a `rust-analyzer.server.path` config option
236-
-- that allows you to override the path via .vscode/settings.json
211+
-- that allows you to override the path.
237212
local server_path = vim.tbl_get(lsp_start_config.settings, 'rust-analyzer', 'server', 'path')
238213
if type(server_path) == 'string' then
239214
if type(rust_analyzer_cmd) == 'table' then
@@ -349,7 +324,7 @@ M.reload_settings = function(bufnr)
349324
local clients = rust_analyzer.get_active_rustaceanvim_clients(bufnr)
350325
---@cast clients vim.lsp.Client[]
351326
for _, client in ipairs(clients) do
352-
local settings = get_start_settings(vim.api.nvim_buf_get_name(bufnr), client.config.root_dir, config.server)
327+
local settings = get_start_settings(client.config.root_dir, config.server)
353328
---@diagnostic disable-next-line: inject-field
354329
client.settings = settings
355330
client:notify('workspace/didChangeConfiguration', {
@@ -390,7 +365,7 @@ function M.set_config(ra_settings)
390365
local clients = rust_analyzer.get_active_rustaceanvim_clients(bufnr)
391366
---@cast clients vim.lsp.Client[]
392367
for _, client in ipairs(clients) do
393-
local settings = get_start_settings(vim.api.nvim_buf_get_name(bufnr), client.config.root_dir, config.server)
368+
local settings = get_start_settings(client.config.root_dir, config.server)
394369
---@diagnostic disable-next-line: inject-field
395370
settings['rust-analyzer'] = vim.tbl_deep_extend('force', settings['rust-analyzer'], ra_settings)
396371
client.settings = settings

spec/json_spec.lua

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

0 commit comments

Comments
 (0)