Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LS: Hide errors from github sources only when they're not associated with a real project #2139

Merged
merged 1 commit into from
Feb 6, 2025
Merged
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
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
Loading