Skip to content

Commit

Permalink
LS: Hide errors from github sources only when they're not associated …
Browse files Browse the repository at this point in the history
…with a real project (#2139)

Small fix to #1787 while staying true to the intention of that change.

We want to _hide_ errors from GitHub sources that are open in the
editor, but aren't associated with a project. They're essentially
orphans. For example, you may have closed the original project that
referenced those GitHub sources, but left the GitHub source open in the
editor.

But we want to _show_ errors from GitHub sources if they're part of a
normal project. Errors from dependencies are helpful.
  • Loading branch information
minestarks authored Feb 6, 2025
1 parent 4b74d68 commit cf1cff1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
16 changes: 10 additions & 6 deletions language_service/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
51 changes: 51 additions & 0 deletions language_service/src/state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit cf1cff1

Please sign in to comment.