aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorKevin DeLorey <[email protected]>2020-02-11 15:40:08 +0000
committerKevin DeLorey <[email protected]>2020-02-11 15:40:08 +0000
commit3aaf46afa13b6fcbfdc36d8eb0cce48196d824a7 (patch)
treea178742f62144801bd70bac21dc090923e1ced9c /crates/ra_ide
parentd7e36c3dd2b601401feb86bef3c0f8bb62fb4331 (diff)
Formatted changes.
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs38
1 files changed, 16 insertions, 22 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index f6f4a99c5..cd3f016bf 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -2,53 +2,55 @@ use crate::completion::{
2 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, 2 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
3}; 3};
4 4
5use ra_syntax::{ast::{self, edit}, AstNode, SyntaxKind, TextRange};
6use hir::{self, Docs, HasSource}; 5use hir::{self, Docs, HasSource};
6use ra_syntax::{
7 ast::{self, edit},
8 AstNode, SyntaxKind, TextRange,
9};
7 10
8use ra_assists::utils::get_missing_impl_items; 11use ra_assists::utils::get_missing_impl_items;
9 12
10/// Analyzes the specified `CompletionContext` and provides magic completions 13/// Analyzes the specified `CompletionContext` and provides magic completions
11/// if the context falls within a `impl Trait for` block. 14/// if the context falls within a `impl Trait for` block.
12/// 15///
13/// # Completion Activation 16/// # 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
15/// definition, an associated type, or an associated constant. 18/// definition, an associated type, or an associated constant.
16/// 19///
17/// ### Functions 20/// ### Functions
18/// ```ignore 21/// ```ignore
19/// trait SomeTrait { 22/// trait SomeTrait {
20/// fn foo(&self); 23/// fn foo(&self);
21/// } 24/// }
22/// 25///
23/// impl SomeTrait for () { 26/// impl SomeTrait for () {
24/// fn <|> 27/// fn <|>
25/// } 28/// }
26/// ``` 29/// ```
27/// 30///
28/// ### Associated Types 31/// ### Associated Types
29/// ```ignore 32/// ```ignore
30/// trait SomeTrait { 33/// trait SomeTrait {
31/// type SomeType; 34/// type SomeType;
32/// } 35/// }
33/// 36///
34/// impl SomeTrait for () { 37/// impl SomeTrait for () {
35/// type <|> 38/// type <|>
36/// } 39/// }
37/// ``` 40/// ```
38/// 41///
39/// ### Associated Constants 42/// ### Associated Constants
40/// ```ignore 43/// ```ignore
41/// trait SomeTrait { 44/// trait SomeTrait {
42/// const SOME_CONST: u16; 45/// const SOME_CONST: u16;
43/// } 46/// }
44/// 47///
45/// impl SomeTrait for () { 48/// impl SomeTrait for () {
46/// const <|> 49/// const <|>
47/// } 50/// }
48/// ``` 51/// ```
49pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) { 52pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
50 53 // 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
52 // attempts from within a `fn` block. 54 // attempts from within a `fn` block.
53 if ctx.function_syntax.is_some() { 55 if ctx.function_syntax.is_some() {
54 return; 56 return;
@@ -111,11 +113,7 @@ fn add_type_alias_impl(
111 .add_to(acc); 113 .add_to(acc);
112} 114}
113 115
114fn add_const_impl( 116fn add_const_impl(acc: &mut Completions, ctx: &CompletionContext, const_: &hir::Const) {
115 acc: &mut Completions,
116 ctx: &CompletionContext,
117 const_: &hir::Const,
118) {
119 let snippet = make_const_compl_syntax(&const_.source(ctx.db).value); 117 let snippet = make_const_compl_syntax(&const_.source(ctx.db).value);
120 118
121 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()) 119 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
@@ -131,12 +129,8 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String {
131 let const_start = const_.syntax().text_range().start(); 129 let const_start = const_.syntax().text_range().start();
132 let const_end = const_.syntax().text_range().end(); 130 let const_end = const_.syntax().text_range().end();
133 131
134 let start = const_ 132 let start =
135 .syntax() 133 const_.syntax().first_child_or_token().map_or(const_start, |f| f.text_range().start());
136 .first_child_or_token()
137 .map_or(
138 const_start,
139 |f| f.text_range().start());
140 134
141 let end = const_ 135 let end = const_
142 .syntax() 136 .syntax()