@@ -2,53 +2,55 @@ use crate::completion::{
22 CompletionContext , CompletionItem , CompletionItemKind , CompletionKind , Completions ,
33} ;
44
5- use ra_syntax:: { ast:: { self , edit} , AstNode , SyntaxKind , TextRange } ;
65use hir:: { self , Docs , HasSource } ;
6+ use ra_syntax:: {
7+ ast:: { self , edit} ,
8+ AstNode , SyntaxKind , TextRange ,
9+ } ;
710
811use ra_assists:: utils:: get_missing_impl_items;
912
1013/// Analyzes the specified `CompletionContext` and provides magic completions
1114/// if the context falls within a `impl Trait for` block.
12- ///
15+ ///
1316/// # Completion Activation
14- /// The completion will activate when a user begins to type a function
17+ /// The completion will activate when a user begins to type a function
1518/// definition, an associated type, or an associated constant.
16- ///
19+ ///
1720/// ### Functions
1821/// ```ignore
1922/// trait SomeTrait {
2023/// fn foo(&self);
2124/// }
22- ///
25+ ///
2326/// impl SomeTrait for () {
2427/// fn <|>
2528/// }
2629/// ```
27- ///
30+ ///
2831/// ### Associated Types
2932/// ```ignore
3033/// trait SomeTrait {
3134/// type SomeType;
3235/// }
33- ///
36+ ///
3437/// impl SomeTrait for () {
3538/// type <|>
3639/// }
3740/// ```
38- ///
41+ ///
3942/// ### Associated Constants
4043/// ```ignore
4144/// trait SomeTrait {
4245/// const SOME_CONST: u16;
4346/// }
44- ///
47+ ///
4548/// impl SomeTrait for () {
4649/// const <|>
4750/// }
4851/// ```
4952pub ( crate ) fn complete_trait_impl ( acc : & mut Completions , ctx : & CompletionContext ) {
50-
51- // it is possible to have a parent `fn` and `impl` block. Ignore completion
53+ // it is possible to have a parent `fn` and `impl` block. Ignore completion
5254 // attempts from within a `fn` block.
5355 if ctx. function_syntax . is_some ( ) {
5456 return ;
@@ -111,11 +113,7 @@ fn add_type_alias_impl(
111113 . add_to ( acc) ;
112114}
113115
114- fn add_const_impl (
115- acc : & mut Completions ,
116- ctx : & CompletionContext ,
117- const_ : & hir:: Const ,
118- ) {
116+ fn add_const_impl ( acc : & mut Completions , ctx : & CompletionContext , const_ : & hir:: Const ) {
119117 let snippet = make_const_compl_syntax ( & const_. source ( ctx. db ) . value ) ;
120118
121119 CompletionItem :: new ( CompletionKind :: Magic , ctx. source_range ( ) , snippet. clone ( ) )
@@ -131,12 +129,8 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String {
131129 let const_start = const_. syntax ( ) . text_range ( ) . start ( ) ;
132130 let const_end = const_. syntax ( ) . text_range ( ) . end ( ) ;
133131
134- let start = const_
135- . syntax ( )
136- . first_child_or_token ( )
137- . map_or (
138- const_start,
139- |f| f. text_range ( ) . start ( ) ) ;
132+ let start =
133+ const_. syntax ( ) . first_child_or_token ( ) . map_or ( const_start, |f| f. text_range ( ) . start ( ) ) ;
140134
141135 let end = const_
142136 . syntax ( )
0 commit comments