@@ -26,7 +26,7 @@ use crate::assist_context::{AssistContext, Assists};
26
26
// ```
27
27
// pub struct S;
28
28
// impl S {
29
- // /// Sets the length.
29
+ // /// Sets the length of this [`S`] .
30
30
// ///
31
31
// /// # Errors
32
32
// ///
@@ -183,11 +183,13 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<Strin
183
183
let ret_ty = hir_func. ret_type ( ctx. db ( ) ) ;
184
184
let self_ty = imp. self_ty ( ctx. db ( ) ) ;
185
185
let name = ast_func. name ( ) ?. to_string ( ) ;
186
+ let linkable_self_ty = self_type_without_lifetimes ( ast_func) ;
187
+ let linkable_self_ty = linkable_self_ty. as_deref ( ) ;
186
188
187
189
let intro_for_new = || {
188
190
let is_new = name == "new" ;
189
191
if is_new && ret_ty == self_ty {
190
- Some ( format ! ( "Creates a new [`{}`]." , self_type_without_lifetimes ( ast_func ) ?) )
192
+ Some ( format ! ( "Creates a new [`{}`]." , linkable_self_ty ?) )
191
193
} else {
192
194
None
193
195
}
@@ -204,15 +206,15 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<Strin
204
206
let mut what = name. trim_end_matches ( "_mut" ) . replace ( '_' , " " ) ;
205
207
if what == "len" {
206
208
what = "length" . into ( )
207
- } ;
209
+ }
208
210
let reference = if ret_ty. is_mutable_reference ( ) {
209
211
" a mutable reference to"
210
212
} else if ret_ty. is_reference ( ) {
211
213
" a reference to"
212
214
} else {
213
215
""
214
216
} ;
215
- Some ( format ! ( "Returns{reference} the {what}." ) )
217
+ Some ( format ! ( "Returns{reference} the {what} of this [`{}`]." , linkable_self_ty? ) )
216
218
}
217
219
_ => None ,
218
220
} ;
@@ -226,7 +228,7 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<Strin
226
228
if what == "len" {
227
229
what = "length" . into ( )
228
230
} ;
229
- Some ( format ! ( "Sets the {what}." ) )
231
+ Some ( format ! ( "Sets the {what} of this [`{}`]." , linkable_self_ty? ) )
230
232
} ;
231
233
232
234
if let Some ( intro) = intro_for_new ( ) {
@@ -325,11 +327,11 @@ fn self_type_without_lifetimes(ast_func: &ast::Fn) -> Option<String> {
325
327
_ => return None ,
326
328
} ;
327
329
let mut name = path_segment. name_ref ( ) ?. to_string ( ) ;
328
- let generics = path_segment
329
- . generic_arg_list ( ) ?
330
- . generic_args ( )
331
- . filter ( |generic| matches ! ( generic, ast :: GenericArg :: TypeArg ( _ ) ) )
332
- . map ( |generic| generic . to_string ( ) ) ;
330
+ let generics = path_segment. generic_arg_list ( ) . into_iter ( ) . flat_map ( |list| {
331
+ list . generic_args ( )
332
+ . filter ( |generic| matches ! ( generic , ast :: GenericArg :: TypeArg ( _ ) ) )
333
+ . map ( |generic| generic. to_string ( ) )
334
+ } ) ;
333
335
let generics: String = generics. format ( ", " ) . to_string ( ) ;
334
336
if !generics. is_empty ( ) {
335
337
name. push ( '<' ) ;
@@ -970,6 +972,26 @@ pub trait MyTrait {
970
972
check_assist (
971
973
generate_documentation_template,
972
974
r#"
975
+ pub struct String(u8);
976
+ impl String {
977
+ pub fn new$0(x: u8) -> String {
978
+ String(x)
979
+ }
980
+ }
981
+ "# ,
982
+ r#"
983
+ pub struct String(u8);
984
+ impl String {
985
+ /// Creates a new [`String`].
986
+ pub fn new(x: u8) -> String {
987
+ String(x)
988
+ }
989
+ }
990
+ "# ,
991
+ ) ;
992
+ check_assist (
993
+ generate_documentation_template,
994
+ r#"
973
995
#[derive(Debug, PartialEq)]
974
996
pub struct MyGenericStruct<T> {
975
997
pub x: T,
@@ -1193,7 +1215,7 @@ impl S {
1193
1215
r#"
1194
1216
pub struct S;
1195
1217
impl S {
1196
- /// Returns the speed.
1218
+ /// Returns the speed of this [`S`] .
1197
1219
pub fn speed(&self) -> f32 { 0.0 }
1198
1220
}
1199
1221
"# ,
@@ -1209,7 +1231,7 @@ impl S {
1209
1231
r#"
1210
1232
pub struct S;
1211
1233
impl S {
1212
- /// Returns a reference to the data.
1234
+ /// Returns a reference to the data of this [`S`] .
1213
1235
pub fn data(&self) -> &[u8] { &[] }
1214
1236
}
1215
1237
"# ,
@@ -1225,7 +1247,7 @@ impl S {
1225
1247
r#"
1226
1248
pub struct S;
1227
1249
impl S {
1228
- /// Returns a mutable reference to the data.
1250
+ /// Returns a mutable reference to the data of this [`S`] .
1229
1251
pub fn data(&mut self) -> &mut [u8] { &mut [] }
1230
1252
}
1231
1253
"# ,
@@ -1241,7 +1263,7 @@ impl S {
1241
1263
r#"
1242
1264
pub struct S;
1243
1265
impl S {
1244
- /// Returns a mutable reference to the data.
1266
+ /// Returns a mutable reference to the data of this [`S`] .
1245
1267
pub fn data_mut(&mut self) -> &mut [u8] { &mut [] }
1246
1268
}
1247
1269
"# ,
@@ -1281,7 +1303,7 @@ impl S {
1281
1303
r#"
1282
1304
pub struct S;
1283
1305
impl S {
1284
- /// Sets the data.
1306
+ /// Sets the data of this [`S`] .
1285
1307
pub fn set_data(&mut self, data: Vec<u8>) {}
1286
1308
}
1287
1309
"# ,
@@ -1297,7 +1319,7 @@ impl S {
1297
1319
r#"
1298
1320
pub struct S;
1299
1321
impl S {
1300
- /// Sets the domain name.
1322
+ /// Sets the domain name of this [`S`] .
1301
1323
pub fn set_domain_name(&mut self, name: String) {}
1302
1324
}
1303
1325
"# ,
0 commit comments