Skip to content

Granular handling for flycheck diagnostics #18332

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

Closed
Closed
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
13 changes: 13 additions & 0 deletions crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ pub struct CrateData {
pub root_file_id: FileId,
pub edition: Edition,
pub version: Option<String>,
pub package_id: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CrateData is agnostic to cargo packages so we shouldn't store this here (and we shouldn't have to either way)

/// A name used in the package's project declaration: for Cargo projects,
/// its `[package].name` can be different for other project types or even
/// absent (a dummy crate for the code snippet, for example).
Expand Down Expand Up @@ -357,6 +358,7 @@ impl CrateGraph {
edition: Edition,
display_name: Option<CrateDisplayName>,
version: Option<String>,
package_id: Option<String>,
cfg_options: Arc<CfgOptions>,
potential_cfg_options: Option<Arc<CfgOptions>>,
mut env: Env,
Expand All @@ -368,6 +370,7 @@ impl CrateGraph {
root_file_id,
edition,
version,
package_id,
display_name,
cfg_options,
potential_cfg_options,
Expand Down Expand Up @@ -690,6 +693,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -701,6 +705,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -712,6 +717,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -737,6 +743,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -748,6 +755,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -770,6 +778,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -781,6 +790,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -792,6 +802,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -814,6 +825,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -825,6 +837,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand Down
7 changes: 7 additions & 0 deletions crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ impl DefMap {
.map(|(id, _data)| id)
}

pub fn files(&self) -> impl Iterator<Item = FileId> + '_ {
self.modules
.iter()
.filter_map(|(_id, data)| data.origin.file_id())
.map(EditionedFileId::file_id)
}

pub fn modules(&self) -> impl Iterator<Item = (LocalModuleId, &ModuleData)> + '_ {
self.modules.iter()
}
Expand Down
20 changes: 19 additions & 1 deletion crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use std::{iter, panic::UnwindSafe};

use cfg::CfgOptions;
use fetch_crates::CrateInfo;
use hir::{sym, ChangeWithProcMacros};
use hir::{db::DefDatabase, sym, ChangeWithProcMacros};
use ide_db::{
base_db::{
ra_salsa::{self, ParallelDatabase},
Expand Down Expand Up @@ -248,6 +248,7 @@ impl Analysis {
Edition::CURRENT,
None,
None,
None,
Arc::new(cfg_options),
None,
Env::default(),
Expand Down Expand Up @@ -593,6 +594,23 @@ impl Analysis {
self.with_db(|db| parent_module::crates_for(db, file_id))
}

/// Returns files that belong to this crate
pub fn files_for(&self, crate_id: CrateId) -> Cancellable<Vec<FileId>> {
self.with_db(|db| db.crate_def_map(crate_id).files().collect())
}

/// Returns the crate with the given package id
pub fn crate_with_id(&self, package_id: &str) -> Cancellable<Option<CrateId>> {
self.with_db(|db| {
let graph = db.crate_graph();
let id = graph.iter().find(|id| {
let crate_data = &graph[*id];
crate_data.package_id.as_deref() == Some(package_id)
});
id
})
}

/// Returns crates this file belongs too.
pub fn transitive_rev_deps(&self, crate_id: CrateId) -> Cancellable<Vec<CrateId>> {
self.with_db(|db| db.crate_graph().transitive_rev_deps(crate_id).collect())
Expand Down
2 changes: 2 additions & 0 deletions crates/ide/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
root_file_id,
edition,
version,
package_id,
display_name,
cfg_options,
potential_cfg_options,
Expand All @@ -81,6 +82,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
format_to!(buf, " Root module file id: {}\n", root_file_id.index());
format_to!(buf, " Edition: {}\n", edition);
format_to!(buf, " Version: {}\n", version.as_deref().unwrap_or("n/a"));
format_to!(buf, " Package Id: {}\n", package_id.as_deref().unwrap_or("n/a"));
format_to!(buf, " Enabled cfgs: {:?}\n", cfg_options);
format_to!(buf, " Potential cfgs: {:?}\n", potential_cfg_options);
format_to!(buf, " Env: {:?}\n", env);
Expand Down
4 changes: 4 additions & 0 deletions crates/project-model/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ fn project_json_to_crate_graph(
*edition,
display_name.clone(),
version.clone(),
None,
Arc::new(cfg_options),
None,
env,
Expand Down Expand Up @@ -1222,6 +1223,7 @@ fn detached_file_to_crate_graph(
Edition::CURRENT,
display_name.clone(),
None,
None,
cfg_options.clone(),
None,
Env::default(),
Expand Down Expand Up @@ -1389,6 +1391,7 @@ fn add_target_crate_root(
edition,
Some(CrateDisplayName::from_canonical_name(cargo_name)),
Some(pkg.version.to_string()),
Some(pkg.id.to_string()),
Arc::new(cfg_options),
potential_cfg_options.map(Arc::new),
env,
Expand Down Expand Up @@ -1528,6 +1531,7 @@ fn sysroot_to_crate_graph(
Edition::CURRENT_FIXME,
Some(display_name),
None,
None,
cfg_options.clone(),
None,
Env::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -70,6 +73,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -141,6 +147,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -212,6 +221,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -283,6 +295,9 @@
version: Some(
"0.2.98",
),
package_id: Some(
"libc 0.2.98 (registry+https://github.com/rust-lang/crates.io-index)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -70,6 +73,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -141,6 +147,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -212,6 +221,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -283,6 +295,9 @@
version: Some(
"0.2.98",
),
package_id: Some(
"libc 0.2.98 (registry+https://github.com/rust-lang/crates.io-index)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -69,6 +72,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -139,6 +145,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -209,6 +218,9 @@
version: Some(
"0.1.0",
),
package_id: Some(
"hello-world 0.1.0 (path+file://$ROOT$hello-world)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down Expand Up @@ -279,6 +291,9 @@
version: Some(
"0.2.98",
),
package_id: Some(
"libc 0.2.98 (registry+https://github.com/rust-lang/crates.io-index)",
),
display_name: Some(
CrateDisplayName {
crate_name: CrateName(
Expand Down
Loading
Loading