Skip to content

Commit

Permalink
Avoid errors in read-only GitHub sources (#1787)
Browse files Browse the repository at this point in the history
This is an incremental improvement for viewing GitHub sources that
avoids treating them as open documents since they are read-only buffers.
In the future, we can do the work to associate them with the existing
compilation taht contains those sources so that things like hover and
goto-def work, but for now those code paths are user-code specific and
need some reworking to handle navigation in a compile unit for a
dependency.
  • Loading branch information
swernli authored Jul 27, 2024
1 parent 58ffcb7 commit 2a42bd0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/qsc_project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ pub use manifest::{Manifest, ManifestDescriptor, PackageRef, PackageType, MANIFE
pub use project::FileSystemAsync;
pub use project::{
key_for_package_ref, package_ref_from_key, DependencyCycle, DirEntry, EntryType, Error,
FileSystem, PackageCache, PackageGraphSources, PackageInfo, Project,
FileSystem, PackageCache, PackageGraphSources, PackageInfo, Project, GITHUB_SCHEME,
};
6 changes: 4 additions & 2 deletions compiler/qsc_project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use std::{
};
use thiserror::Error;

pub const GITHUB_SCHEME: &str = "qsharp-github-source";

/// Describes a Q# project with all its sources and dependencies resolved.
#[derive(Debug, Clone)]
pub struct Project {
Expand Down Expand Up @@ -414,7 +416,7 @@ pub trait FileSystemAsync {
let manifest = serde_json::from_str::<Manifest>(&manifest_content).map_err(|e| {
Error::GitHubManifestParse {
path: format!(
"qsharp-github-source:{}/{}/{}{}/qsharp.json",
"{GITHUB_SCHEME}:{}/{}/{}{}/qsharp.json",
dep.owner,
dep.repo,
dep.r#ref,
Expand Down Expand Up @@ -448,7 +450,7 @@ pub trait FileSystemAsync {
// and open them using cached contents.
sources.push((
format!(
"qsharp-github-source:{}/{}/{}{path}",
"{GITHUB_SCHEME}:{}/{}/{}{path}",
dep.owner, dep.repo, dep.r#ref
)
.into(),
Expand Down
6 changes: 6 additions & 0 deletions language_service/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@ 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

0 comments on commit 2a42bd0

Please sign in to comment.