From 256e36de35f0204d56db56463d18c439846783bc Mon Sep 17 00:00:00 2001 From: Mine Starks <16928427+minestarks@users.noreply.github.com> Date: Fri, 31 Jan 2025 01:58:09 +0000 Subject: [PATCH] Hide errors from github sources only when they're not associated with a real project --- language_service/src/state.rs | 16 +++++---- language_service/src/state/tests.rs | 51 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/language_service/src/state.rs b/language_service/src/state.rs index 00a726fe53..89fbc6c3c0 100644 --- a/language_service/src/state.rs +++ b/language_service/src/state.rs @@ -417,6 +417,16 @@ impl<'a> CompilationStateUpdater<'a> { for (compilation_uri, compilation) in &state.compilations { trace!("publishing diagnostics for {compilation_uri}"); + if compilation_uri.starts_with(qsc_project::GITHUB_SCHEME) { + // If the compilation URI is a GitHub virtual document URI, + // that's a signal that this is a source file from a GitHub package + // that is open in the editor. + // We can't discover the manifest and load the project for these files. + // So they end up in their own single-file compilation. + // Don't publish diagnostics for these, as they will contain spurious errors. + continue; + } + for (uri, errors) in map_errors_to_docs( compilation_uri, &compilation.0.compile_errors, @@ -430,12 +440,6 @@ impl<'a> CompilationStateUpdater<'a> { // a less confusing user experience. continue; } - if uri.starts_with(qsc_project::GITHUB_SCHEME) { - // Don't publish diagnostics for GitHub URIs. - // This is temporary workaround to avoid spurious errors when a document - // is opened in single file mode that is part of a read-only GitHub project. - continue; - } self.publish_diagnostics_for_doc(state, &uri, errors); } diff --git a/language_service/src/state/tests.rs b/language_service/src/state/tests.rs index 9e5d7a4a45..13b83eeb5b 100644 --- a/language_service/src/state/tests.rs +++ b/language_service/src/state/tests.rs @@ -1591,6 +1591,57 @@ async fn error_from_dependency_reported() { ); } +#[tokio::test] +async fn single_github_source_no_errors() { + let received_errors = RefCell::new(Vec::new()); + let test_cases = RefCell::new(Vec::new()); + let mut updater = new_updater(&received_errors, &test_cases); + + updater + .update_document("qsharp-github-source:foo/bar/Main.qs", 1, "badsyntax") + .await; + + updater + .update_document("/foo/bar/Main.qs", 1, "badsyntax") + .await; + + // Same error exists in both files, but the github one should not be reported + + check_state_and_errors( + &updater, + &received_errors, + &expect![[r#" + { + "qsharp-github-source:foo/bar/Main.qs": OpenDocument { + version: 1, + compilation: "qsharp-github-source:foo/bar/Main.qs", + latest_str_content: "badsyntax", + }, + "/foo/bar/Main.qs": OpenDocument { + version: 1, + compilation: "/foo/bar/Main.qs", + latest_str_content: "badsyntax", + }, + } + "#]], + &expect![[r#" + qsharp-github-source:foo/bar/Main.qs: [ + "qsharp-github-source:foo/bar/Main.qs": "badsyntax", + ], + /foo/bar/Main.qs: [ + "/foo/bar/Main.qs": "badsyntax", + ], + "#]], + &expect![[r#" + [ + uri: "/foo/bar/Main.qs" version: Some(1) errors: [ + syntax error + [/foo/bar/Main.qs] [badsyntax] + ], + ]"#]], + ); +} + #[tokio::test] async fn test_case_detected() { let fs = FsNode::Dir(