Refresh generated neovim config
This commit is contained in:
@ -59,6 +59,7 @@ function cargo.get_root_dir(file_name)
|
||||
upward = true,
|
||||
path = path,
|
||||
})[1])
|
||||
---@type string | nil
|
||||
local cargo_workspace_dir = nil
|
||||
if vim.fn.executable('cargo') == 1 then
|
||||
local cmd = { 'cargo', 'metadata', '--no-deps', '--format-version', '1' }
|
||||
@ -80,8 +81,10 @@ function cargo.get_root_dir(file_name)
|
||||
cm = -1
|
||||
end
|
||||
if cm == 0 then
|
||||
cargo_workspace_dir = vim.fn.json_decode(cargo_metadata)['workspace_root']
|
||||
---@cast cargo_workspace_dir string
|
||||
local ok, cargo_metadata_json = pcall(vim.fn.json_decode, cargo_metadata)
|
||||
if ok and cargo_metadata_json then
|
||||
cargo_workspace_dir = cargo_metadata_json['workspace_root']
|
||||
end
|
||||
end
|
||||
end
|
||||
return cargo_workspace_dir
|
||||
|
||||
@ -332,17 +332,17 @@ function M.create_rust_lsp_command()
|
||||
bang = true,
|
||||
desc = 'Interacts with the rust-analyzer LSP client',
|
||||
complete = function(arg_lead, cmdline, _)
|
||||
local commands = cmdline:match('^' .. rust_lsp_cmd_name .. '!') ~= nil
|
||||
local commands = cmdline:match("^['<,'>]*" .. rust_lsp_cmd_name .. '!') ~= nil
|
||||
-- bang!
|
||||
and tbl_keys_by_value_filter(function(command)
|
||||
return command.bang == true
|
||||
end, rustlsp_command_tbl)
|
||||
or vim.tbl_keys(rustlsp_command_tbl)
|
||||
local subcmd, subcmd_arg_lead = cmdline:match('^' .. rust_lsp_cmd_name .. '[!]*%s(%S+)%s(.*)$')
|
||||
local subcmd, subcmd_arg_lead = cmdline:match("^['<,'>]*" .. rust_lsp_cmd_name .. '[!]*%s(%S+)%s(.*)$')
|
||||
if subcmd and subcmd_arg_lead and rustlsp_command_tbl[subcmd] and rustlsp_command_tbl[subcmd].complete then
|
||||
return rustlsp_command_tbl[subcmd].complete(subcmd_arg_lead)
|
||||
end
|
||||
if cmdline:match('^' .. rust_lsp_cmd_name .. '[!]*%s+%w*$') then
|
||||
if cmdline:match("^['<,'>]*" .. rust_lsp_cmd_name .. '[!]*%s+%w*$') then
|
||||
return vim.tbl_filter(function(command)
|
||||
return command:find(arg_lead) ~= nil
|
||||
end, commands)
|
||||
|
||||
@ -82,9 +82,9 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
|
||||
---@see vim.lsp.util.open_floating_preview.Opts
|
||||
---@see vim.api.nvim_open_win
|
||||
|
||||
---@alias executor_alias 'termopen' | 'quickfix' | 'toggleterm' | 'vimux' | 'neotest'
|
||||
---@alias executor_alias 'termopen' | 'quickfix' | 'toggleterm' | 'vimux'
|
||||
|
||||
---@alias test_executor_alias executor_alias | 'background'
|
||||
---@alias test_executor_alias executor_alias | 'background' | 'neotest'
|
||||
|
||||
---@class RustaceanHoverActionsOpts
|
||||
---@field replace_builtin_hover? boolean Whether to replace Neovim's built-in `vim.lsp.buf.hover` with hover actions. Default: `true`
|
||||
@ -115,6 +115,7 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
|
||||
---@field standalone? boolean Standalone file support (enabled by default). Disabling it may improve rust-analyzer's startup time.
|
||||
---@field logfile? string The path to the rust-analyzer log file.
|
||||
---@field load_vscode_settings? boolean Whether to search (upward from the buffer) for rust-analyzer settings in .vscode/settings json. If found, loaded settings will override configured options. Default: false
|
||||
---@see vim.lsp.ClientConfig
|
||||
|
||||
---@class RustaceanDapOpts
|
||||
--- @field autoload_configurations boolean Whether to autoload nvim-dap configurations when rust-analyzer has attached? Default: `true`.
|
||||
|
||||
@ -29,7 +29,6 @@ function server.load_rust_analyzer_settings(project_root, opts)
|
||||
then
|
||||
---@diagnostic disable-next-line: inject-field
|
||||
default_settings['rust-analyzer'].check = {
|
||||
allFeatures = true,
|
||||
command = 'clippy',
|
||||
extraArgs = { '--no-deps' },
|
||||
}
|
||||
@ -148,7 +147,7 @@ function server.create_client_capabilities()
|
||||
}
|
||||
end)
|
||||
return vim.tbl_deep_extend(
|
||||
'keep',
|
||||
'force',
|
||||
rs_capabilities,
|
||||
cmp_capabilities,
|
||||
selection_range_capabilities,
|
||||
|
||||
@ -188,7 +188,7 @@ local function add_dynamic_library_paths(adapter, workspace_root)
|
||||
if not workspace_root or environments[workspace_root] then
|
||||
return
|
||||
end
|
||||
compat.system({ 'rustc', '--print', 'target-libdir' }, nil, function(sc)
|
||||
compat.system({ 'rustc', '--print', 'target-libdir' }, { cwd = workspace_root }, function(sc)
|
||||
---@cast sc vim.SystemCompleted
|
||||
local result = sc.stdout
|
||||
if sc.code ~= 0 or result == nil then
|
||||
@ -202,7 +202,7 @@ local function add_dynamic_library_paths(adapter, workspace_root)
|
||||
elseif shell.is_macos() then
|
||||
---@diagnostic disable-next-line: missing-parameter
|
||||
environments[workspace_root] = environments[workspace_root]
|
||||
or format_environment_variable(adapter, 'DKLD_LIBRARY_PATH', { rustc_target_path, target_path }, ':')
|
||||
or format_environment_variable(adapter, 'DYLD_LIBRARY_PATH', { rustc_target_path, target_path }, ':')
|
||||
else
|
||||
---@diagnostic disable-next-line: missing-parameter
|
||||
environments[workspace_root] = environments[workspace_root]
|
||||
|
||||
@ -73,6 +73,27 @@ local function get_start_settings(bufname, root_dir, client_config)
|
||||
return evaluated_settings
|
||||
end
|
||||
|
||||
---HACK: Workaround for https://github.com/neovim/neovim/pull/28690
|
||||
--- to solve #423.
|
||||
--- Checks if Neovim's file watcher is enabled, and if it isn't,
|
||||
--- configures rust-analyzer to enable server-side file watching (if not configured otherwise).
|
||||
---
|
||||
---@param server_cfg LspStartConfig LSP start settings
|
||||
local function configure_file_watcher(server_cfg)
|
||||
local is_client_file_watcher_enabled =
|
||||
vim.tbl_get(server_cfg.capabilities, 'workspace', 'didChangeWatchedFiles', 'dynamicRegistration')
|
||||
local file_watcher_setting = vim.tbl_get(server_cfg.settings, 'rust-analyzer', 'files', 'watcher')
|
||||
if is_client_file_watcher_enabled and not file_watcher_setting then
|
||||
server_cfg.settings = vim.tbl_deep_extend('force', server_cfg.settings, {
|
||||
['rust-analyzer'] = {
|
||||
files = {
|
||||
watcher = 'server',
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
---@class LspStartConfig: RustaceanLspClientConfig
|
||||
---@field root_dir string | nil
|
||||
---@field init_options? table
|
||||
@ -105,6 +126,7 @@ M.start = function(bufnr)
|
||||
lsp_start_config.root_dir = root_dir
|
||||
|
||||
lsp_start_config.settings = get_start_settings(bufname, root_dir, client_config)
|
||||
configure_file_watcher(lsp_start_config)
|
||||
|
||||
-- Check if a client is already running and add the workspace folder if necessary.
|
||||
for _, client in pairs(rust_analyzer.get_active_rustaceanvim_clients()) do
|
||||
|
||||
Reference in New Issue
Block a user