diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-20 16:09:51 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-20 16:09:51 +0100 |
commit | 1c24f57ef8420e924e904ec481e7c6471f3ddcc8 (patch) | |
tree | c7f1ebcc5979838d1747cf19dd562004916a7274 /crates/ide/src | |
parent | be762ccccd5a86632e60351518528d078785a3e2 (diff) | |
parent | 3b1a648539487c08bc613b6fd6e573b0e0e38948 (diff) |
Merge #6295
6295: More type safety around names r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/doc_links.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 7 | ||||
-rw-r--r-- | crates/ide/src/prime_caches.rs | 3 | ||||
-rw-r--r-- | crates/ide/src/status.rs | 2 |
5 files changed, 10 insertions, 12 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index d9dc63b33..b9d8b8a2b 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs | |||
@@ -130,7 +130,7 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { | |||
130 | let module = definition.module(db)?; | 130 | let module = definition.module(db)?; |
131 | let krate = module.krate(); | 131 | let krate = module.krate(); |
132 | let import_map = db.import_map(krate.into()); | 132 | let import_map = db.import_map(krate.into()); |
133 | let base = once(krate.declaration_name(db)?.to_string()) | 133 | let base = once(krate.display_name(db)?.to_string()) |
134 | .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) | 134 | .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) |
135 | .join("/"); | 135 | .join("/"); |
136 | 136 | ||
@@ -188,7 +188,7 @@ fn rewrite_intra_doc_link( | |||
188 | let krate = resolved.module(db)?.krate(); | 188 | let krate = resolved.module(db)?.krate(); |
189 | let canonical_path = resolved.canonical_path(db)?; | 189 | let canonical_path = resolved.canonical_path(db)?; |
190 | let new_target = get_doc_url(db, &krate)? | 190 | let new_target = get_doc_url(db, &krate)? |
191 | .join(&format!("{}/", krate.declaration_name(db)?)) | 191 | .join(&format!("{}/", krate.display_name(db)?)) |
192 | .ok()? | 192 | .ok()? |
193 | .join(&canonical_path.replace("::", "/")) | 193 | .join(&canonical_path.replace("::", "/")) |
194 | .ok()? | 194 | .ok()? |
@@ -208,7 +208,7 @@ fn rewrite_url_link(db: &RootDatabase, def: ModuleDef, target: &str) -> Option<S | |||
208 | let module = def.module(db)?; | 208 | let module = def.module(db)?; |
209 | let krate = module.krate(); | 209 | let krate = module.krate(); |
210 | let canonical_path = def.canonical_path(db)?; | 210 | let canonical_path = def.canonical_path(db)?; |
211 | let base = format!("{}/{}", krate.declaration_name(db)?, canonical_path.replace("::", "/")); | 211 | let base = format!("{}/{}", krate.display_name(db)?, canonical_path.replace("::", "/")); |
212 | 212 | ||
213 | get_doc_url(db, &krate) | 213 | get_doc_url(db, &krate) |
214 | .and_then(|url| url.join(&base).ok()) | 214 | .and_then(|url| url.join(&base).ok()) |
@@ -357,7 +357,7 @@ fn get_doc_url(db: &RootDatabase, krate: &Crate) -> Option<Url> { | |||
357 | // | 357 | // |
358 | // FIXME: clicking on the link should just open the file in the editor, | 358 | // FIXME: clicking on the link should just open the file in the editor, |
359 | // instead of falling back to external urls. | 359 | // instead of falling back to external urls. |
360 | Some(format!("https://docs.rs/{}/*/", krate.declaration_name(db)?)) | 360 | Some(format!("https://docs.rs/{}/*/", krate.display_name(db)?)) |
361 | }) | 361 | }) |
362 | .and_then(|s| Url::parse(&s).ok()) | 362 | .and_then(|s| Url::parse(&s).ok()) |
363 | } | 363 | } |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 845333e2a..6466422c5 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -300,7 +300,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> | |||
300 | 300 | ||
301 | fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String { | 301 | fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String { |
302 | let crate_name = | 302 | let crate_name = |
303 | db.crate_graph()[module.krate().into()].declaration_name.as_ref().map(ToString::to_string); | 303 | db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string()); |
304 | let module_path = module | 304 | let module_path = module |
305 | .path_to_root(db) | 305 | .path_to_root(db) |
306 | .into_iter() | 306 | .into_iter() |
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index e2079bbcf..56b985e80 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -1,15 +1,14 @@ | |||
1 | use assists::utils::FamousDefs; | 1 | use assists::utils::FamousDefs; |
2 | use either::Either; | ||
2 | use hir::{known, HirDisplay, Semantics}; | 3 | use hir::{known, HirDisplay, Semantics}; |
3 | use ide_db::RootDatabase; | 4 | use ide_db::RootDatabase; |
4 | use stdx::to_lower_snake_case; | 5 | use stdx::to_lower_snake_case; |
5 | use syntax::{ | 6 | use syntax::{ |
6 | ast::{self, ArgListOwner, AstNode}, | 7 | ast::{self, ArgListOwner, AstNode, NameOwner}, |
7 | match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T, | 8 | match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T, |
8 | }; | 9 | }; |
9 | 10 | ||
10 | use crate::FileId; | 11 | use crate::FileId; |
11 | use ast::NameOwner; | ||
12 | use either::Either; | ||
13 | 12 | ||
14 | #[derive(Clone, Debug, PartialEq, Eq)] | 13 | #[derive(Clone, Debug, PartialEq, Eq)] |
15 | pub struct InlayHintsConfig { | 14 | pub struct InlayHintsConfig { |
@@ -215,7 +214,7 @@ fn hint_iterator( | |||
215 | .last() | 214 | .last() |
216 | .and_then(|strukt| strukt.as_adt())?; | 215 | .and_then(|strukt| strukt.as_adt())?; |
217 | let krate = strukt.krate(db)?; | 216 | let krate = strukt.krate(db)?; |
218 | if krate.declaration_name(db).as_deref() != Some("core") { | 217 | if krate.display_name(db).as_deref() != Some("core") { |
219 | return None; | 218 | return None; |
220 | } | 219 | } |
221 | let iter_trait = FamousDefs(sema, krate).core_iter_Iterator()?; | 220 | let iter_trait = FamousDefs(sema, krate).core_iter_Iterator()?; |
diff --git a/crates/ide/src/prime_caches.rs b/crates/ide/src/prime_caches.rs index 9687c2734..6944dbcd2 100644 --- a/crates/ide/src/prime_caches.rs +++ b/crates/ide/src/prime_caches.rs | |||
@@ -32,8 +32,7 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress) | |||
32 | // Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks | 32 | // Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks |
33 | // cancellation, so we cannot use rayon. | 33 | // cancellation, so we cannot use rayon. |
34 | for (i, krate) in topo.iter().enumerate() { | 34 | for (i, krate) in topo.iter().enumerate() { |
35 | let crate_name = | 35 | let crate_name = graph[*krate].display_name.as_deref().unwrap_or_default().to_string(); |
36 | graph[*krate].declaration_name.as_ref().map(ToString::to_string).unwrap_or_default(); | ||
37 | 36 | ||
38 | cb(PrimeCachesProgress::StartedOnCrate { | 37 | cb(PrimeCachesProgress::StartedOnCrate { |
39 | on_crate: crate_name, | 38 | on_crate: crate_name, |
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs index f67f10491..0af84daa0 100644 --- a/crates/ide/src/status.rs +++ b/crates/ide/src/status.rs | |||
@@ -45,7 +45,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String { | |||
45 | match krate { | 45 | match krate { |
46 | Some(krate) => { | 46 | Some(krate) => { |
47 | let crate_graph = db.crate_graph(); | 47 | let crate_graph = db.crate_graph(); |
48 | let display_crate = |krate: CrateId| match &crate_graph[krate].declaration_name { | 48 | let display_crate = |krate: CrateId| match &crate_graph[krate].display_name { |
49 | Some(it) => format!("{}({:?})", it, krate), | 49 | Some(it) => format!("{}({:?})", it, krate), |
50 | None => format!("{:?}", krate), | 50 | None => format!("{:?}", krate), |
51 | }; | 51 | }; |