diff options
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/doc_links.rs | 28 | ||||
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 29 |
2 files changed, 52 insertions, 5 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index b9d8b8a2b..250f10f9f 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs | |||
@@ -132,7 +132,8 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { | |||
132 | let import_map = db.import_map(krate.into()); | 132 | let import_map = db.import_map(krate.into()); |
133 | let base = once(krate.display_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 | 137 | ||
137 | let filename = get_symbol_filename(db, &target_def); | 138 | let filename = get_symbol_filename(db, &target_def); |
138 | let fragment = match definition { | 139 | let fragment = match definition { |
@@ -152,9 +153,16 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { | |||
152 | _ => None, | 153 | _ => None, |
153 | }; | 154 | }; |
154 | 155 | ||
155 | get_doc_url(db, &krate) | 156 | get_doc_url(db, &krate)? |
156 | .and_then(|url| url.join(&base).ok()) | 157 | .join(&base) |
157 | .and_then(|url| filename.as_deref().and_then(|f| url.join(f).ok())) | 158 | .ok() |
159 | .and_then(|mut url| { | ||
160 | if !matches!(definition, Definition::ModuleDef(ModuleDef::Module(..))) { | ||
161 | url.path_segments_mut().ok()?.pop(); | ||
162 | }; | ||
163 | Some(url) | ||
164 | }) | ||
165 | .and_then(|url| url.join(filename.as_deref()?).ok()) | ||
158 | .and_then( | 166 | .and_then( |
159 | |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) }, | 167 | |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) }, |
160 | ) | 168 | ) |
@@ -522,6 +530,18 @@ pub struct Foo { | |||
522 | ); | 530 | ); |
523 | } | 531 | } |
524 | 532 | ||
533 | #[test] | ||
534 | fn test_module() { | ||
535 | check( | ||
536 | r#" | ||
537 | pub mod foo { | ||
538 | pub mod ba<|>r {} | ||
539 | } | ||
540 | "#, | ||
541 | expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]], | ||
542 | ) | ||
543 | } | ||
544 | |||
525 | // FIXME: ImportMap will return re-export paths instead of public module | 545 | // FIXME: ImportMap will return re-export paths instead of public module |
526 | // paths. The correct path to documentation will never be a re-export. | 546 | // paths. The correct path to documentation will never be a re-export. |
527 | // This problem stops us from resolving stdlib items included in the prelude | 547 | // This problem stops us from resolving stdlib items included in the prelude |
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index cccea129a..49d8e4ae1 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -378,7 +378,11 @@ fn is_enum_name_similar_to_param_name( | |||
378 | fn get_string_representation(expr: &ast::Expr) -> Option<String> { | 378 | fn get_string_representation(expr: &ast::Expr) -> Option<String> { |
379 | match expr { | 379 | match expr { |
380 | ast::Expr::MethodCallExpr(method_call_expr) => { | 380 | ast::Expr::MethodCallExpr(method_call_expr) => { |
381 | Some(method_call_expr.name_ref()?.to_string()) | 381 | let name_ref = method_call_expr.name_ref()?; |
382 | match name_ref.text().as_str() { | ||
383 | "clone" => method_call_expr.receiver().map(|rec| rec.to_string()), | ||
384 | name_ref => Some(name_ref.to_owned()), | ||
385 | } | ||
382 | } | 386 | } |
383 | ast::Expr::RefExpr(ref_expr) => get_string_representation(&ref_expr.expr()?), | 387 | ast::Expr::RefExpr(ref_expr) => get_string_representation(&ref_expr.expr()?), |
384 | _ => Some(expr.to_string()), | 388 | _ => Some(expr.to_string()), |
@@ -1208,4 +1212,27 @@ fn main() { | |||
1208 | "#, | 1212 | "#, |
1209 | ); | 1213 | ); |
1210 | } | 1214 | } |
1215 | |||
1216 | #[test] | ||
1217 | fn hide_param_hints_for_clones() { | ||
1218 | check_with_config( | ||
1219 | InlayHintsConfig { | ||
1220 | parameter_hints: true, | ||
1221 | type_hints: false, | ||
1222 | chaining_hints: false, | ||
1223 | max_length: None, | ||
1224 | }, | ||
1225 | r#" | ||
1226 | fn foo(bar: i32, baz: String, qux: f32) {} | ||
1227 | |||
1228 | fn main() { | ||
1229 | let bar = 3; | ||
1230 | let baz = &"baz"; | ||
1231 | let fez = 1.0; | ||
1232 | foo(bar.clone(), baz.clone(), fez.clone()); | ||
1233 | //^^^^^^^^^^^ qux | ||
1234 | } | ||
1235 | "#, | ||
1236 | ); | ||
1237 | } | ||
1211 | } | 1238 | } |