File tree 5 files changed +28
-0
lines changed
5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,13 @@ impl Attrs {
207
207
} )
208
208
}
209
209
210
+ pub fn has_doc_notable_trait ( & self ) -> bool {
211
+ self . by_key ( "doc" ) . tt_values ( ) . any ( |tt| {
212
+ tt. delimiter . kind == DelimiterKind :: Parenthesis &&
213
+ matches ! ( & * tt. token_trees, [ tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident) ) ] if ident. text == "notable_trait" )
214
+ } )
215
+ }
216
+
210
217
pub fn doc_exprs ( & self ) -> impl Iterator < Item = DocExpr > + ' _ {
211
218
self . by_key ( "doc" ) . tt_values ( ) . map ( DocExpr :: parse)
212
219
}
Original file line number Diff line number Diff line change @@ -529,6 +529,11 @@ impl CompletionContext<'_> {
529
529
}
530
530
}
531
531
532
+ /// Whether the given trait has `#[doc(notable_trait)]`
533
+ pub ( crate ) fn is_doc_notable_trait ( & self , trait_ : hir:: Trait ) -> bool {
534
+ trait_. attrs ( self . db ) . has_doc_notable_trait ( )
535
+ }
536
+
532
537
/// Returns the traits in scope, with the [`Drop`] trait removed.
533
538
pub ( crate ) fn traits_in_scope ( & self ) -> hir:: VisibleTraits {
534
539
let mut traits_in_scope = self . scope . visible_traits ( ) ;
Original file line number Diff line number Diff line change @@ -152,6 +152,8 @@ pub struct CompletionRelevance {
152
152
pub is_local : bool ,
153
153
/// This is set when trait items are completed in an impl of that trait.
154
154
pub is_item_from_trait : bool ,
155
+ /// This is set for when trait items are from traits with `#[doc(notable_trait)]`
156
+ pub is_item_from_notable_trait : bool ,
155
157
/// This is set when an import is suggested whose name is already imported.
156
158
pub is_name_already_imported : bool ,
157
159
/// This is set for completions that will insert a `use` item.
@@ -228,6 +230,7 @@ impl CompletionRelevance {
228
230
is_private_editable,
229
231
postfix_match,
230
232
is_definite,
233
+ is_item_from_notable_trait,
231
234
} = self ;
232
235
233
236
// lower rank private things
@@ -266,6 +269,9 @@ impl CompletionRelevance {
266
269
if is_item_from_trait {
267
270
score += 1 ;
268
271
}
272
+ if is_item_from_notable_trait {
273
+ score += 1 ;
274
+ }
269
275
if is_definite {
270
276
score += 10 ;
271
277
}
Original file line number Diff line number Diff line change @@ -1170,6 +1170,7 @@ fn main() { let _: m::Spam = S$0 }
1170
1170
),
1171
1171
is_local: false,
1172
1172
is_item_from_trait: false,
1173
+ is_item_from_notable_trait: false,
1173
1174
is_name_already_imported: false,
1174
1175
requires_import: false,
1175
1176
is_op_method: false,
@@ -1196,6 +1197,7 @@ fn main() { let _: m::Spam = S$0 }
1196
1197
),
1197
1198
is_local: false,
1198
1199
is_item_from_trait: false,
1200
+ is_item_from_notable_trait: false,
1199
1201
is_name_already_imported: false,
1200
1202
requires_import: false,
1201
1203
is_op_method: false,
@@ -1274,6 +1276,7 @@ fn foo() { A { the$0 } }
1274
1276
),
1275
1277
is_local: false,
1276
1278
is_item_from_trait: false,
1279
+ is_item_from_notable_trait: false,
1277
1280
is_name_already_imported: false,
1278
1281
requires_import: false,
1279
1282
is_op_method: false,
@@ -2089,6 +2092,7 @@ fn foo() {
2089
2092
),
2090
2093
is_local: false,
2091
2094
is_item_from_trait: false,
2095
+ is_item_from_notable_trait: false,
2092
2096
is_name_already_imported: false,
2093
2097
requires_import: false,
2094
2098
is_op_method: false,
Original file line number Diff line number Diff line change @@ -79,6 +79,11 @@ fn render(
79
79
. and_then ( |trait_| trait_. containing_trait_or_trait_impl ( ctx. db ( ) ) )
80
80
. map_or ( false , |trait_| completion. is_ops_trait ( trait_) ) ;
81
81
82
+ let is_item_from_notable_trait = func
83
+ . as_assoc_item ( ctx. db ( ) )
84
+ . and_then ( |trait_| trait_. containing_trait ( ctx. db ( ) ) )
85
+ . map_or ( false , |trait_| completion. is_doc_notable_trait ( trait_) ) ;
86
+
82
87
let ( has_dot_receiver, has_call_parens, cap) = match func_kind {
83
88
FuncKind :: Function ( & PathCompletionCtx {
84
89
kind : PathKind :: Expr { .. } ,
@@ -105,6 +110,7 @@ fn render(
105
110
} ,
106
111
exact_name_match : compute_exact_name_match ( completion, & call) ,
107
112
is_op_method,
113
+ is_item_from_notable_trait,
108
114
..ctx. completion_relevance ( )
109
115
} ) ;
110
116
You can’t perform that action at this time.
0 commit comments