From a3a8ad8bc45d87607493d3c07d7e89e54f7b8c11 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Oct 2020 17:38:21 +0200 Subject: Don't rely on display names in inlay_hints --- crates/assists/src/utils.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'crates/assists/src/utils.rs') diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 4e89a7aed..1a6b48b45 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs @@ -275,7 +275,7 @@ impl TryEnum { /// somewhat similar to the known paths infra inside hir, but it different; We /// want to make sure that IDE specific paths don't become interesting inside /// the compiler itself as well. -pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Crate); +pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Option); #[allow(non_snake_case)] impl FamousDefs<'_, '_> { @@ -362,6 +362,10 @@ pub mod prelude { pub use prelude::*; "#; + pub fn core(&self) -> Option { + self.find_crate("core") + } + pub(crate) fn core_convert_From(&self) -> Option { self.find_trait("core:convert:From") } @@ -399,21 +403,20 @@ pub use prelude::*; } } + fn find_crate(&self, name: &str) -> Option { + let krate = self.1?; + let db = self.0.db; + let res = + krate.dependencies(db).into_iter().find(|dep| dep.name.to_string() == name)?.krate; + Some(res) + } + fn find_def(&self, path: &str) -> Option { let db = self.0.db; let mut path = path.split(':'); let trait_ = path.next_back()?; let std_crate = path.next()?; - let std_crate = if self - .1 - .display_name(db) - .map(|name| name.to_string() == std_crate) - .unwrap_or(false) - { - self.1 - } else { - self.1.dependencies(db).into_iter().find(|dep| dep.name.to_string() == std_crate)?.krate - }; + let std_crate = self.find_crate(std_crate)?; let mut module = std_crate.root_module(db); for segment in path { module = module.children(db).find_map(|child| { -- cgit v1.2.3