aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs49
1 files changed, 48 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index cb15da647..eb12b7d28 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -7,6 +7,45 @@ use hir::{self, Docs, HasSource};
7 7
8use ra_assists::utils::get_missing_impl_items; 8use ra_assists::utils::get_missing_impl_items;
9 9
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/// ```
10pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) { 49pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
11 50
12 // it is possible to have a parent `fn` and `impl` block. Ignore completion 51 // it is possible to have a parent `fn` and `impl` block. Ignore completion
@@ -86,9 +125,17 @@ fn add_const_impl(
86 .add_to(acc); 125 .add_to(acc);
87} 126}
88 127
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.
89fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { 136fn make_const_compl_syntax(const_: &ast::ConstDef) -> String {
90 let const_ = edit::strip_attrs_and_docs(const_); 137 let const_ = edit::strip_attrs_and_docs(const_);
91 138
92 let const_start = const_.syntax().text_range().start(); 139 let const_start = const_.syntax().text_range().start();
93 let const_end = const_.syntax().text_range().end(); 140 let const_end = const_.syntax().text_range().end();
94 141