Skip to content

Commit

Permalink
feat(lsp): enable server-side file watching if client-side disabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Jun 16, 2024
1 parent ab61a8c commit 17f72a2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- LSP: If Neovim's file watcher is disabled, configure rust-analyzer
to enable server-side file watching, unless it has been configured
otherwise [[#423](https://github.com/mrcjkb/rustaceanvim/issues/423)].

### Fixed

- DAP: Dynamic library path setup using nightly rust builds
Expand Down
22 changes: 22 additions & 0 deletions lua/rustaceanvim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 17f72a2

Please sign in to comment.