Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/flycheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ impl JsonLinesParser<CheckMessage> for CheckParser {
}
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
#[serde(untagged)]
enum JsonMessage {
Cargo(cargo_metadata::Message),
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/handlers/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub(crate) fn handle_did_change_watched_files(
if let Ok(path) = from_proto::abs_path(&change.uri) {
if !trigger_flycheck {
trigger_flycheck =
state.config.workspace_roots().iter().any(|root| !path.starts_with(root));
state.config.workspace_roots().iter().all(|root| !path.starts_with(root));
}
state.loader.handle.invalidate(path);
}
Expand Down
47 changes: 47 additions & 0 deletions crates/rust-analyzer/tests/slow-tests/flycheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,50 @@ fn main() {}
diagnostics.diagnostics,
);
}

#[cfg(unix)] // We're using sh -c in this test, so skip windows.
#[test]
fn test_flycheck_multiple_workspaces() {
if skip_slow_tests() {
return;
}

let server = Project::with_fixture(
r#"
//- /ws1/Cargo.toml
[package]
name = "foo"
version = "0.0.0"

//- /ws1/src/main.rs
fn main() {}

//- /ws2/Cargo.toml
[package]
name = "bar"
version = "0.0.0"

//- /ws2/src/main.rs
fn main() {}
"#,
)
.root("ws1")
.root("ws2")
.with_config(serde_json::json!({
"checkOnSave": true,
"check": {
"overrideCommand": ["sh", "-c", "sleep 1 && rustc --error-format=json {saved_file}"],
}
}))
.server()
.wait_until_workspace_is_loaded();

server.write_file_and_save("ws1/src/main.rs", "fn main() {\n let x = 1;\n}\n".to_owned());

let diag1 = server.wait_for_diagnostics();
assert!(
diag1.diagnostics.iter().any(|d| d.message.contains("unused variable")),
"expected unused variable diagnostic from ws1, got: {:?}",
diag1.diagnostics,
);
}
17 changes: 16 additions & 1 deletion crates/rust-analyzer/tests/slow-tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,22 @@ impl Server {
text_document: self.doc_id(path),
text: Some(text),
},
)
);

// In a real LSP session, we receive DidChangeWatchedFiles
// shortly after DidSave, but there is a non-zero amount of
// time between the notifications. Add a brief sleep so we can
// start handling the DidSave event, mimicking a real session.
std::thread::sleep(std::time::Duration::from_millis(500));

self.notification::<lsp_types::notification::DidChangeWatchedFiles>(
lsp_types::DidChangeWatchedFilesParams {
changes: vec![lsp_types::FileEvent {
uri: self.doc_id(path).uri,
typ: lsp_types::FileChangeType::CHANGED,
}],
},
);
}
}

Expand Down
Loading