Repository: rust-analyzer/rust-analyzer
Pull request #11151 (2022-01-01 14:27:28)

feat: correctly fallback to notify if the clinet-side file watching is not supported
bors r+
🤖


Patch:
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 867f2bd1f0..818aab3515 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -723,7 +723,10 @@ impl Config {
         FilesConfig {
             watcher: match self.data.files_watcher.as_str() {
                 "notify" => FilesWatcher::Notify,
-                "client" | _ => FilesWatcher::Client,
+                "client" if self.did_change_watched_files_dynamic_registration() => {
+                    FilesWatcher::Client
+                }
+                _ => FilesWatcher::Notify,
             },
             exclude: self.data.files_excludeDirs.iter().map(|it| self.root_path.join(it)).collect(),
         }
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 7ba5697176..b14b3dbcfa 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -241,38 +241,33 @@ impl GlobalState {
         }
 
         if let FilesWatcher::Client = self.config.files().watcher {
-            if self.config.did_change_watched_files_dynamic_registration() {
-                let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions {
-                    watchers: self
-                        .workspaces
-                        .iter()
-                        .flat_map(|ws| ws.to_roots())
-                        .filter(|it| it.is_local)
-                        .flat_map(|root| {
-                            root.include.into_iter().flat_map(|it| {
-                                [
-                                    format!("{}/**/*.rs", it.display()),
-                                    format!("{}/**/Cargo.toml", it.display()),
-                                    format!("{}/**/Cargo.lock", it.display()),
-                                ]
-                            })
-                        })
-                        .map(|glob_pattern| lsp_types::FileSystemWatcher {
-                            glob_pattern,
-                            kind: None,
+            let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions {
+                watchers: self
+                    .workspaces
+                    .iter()
+                    .flat_map(|ws| ws.to_roots())
+                    .filter(|it| it.is_local)
+                    .flat_map(|root| {
+                        root.include.into_iter().flat_map(|it| {
+                            [
+                                format!("{}/**/*.rs", it.display()),
+                                format!("{}/**/Cargo.toml", it.display()),
+                                format!("{}/**/Cargo.lock", it.display()),
+                            ]
                         })
-                        .collect(),
-                };
-                let registration = lsp_types::Registration {
-                    id: "workspace/didChangeWatchedFiles".to_string(),
-                    method: "workspace/didChangeWatchedFiles".to_string(),
-                    register_options: Some(serde_json::to_value(registration_options).unwrap()),
-                };
-                self.send_request::<lsp_types::request::RegisterCapability>(
-                    lsp_types::RegistrationParams { registrations: vec![registration] },
-                    |_, _| (),
-                );
-            }
+                    })
+                    .map(|glob_pattern| lsp_types::FileSystemWatcher { glob_pattern, kind: None })
+                    .collect(),
+            };
+            let registration = lsp_types::Registration {
+                id: "workspace/didChangeWatchedFiles".to_string(),
+                method: "workspace/didChangeWatchedFiles".to_string(),
+                register_options: Some(serde_json::to_value(registration_options).unwrap()),
+            };
+            self.send_request::<lsp_types::request::RegisterCapability>(
+                lsp_types::RegistrationParams { registrations: vec![registration] },
+                |_, _| (),
+            );
         }
 
         let mut change = Change::new();


Test patch:
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs
index 517dfb15b6..b93072d446 100644
--- a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs
+++ b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs
@@ -103,22 +103,3 @@ stringify!(;
 "#]],
     );
 }
-
-#[test]
-fn range_patterns() {
-    // FIXME: rustc thinks there are three patterns here, not one.
-    check(
-        r#"
-macro_rules! m {
-    ($($p:pat)*) => (stringify!($($p |)*);)
-}
-m!(.. .. ..);
-"#,
-        expect![[r#"
-macro_rules! m {
-    ($($p:pat)*) => (stringify!($($p |)*);)
-}
-stringify!(.. .. ..|);
-"#]],
-    );
-}
diff --git a/crates/parser/src/tests/entries.rs b/crates/parser/src/tests/entries.rs
index 1174e33f5f..947922d8b3 100644
--- a/crates/parser/src/tests/entries.rs
+++ b/crates/parser/src/tests/entries.rs
@@ -21,48 +21,12 @@ fn stmt() {
     check_prefix(PrefixEntryPoint::Stmt, "92; fn", "92");
     check_prefix(PrefixEntryPoint::Stmt, "let _ = 92; 1", "let _ = 92");
     check_prefix(PrefixEntryPoint::Stmt, "pub fn f() {} = 92", "pub fn f() {}");
-    check_prefix(PrefixEntryPoint::Stmt, "struct S;;", "struct S;");
-    check_prefix(PrefixEntryPoint::Stmt, "fn f() {};", "fn f() {}");
     check_prefix(PrefixEntryPoint::Stmt, ";;;", ";");
     check_prefix(PrefixEntryPoint::Stmt, "+", "+");
     check_prefix(PrefixEntryPoint::Stmt, "@", "@");
     check_prefix(PrefixEntryPoint::Stmt, "loop {} - 1", "loop {}");
 }
 
-#[test]
-fn pat() {
-    check_prefix(PrefixEntryPoint::Pat, "x y", "x");
-    check_prefix(PrefixEntryPoint::Pat, "fn f() {}", "fn");
-    // FIXME: This one is wrong, we should consume only one pattern.
-    check_prefix(PrefixEntryPoint::Pat, ".. ..", ".. ..");
-}
-
-#[test]
-fn ty() {
-    check_prefix(PrefixEntryPoint::Ty, "fn() foo", "fn()");
-    check_prefix(PrefixEntryPoint::Ty, "Clone + Copy + fn", "Clone + Copy +");
-    check_prefix(PrefixEntryPoint::Ty, "struct f", "struct");
-}
-
-#[test]
-fn expr() {
-    check_prefix(PrefixEntryPoint::Expr, "92 92", "92");
-    check_prefix(PrefixEntryPoint::Expr, "+1", "+");
-    check_prefix(PrefixEntryPoint::Expr, "-1", "-1");
-    check_prefix(PrefixEntryPoint::Expr, "fn foo() {}", "fn");
-    check_prefix(PrefixEntryPoint::Expr, "#[attr] ()", "#[attr] ()");
-}
-
-#[test]
-fn path() {
-    check_prefix(PrefixEntryPoint::Path, "foo::bar baz", "foo::bar");
-    check_prefix(PrefixEntryPoint::Path, "foo::<> baz", "foo::<>");
-    check_prefix(PrefixEntryPoint::Path, "foo<> baz", "foo<>");
-    check_prefix(PrefixEntryPoint::Path, "Fn() -> i32?", "Fn() -> i32");
-    // FIXME: this shouldn't be accepted as path actually.
-    check_prefix(PrefixEntryPoint::Path, "<_>::foo", "<_>::foo");
-}
-
 fn check_prefix(entry: PrefixEntryPoint, input: &str, prefix: &str) {
     let lexed = LexedStr::new(input);
     let input = lexed.to_input();
diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs
index a8c2a5bb61..6e7ecec5b2 100644
--- a/crates/rust-analyzer/tests/slow-tests/support.rs
+++ b/crates/rust-analyzer/tests/slow-tests/support.rs
@@ -101,6 +101,14 @@ impl<'a> Project<'a> {
         let mut config = Config::new(
             tmp_dir_path,
             lsp_types::ClientCapabilities {
+                workspace: Some(lsp_types::WorkspaceClientCapabilities {
+                    did_change_watched_files: Some(
+                        lsp_types::DidChangeWatchedFilesClientCapabilities {
+                            dynamic_registration: Some(true),
+                        },
+                    ),
+                    ..Default::default()
+                }),
                 text_document: Some(lsp_types::TextDocumentClientCapabilities {
                     definition: Some(lsp_types::GotoCapability {
                         link_support: Some(true),
diff --git a/crates/rust-analyzer/tests/slow-tests/testdir.rs b/crates/rust-analyzer/tests/slow-tests/testdir.rs
index c7e5c21806..3bec23a911 100644
--- a/crates/rust-analyzer/tests/slow-tests/testdir.rs
+++ b/crates/rust-analyzer/tests/slow-tests/testdir.rs
@@ -52,7 +52,9 @@ impl Drop for TestDir {
         if self.keep {
             return;
         }
-        remove_dir_all(&self.path).unwrap()
+        remove_dir_all(&self.path).unwrap_or_else(|err| {
+            panic!("failed to remove temporary directory {}: {}", self.path.display(), err)
+        })
     }
 }