@@ -7,6 +7,45 @@ use hir::{self, Docs, HasSource};
77
88use ra_assists:: utils:: get_missing_impl_items;
99
10+ /// Analyzes the specified `CompletionContext` and provides magic completions
11+ /// if the context falls within a `impl Trait for` block.
12+ ///
13+ /// # Completion Activation
14+ /// The completion will activate when a user begins to type a function
15+ /// definition, an associated type, or an associated constant.
16+ ///
17+ /// ### Functions
18+ /// ```ignore
19+ /// trait SomeTrait {
20+ /// fn foo(&self);
21+ /// }
22+ ///
23+ /// impl SomeTrait for () {
24+ /// fn <|>
25+ /// }
26+ /// ```
27+ ///
28+ /// ### Associated Types
29+ /// ```ignore
30+ /// trait SomeTrait {
31+ /// type SomeType;
32+ /// }
33+ ///
34+ /// impl SomeTrait for () {
35+ /// type <|>
36+ /// }
37+ /// ```
38+ ///
39+ /// ### Associated Constants
40+ /// ```ignore
41+ /// trait SomeTrait {
42+ /// const SOME_CONST: u16;
43+ /// }
44+ ///
45+ /// impl SomeTrait for () {
46+ /// const <|>
47+ /// }
48+ /// ```
1049pub ( crate ) fn complete_trait_impl ( acc : & mut Completions , ctx : & CompletionContext ) {
1150
1251 // it is possible to have a parent `fn` and `impl` block. Ignore completion
@@ -86,9 +125,17 @@ fn add_const_impl(
86125 . add_to ( acc) ;
87126}
88127
128+ /// Using a `ConstDef` `SyntaxNode` to create a `String` that represents
129+ /// the output of the magic completion.
130+ ///
131+ /// There isn't a whole lot of information about a `hir::Const` or
132+ /// `ast::ConstDef` to prove useful when creating the magic completion for the
133+ /// associated constant. This method simply copies the syntax tree of the
134+ /// target trait up until a `;` or `=` is found. From the sliced syntax tree
135+ /// it formulates the magic completion string.
89136fn make_const_compl_syntax ( const_ : & ast:: ConstDef ) -> String {
90137 let const_ = edit:: strip_attrs_and_docs ( const_) ;
91-
138+
92139 let const_start = const_. syntax ( ) . text_range ( ) . start ( ) ;
93140 let const_end = const_. syntax ( ) . text_range ( ) . end ( ) ;
94141
0 commit comments