diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/completion/complete_postfix/format_like.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/completion/complete_unqualified_path.rs | 20 | ||||
-rw-r--r-- | crates/ide/src/completion/completion_context.rs | 5 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 32 | ||||
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 34 | ||||
-rw-r--r-- | crates/ide/src/link_rewrite.rs | 6 | ||||
-rw-r--r-- | crates/ide/src/status.rs | 2 |
7 files changed, 93 insertions, 8 deletions
diff --git a/crates/ide/src/completion/complete_postfix/format_like.rs b/crates/ide/src/completion/complete_postfix/format_like.rs index 0287fc803..81c33bf3a 100644 --- a/crates/ide/src/completion/complete_postfix/format_like.rs +++ b/crates/ide/src/completion/complete_postfix/format_like.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | // Feature: Postfix completion for `format`-like strings. | 1 | // Feature: Format String Completion. |
2 | // | 2 | // |
3 | // `"Result {result} is {2 + 2}"` is expanded to the `"Result {} is {}", result, 2 + 2`. | 3 | // `"Result {result} is {2 + 2}"` is expanded to the `"Result {} is {}", result, 2 + 2`. |
4 | // | 4 | // |
diff --git a/crates/ide/src/completion/complete_unqualified_path.rs b/crates/ide/src/completion/complete_unqualified_path.rs index 2010d9a2f..8b6757195 100644 --- a/crates/ide/src/completion/complete_unqualified_path.rs +++ b/crates/ide/src/completion/complete_unqualified_path.rs | |||
@@ -267,6 +267,26 @@ fn quux() { <|> } | |||
267 | ); | 267 | ); |
268 | } | 268 | } |
269 | 269 | ||
270 | /// Regression test for issue #6091. | ||
271 | #[test] | ||
272 | fn correctly_completes_module_items_prefixed_with_underscore() { | ||
273 | check_edit( | ||
274 | "_alpha", | ||
275 | r#" | ||
276 | fn main() { | ||
277 | _<|> | ||
278 | } | ||
279 | fn _alpha() {} | ||
280 | "#, | ||
281 | r#" | ||
282 | fn main() { | ||
283 | _alpha()$0 | ||
284 | } | ||
285 | fn _alpha() {} | ||
286 | "#, | ||
287 | ) | ||
288 | } | ||
289 | |||
270 | #[test] | 290 | #[test] |
271 | fn completes_extern_prelude() { | 291 | fn completes_extern_prelude() { |
272 | check( | 292 | check( |
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs index 101be8eb5..8dea8a4bf 100644 --- a/crates/ide/src/completion/completion_context.rs +++ b/crates/ide/src/completion/completion_context.rs | |||
@@ -221,10 +221,11 @@ impl<'a> CompletionContext<'a> { | |||
221 | Some(ctx) | 221 | Some(ctx) |
222 | } | 222 | } |
223 | 223 | ||
224 | // The range of the identifier that is being completed. | 224 | /// The range of the identifier that is being completed. |
225 | pub(crate) fn source_range(&self) -> TextRange { | 225 | pub(crate) fn source_range(&self) -> TextRange { |
226 | // check kind of macro-expanded token, but use range of original token | 226 | // check kind of macro-expanded token, but use range of original token |
227 | if self.token.kind() == IDENT || self.token.kind().is_keyword() { | 227 | let kind = self.token.kind(); |
228 | if kind == IDENT || kind == UNDERSCORE || kind.is_keyword() { | ||
228 | mark::hit!(completes_if_prefix_is_keyword); | 229 | mark::hit!(completes_if_prefix_is_keyword); |
229 | self.original_token.text_range() | 230 | self.original_token.text_range() |
230 | } else { | 231 | } else { |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index ba67dd9f8..53265488e 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()].display_name.as_ref().map(ToString::to_string); | 303 | db.crate_graph()[module.krate().into()].declaration_name.as_ref().map(ToString::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() |
@@ -3202,4 +3202,34 @@ fn main() { let s<|>t = test().get(); } | |||
3202 | "#]], | 3202 | "#]], |
3203 | ); | 3203 | ); |
3204 | } | 3204 | } |
3205 | |||
3206 | #[test] | ||
3207 | fn hover_displays_normalized_crate_names() { | ||
3208 | check( | ||
3209 | r#" | ||
3210 | //- /lib.rs crate:name-with-dashes | ||
3211 | pub mod wrapper { | ||
3212 | pub struct Thing { x: u32 } | ||
3213 | |||
3214 | impl Thing { | ||
3215 | pub fn new() -> Thing { Thing { x: 0 } } | ||
3216 | } | ||
3217 | } | ||
3218 | |||
3219 | //- /main.rs crate:main deps:name-with-dashes | ||
3220 | fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); } | ||
3221 | "#, | ||
3222 | expect![[r#" | ||
3223 | *new* | ||
3224 | |||
3225 | ```rust | ||
3226 | name_with_dashes::wrapper::Thing | ||
3227 | ``` | ||
3228 | |||
3229 | ```rust | ||
3230 | pub fn new() -> Thing | ||
3231 | ``` | ||
3232 | "#]], | ||
3233 | ) | ||
3234 | } | ||
3205 | } | 3235 | } |
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 1d7e8de56..3a4dc6a84 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -1026,4 +1026,38 @@ mod collections { | |||
1026 | "#, | 1026 | "#, |
1027 | ); | 1027 | ); |
1028 | } | 1028 | } |
1029 | |||
1030 | #[test] | ||
1031 | fn multi_dyn_trait_bounds() { | ||
1032 | check_with_config( | ||
1033 | InlayHintsConfig { | ||
1034 | type_hints: true, | ||
1035 | parameter_hints: false, | ||
1036 | chaining_hints: false, | ||
1037 | max_length: None, | ||
1038 | }, | ||
1039 | r#" | ||
1040 | //- /main.rs crate:main | ||
1041 | pub struct Vec<T> {} | ||
1042 | |||
1043 | impl<T> Vec<T> { | ||
1044 | pub fn new() -> Self { Vec {} } | ||
1045 | } | ||
1046 | |||
1047 | pub struct Box<T> {} | ||
1048 | |||
1049 | trait Display {} | ||
1050 | trait Sync {} | ||
1051 | |||
1052 | fn main() { | ||
1053 | let _v = Vec::<Box<&(dyn Display + Sync)>>::new(); | ||
1054 | //^^ Vec<Box<&(dyn Display + Sync)>> | ||
1055 | let _v = Vec::<Box<*const (dyn Display + Sync)>>::new(); | ||
1056 | //^^ Vec<Box<*const (dyn Display + Sync)>> | ||
1057 | let _v = Vec::<Box<dyn Display + Sync>>::new(); | ||
1058 | //^^ Vec<Box<dyn Display + Sync>> | ||
1059 | } | ||
1060 | "#, | ||
1061 | ); | ||
1062 | } | ||
1029 | } | 1063 | } |
diff --git a/crates/ide/src/link_rewrite.rs b/crates/ide/src/link_rewrite.rs index a16f90e17..c317a2379 100644 --- a/crates/ide/src/link_rewrite.rs +++ b/crates/ide/src/link_rewrite.rs | |||
@@ -107,7 +107,7 @@ fn rewrite_intra_doc_link( | |||
107 | let krate = resolved.module(db)?.krate(); | 107 | let krate = resolved.module(db)?.krate(); |
108 | let canonical_path = resolved.canonical_path(db)?; | 108 | let canonical_path = resolved.canonical_path(db)?; |
109 | let new_target = get_doc_url(db, &krate)? | 109 | let new_target = get_doc_url(db, &krate)? |
110 | .join(&format!("{}/", krate.display_name(db)?)) | 110 | .join(&format!("{}/", krate.declaration_name(db)?)) |
111 | .ok()? | 111 | .ok()? |
112 | .join(&canonical_path.replace("::", "/")) | 112 | .join(&canonical_path.replace("::", "/")) |
113 | .ok()? | 113 | .ok()? |
@@ -127,7 +127,7 @@ fn rewrite_url_link(db: &RootDatabase, def: ModuleDef, target: &str) -> Option<S | |||
127 | let module = def.module(db)?; | 127 | let module = def.module(db)?; |
128 | let krate = module.krate(); | 128 | let krate = module.krate(); |
129 | let canonical_path = def.canonical_path(db)?; | 129 | let canonical_path = def.canonical_path(db)?; |
130 | let base = format!("{}/{}", krate.display_name(db)?, canonical_path.replace("::", "/")); | 130 | let base = format!("{}/{}", krate.declaration_name(db)?, canonical_path.replace("::", "/")); |
131 | 131 | ||
132 | get_doc_url(db, &krate) | 132 | get_doc_url(db, &krate) |
133 | .and_then(|url| url.join(&base).ok()) | 133 | .and_then(|url| url.join(&base).ok()) |
@@ -248,7 +248,7 @@ fn get_doc_url(db: &RootDatabase, krate: &Crate) -> Option<Url> { | |||
248 | // | 248 | // |
249 | // FIXME: clicking on the link should just open the file in the editor, | 249 | // FIXME: clicking on the link should just open the file in the editor, |
250 | // instead of falling back to external urls. | 250 | // instead of falling back to external urls. |
251 | Some(format!("https://docs.rs/{}/*/", krate.display_name(db)?)) | 251 | Some(format!("https://docs.rs/{}/*/", krate.declaration_name(db)?)) |
252 | }) | 252 | }) |
253 | .and_then(|s| Url::parse(&s).ok()) | 253 | .and_then(|s| Url::parse(&s).ok()) |
254 | } | 254 | } |
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs index 0af84daa0..f67f10491 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].display_name { | 48 | let display_crate = |krate: CrateId| match &crate_graph[krate].declaration_name { |
49 | Some(it) => format!("{}({:?})", it, krate), | 49 | Some(it) => format!("{}({:?})", it, krate), |
50 | None => format!("{:?}", krate), | 50 | None => format!("{:?}", krate), |
51 | }; | 51 | }; |