Skip to content

Commit 9c210a4

Browse files
bors[bot]matklad
andauthored
Merge #11151
11151: feat: correctly fallback to notify if the clinet-side file watching is not supported r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents b8a6321 + a1c33c2 commit 9c210a4

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,10 @@ impl Config {
723723
FilesConfig {
724724
watcher: match self.data.files_watcher.as_str() {
725725
"notify" => FilesWatcher::Notify,
726-
"client" | _ => FilesWatcher::Client,
726+
"client" if self.did_change_watched_files_dynamic_registration() => {
727+
FilesWatcher::Client
728+
}
729+
_ => FilesWatcher::Notify,
727730
},
728731
exclude: self.data.files_excludeDirs.iter().map(|it| self.root_path.join(it)).collect(),
729732
}

crates/rust-analyzer/src/reload.rs

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -241,38 +241,33 @@ impl GlobalState {
241241
}
242242

243243
if let FilesWatcher::Client = self.config.files().watcher {
244-
if self.config.did_change_watched_files_dynamic_registration() {
245-
let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions {
246-
watchers: self
247-
.workspaces
248-
.iter()
249-
.flat_map(|ws| ws.to_roots())
250-
.filter(|it| it.is_local)
251-
.flat_map(|root| {
252-
root.include.into_iter().flat_map(|it| {
253-
[
254-
format!("{}/**/*.rs", it.display()),
255-
format!("{}/**/Cargo.toml", it.display()),
256-
format!("{}/**/Cargo.lock", it.display()),
257-
]
258-
})
259-
})
260-
.map(|glob_pattern| lsp_types::FileSystemWatcher {
261-
glob_pattern,
262-
kind: None,
244+
let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions {
245+
watchers: self
246+
.workspaces
247+
.iter()
248+
.flat_map(|ws| ws.to_roots())
249+
.filter(|it| it.is_local)
250+
.flat_map(|root| {
251+
root.include.into_iter().flat_map(|it| {
252+
[
253+
format!("{}/**/*.rs", it.display()),
254+
format!("{}/**/Cargo.toml", it.display()),
255+
format!("{}/**/Cargo.lock", it.display()),
256+
]
263257
})
264-
.collect(),
265-
};
266-
let registration = lsp_types::Registration {
267-
id: "workspace/didChangeWatchedFiles".to_string(),
268-
method: "workspace/didChangeWatchedFiles".to_string(),
269-
register_options: Some(serde_json::to_value(registration_options).unwrap()),
270-
};
271-
self.send_request::<lsp_types::request::RegisterCapability>(
272-
lsp_types::RegistrationParams { registrations: vec![registration] },
273-
|_, _| (),
274-
);
275-
}
258+
})
259+
.map(|glob_pattern| lsp_types::FileSystemWatcher { glob_pattern, kind: None })
260+
.collect(),
261+
};
262+
let registration = lsp_types::Registration {
263+
id: "workspace/didChangeWatchedFiles".to_string(),
264+
method: "workspace/didChangeWatchedFiles".to_string(),
265+
register_options: Some(serde_json::to_value(registration_options).unwrap()),
266+
};
267+
self.send_request::<lsp_types::request::RegisterCapability>(
268+
lsp_types::RegistrationParams { registrations: vec![registration] },
269+
|_, _| (),
270+
);
276271
}
277272

278273
let mut change = Change::new();

crates/rust-analyzer/tests/slow-tests/support.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ impl<'a> Project<'a> {
101101
let mut config = Config::new(
102102
tmp_dir_path,
103103
lsp_types::ClientCapabilities {
104+
workspace: Some(lsp_types::WorkspaceClientCapabilities {
105+
did_change_watched_files: Some(
106+
lsp_types::DidChangeWatchedFilesClientCapabilities {
107+
dynamic_registration: Some(true),
108+
},
109+
),
110+
..Default::default()
111+
}),
104112
text_document: Some(lsp_types::TextDocumentClientCapabilities {
105113
definition: Some(lsp_types::GotoCapability {
106114
link_support: Some(true),

crates/rust-analyzer/tests/slow-tests/testdir.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ impl Drop for TestDir {
5252
if self.keep {
5353
return;
5454
}
55-
remove_dir_all(&self.path).unwrap()
55+
remove_dir_all(&self.path).unwrap_or_else(|err| {
56+
panic!("failed to remove temporary directory {}: {}", self.path.display(), err)
57+
})
5658
}
5759
}
5860

0 commit comments

Comments
 (0)