Skip to content

Commit cf1cff1

Browse files
authored
LS: Hide errors from github sources only when they're not associated 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.
1 parent 4b74d68 commit cf1cff1

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

language_service/src/state.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ impl<'a> CompilationStateUpdater<'a> {
417417
for (compilation_uri, compilation) in &state.compilations {
418418
trace!("publishing diagnostics for {compilation_uri}");
419419

420+
if compilation_uri.starts_with(qsc_project::GITHUB_SCHEME) {
421+
// If the compilation URI is a GitHub virtual document URI,
422+
// that's a signal that this is a source file from a GitHub package
423+
// that is open in the editor.
424+
// We can't discover the manifest and load the project for these files.
425+
// So they end up in their own single-file compilation.
426+
// Don't publish diagnostics for these, as they will contain spurious errors.
427+
continue;
428+
}
429+
420430
for (uri, errors) in map_errors_to_docs(
421431
compilation_uri,
422432
&compilation.0.compile_errors,
@@ -430,12 +440,6 @@ impl<'a> CompilationStateUpdater<'a> {
430440
// a less confusing user experience.
431441
continue;
432442
}
433-
if uri.starts_with(qsc_project::GITHUB_SCHEME) {
434-
// Don't publish diagnostics for GitHub URIs.
435-
// This is temporary workaround to avoid spurious errors when a document
436-
// is opened in single file mode that is part of a read-only GitHub project.
437-
continue;
438-
}
439443

440444
self.publish_diagnostics_for_doc(state, &uri, errors);
441445
}

language_service/src/state/tests.rs

+51
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,57 @@ async fn error_from_dependency_reported() {
15911591
);
15921592
}
15931593

1594+
#[tokio::test]
1595+
async fn single_github_source_no_errors() {
1596+
let received_errors = RefCell::new(Vec::new());
1597+
let test_cases = RefCell::new(Vec::new());
1598+
let mut updater = new_updater(&received_errors, &test_cases);
1599+
1600+
updater
1601+
.update_document("qsharp-github-source:foo/bar/Main.qs", 1, "badsyntax")
1602+
.await;
1603+
1604+
updater
1605+
.update_document("/foo/bar/Main.qs", 1, "badsyntax")
1606+
.await;
1607+
1608+
// Same error exists in both files, but the github one should not be reported
1609+
1610+
check_state_and_errors(
1611+
&updater,
1612+
&received_errors,
1613+
&expect![[r#"
1614+
{
1615+
"qsharp-github-source:foo/bar/Main.qs": OpenDocument {
1616+
version: 1,
1617+
compilation: "qsharp-github-source:foo/bar/Main.qs",
1618+
latest_str_content: "badsyntax",
1619+
},
1620+
"/foo/bar/Main.qs": OpenDocument {
1621+
version: 1,
1622+
compilation: "/foo/bar/Main.qs",
1623+
latest_str_content: "badsyntax",
1624+
},
1625+
}
1626+
"#]],
1627+
&expect![[r#"
1628+
qsharp-github-source:foo/bar/Main.qs: [
1629+
"qsharp-github-source:foo/bar/Main.qs": "badsyntax",
1630+
],
1631+
/foo/bar/Main.qs: [
1632+
"/foo/bar/Main.qs": "badsyntax",
1633+
],
1634+
"#]],
1635+
&expect![[r#"
1636+
[
1637+
uri: "/foo/bar/Main.qs" version: Some(1) errors: [
1638+
syntax error
1639+
[/foo/bar/Main.qs] [badsyntax]
1640+
],
1641+
]"#]],
1642+
);
1643+
}
1644+
15941645
#[tokio::test]
15951646
async fn test_case_detected() {
15961647
let fs = FsNode::Dir(

0 commit comments

Comments
 (0)