Skip to content

Commit

Permalink
Clear diagnostics with package id instead of crate name
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Lavergne committed Oct 29, 2024
1 parent 0e5b9c8 commit d0a5683
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 15 deletions.
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>,
/// 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 @@ -352,6 +353,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 @@ -363,6 +365,7 @@ impl CrateGraph {
root_file_id,
edition,
version,
package_id,
display_name,
cfg_options,
potential_cfg_options,
Expand Down Expand Up @@ -708,6 +711,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -719,6 +723,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -730,6 +735,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -755,6 +761,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -766,6 +773,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -788,6 +796,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -799,6 +808,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -810,6 +820,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -832,6 +843,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand All @@ -843,6 +855,7 @@ mod tests {
Edition2018,
None,
None,
None,
Default::default(),
Default::default(),
Env::default(),
Expand Down
13 changes: 4 additions & 9 deletions crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl Analysis {
Edition::CURRENT,
None,
None,
None,
Arc::new(cfg_options),
None,
Env::default(),
Expand Down Expand Up @@ -588,19 +589,13 @@ impl Analysis {
self.with_db(|db| db.crate_def_map(crate_id).files().collect())
}

/// Returns the crate with the given name
pub fn crate_with_name(&self, crate_name: &str) -> Cancellable<Option<CrateId>> {
/// 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];
match &crate_data.origin {
CrateOrigin::Local { name: Some(name), .. } if name.as_str() == crate_name => {
true
}
CrateOrigin::Library { name, .. } if name.as_str() == crate_name => true,
_ => false,
}
crate_data.package_id.as_deref() == Some(package_id)
});
id
})
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 @@ -1525,6 +1528,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 @@ -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
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
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 @@ -68,6 +71,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 @@ -137,6 +143,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 @@ -206,6 +215,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 @@ -275,6 +287,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

0 comments on commit d0a5683

Please sign in to comment.