aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/complete_attribute.rs10
-rw-r--r--crates/ra_ide/src/completion/complete_fn_param.rs10
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs25
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs16
-rw-r--r--crates/ra_ide/src/completion/patterns.rs10
6 files changed, 35 insertions, 38 deletions
diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs
index 109c5e9a8..2faaae974 100644
--- a/crates/ra_ide/src/completion/complete_attribute.rs
+++ b/crates/ra_ide/src/completion/complete_attribute.rs
@@ -13,20 +13,18 @@ use crate::completion::{
13 13
14pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { 14pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
15 let attribute = ctx.attribute_under_caret.as_ref()?; 15 let attribute = ctx.attribute_under_caret.as_ref()?;
16 match (attribute.path(), attribute.input()) { 16 match (attribute.path(), attribute.token_tree()) {
17 (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) 17 (Some(path), Some(token_tree)) if path.to_string() == "derive" => {
18 if path.to_string() == "derive" =>
19 {
20 complete_derive(acc, ctx, token_tree) 18 complete_derive(acc, ctx, token_tree)
21 } 19 }
22 (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) 20 (Some(path), Some(token_tree))
23 if ["allow", "warn", "deny", "forbid"] 21 if ["allow", "warn", "deny", "forbid"]
24 .iter() 22 .iter()
25 .any(|lint_level| lint_level == &path.to_string()) => 23 .any(|lint_level| lint_level == &path.to_string()) =>
26 { 24 {
27 complete_lint(acc, ctx, token_tree) 25 complete_lint(acc, ctx, token_tree)
28 } 26 }
29 (_, Some(ast::AttrInput::TokenTree(_token_tree))) => {} 27 (_, Some(_token_tree)) => {}
30 _ => complete_attribute_start(acc, ctx, attribute), 28 _ => complete_attribute_start(acc, ctx, attribute),
31 } 29 }
32 Some(()) 30 Some(())
diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs
index d4b6112a5..406334257 100644
--- a/crates/ra_ide/src/completion/complete_fn_param.rs
+++ b/crates/ra_ide/src/completion/complete_fn_param.rs
@@ -19,8 +19,8 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
19 19
20 let mut params = FxHashMap::default(); 20 let mut params = FxHashMap::default();
21 21
22 let me = ctx.token.ancestors().find_map(ast::FnDef::cast); 22 let me = ctx.token.ancestors().find_map(ast::Fn::cast);
23 let mut process_fn = |func: ast::FnDef| { 23 let mut process_fn = |func: ast::Fn| {
24 if Some(&func) == me.as_ref() { 24 if Some(&func) == me.as_ref() {
25 return; 25 return;
26 } 26 }
@@ -34,15 +34,15 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
34 match_ast! { 34 match_ast! {
35 match node { 35 match node {
36 ast::SourceFile(it) => it.items().filter_map(|item| match item { 36 ast::SourceFile(it) => it.items().filter_map(|item| match item {
37 ast::Item::FnDef(it) => Some(it), 37 ast::Item::Fn(it) => Some(it),
38 _ => None, 38 _ => None,
39 }).for_each(&mut process_fn), 39 }).for_each(&mut process_fn),
40 ast::ItemList(it) => it.items().filter_map(|item| match item { 40 ast::ItemList(it) => it.items().filter_map(|item| match item {
41 ast::Item::FnDef(it) => Some(it), 41 ast::Item::Fn(it) => Some(it),
42 _ => None, 42 _ => None,
43 }).for_each(&mut process_fn), 43 }).for_each(&mut process_fn),
44 ast::AssocItemList(it) => it.assoc_items().filter_map(|item| match item { 44 ast::AssocItemList(it) => it.assoc_items().filter_map(|item| match item {
45 ast::AssocItem::FnDef(it) => Some(it), 45 ast::AssocItem::Fn(it) => Some(it),
46 _ => None, 46 _ => None,
47 }).for_each(&mut process_fn), 47 }).for_each(&mut process_fn),
48 _ => continue, 48 _ => continue,
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs
index 1581b2d5d..b62064797 100644
--- a/crates/ra_ide/src/completion/complete_keyword.rs
+++ b/crates/ra_ide/src/completion/complete_keyword.rs
@@ -169,7 +169,7 @@ fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet
169 169
170fn complete_return( 170fn complete_return(
171 ctx: &CompletionContext, 171 ctx: &CompletionContext,
172 fn_def: &ast::FnDef, 172 fn_def: &ast::Fn,
173 can_be_stmt: bool, 173 can_be_stmt: bool,
174) -> Option<CompletionItem> { 174) -> Option<CompletionItem> {
175 let snip = match (can_be_stmt, fn_def.ret_type().is_some()) { 175 let snip = match (can_be_stmt, fn_def.ret_type().is_some()) {
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index cf716540f..d9a0ef167 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -2,8 +2,8 @@
2//! 2//!
3//! This module adds the completion items related to implementing associated 3//! This module adds the completion items related to implementing associated
4//! items within a `impl Trait for Struct` block. The current context node 4//! items within a `impl Trait for Struct` block. The current context node
5//! must be within either a `FN_DEF`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node 5//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST` node
6//! and an direct child of an `IMPL_DEF`. 6//! and an direct child of an `IMPL`.
7//! 7//!
8//! # Examples 8//! # Examples
9//! 9//!
@@ -34,7 +34,7 @@
34use hir::{self, Docs, HasSource}; 34use hir::{self, Docs, HasSource};
35use ra_assists::utils::get_missing_assoc_items; 35use ra_assists::utils::get_missing_assoc_items;
36use ra_syntax::{ 36use ra_syntax::{
37 ast::{self, edit, ImplDef}, 37 ast::{self, edit, Impl},
38 AstNode, SyntaxKind, SyntaxNode, TextRange, T, 38 AstNode, SyntaxKind, SyntaxNode, TextRange, T,
39}; 39};
40use ra_text_edit::TextEdit; 40use ra_text_edit::TextEdit;
@@ -63,7 +63,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
63 } 63 }
64 }), 64 }),
65 65
66 SyntaxKind::FN_DEF => { 66 SyntaxKind::FN => {
67 for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) 67 for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def)
68 .into_iter() 68 .into_iter()
69 .filter_map(|item| match item { 69 .filter_map(|item| match item {
@@ -75,7 +75,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
75 } 75 }
76 } 76 }
77 77
78 SyntaxKind::TYPE_ALIAS_DEF => { 78 SyntaxKind::TYPE_ALIAS => {
79 for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) 79 for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def)
80 .into_iter() 80 .into_iter()
81 .filter_map(|item| match item { 81 .filter_map(|item| match item {
@@ -87,7 +87,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
87 } 87 }
88 } 88 }
89 89
90 SyntaxKind::CONST_DEF => { 90 SyntaxKind::CONST => {
91 for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) 91 for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def)
92 .into_iter() 92 .into_iter()
93 .filter_map(|item| match item { 93 .filter_map(|item| match item {
@@ -104,18 +104,17 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
104 } 104 }
105} 105}
106 106
107fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { 107fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, Impl)> {
108 let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { 108 let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() {
109 SyntaxKind::FN_DEF 109 SyntaxKind::FN | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => {
110 | SyntaxKind::TYPE_ALIAS_DEF 110 Some((p, 2))
111 | SyntaxKind::CONST_DEF 111 }
112 | SyntaxKind::BLOCK_EXPR => Some((p, 2)),
113 SyntaxKind::NAME_REF => Some((p, 5)), 112 SyntaxKind::NAME_REF => Some((p, 5)),
114 _ => None, 113 _ => None,
115 })?; 114 })?;
116 let impl_def = (0..impl_def_offset - 1) 115 let impl_def = (0..impl_def_offset - 1)
117 .try_fold(trigger.parent()?, |t, _| t.parent()) 116 .try_fold(trigger.parent()?, |t, _| t.parent())
118 .and_then(ast::ImplDef::cast)?; 117 .and_then(ast::Impl::cast)?;
119 Some((trigger, impl_def)) 118 Some((trigger, impl_def))
120} 119}
121 120
@@ -201,7 +200,7 @@ fn add_const_impl(
201 } 200 }
202} 201}
203 202
204fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { 203fn make_const_compl_syntax(const_: &ast::Const) -> String {
205 let const_ = edit::remove_attrs_and_docs(const_); 204 let const_ = edit::remove_attrs_and_docs(const_);
206 205
207 let const_start = const_.syntax().text_range().start(); 206 let const_start = const_.syntax().text_range().start();
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index cc55f6dd6..2113abbb2 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -35,12 +35,12 @@ pub(crate) struct CompletionContext<'a> {
35 pub(super) krate: Option<hir::Crate>, 35 pub(super) krate: Option<hir::Crate>,
36 pub(super) expected_type: Option<Type>, 36 pub(super) expected_type: Option<Type>,
37 pub(super) name_ref_syntax: Option<ast::NameRef>, 37 pub(super) name_ref_syntax: Option<ast::NameRef>,
38 pub(super) function_syntax: Option<ast::FnDef>, 38 pub(super) function_syntax: Option<ast::Fn>,
39 pub(super) use_item_syntax: Option<ast::Use>, 39 pub(super) use_item_syntax: Option<ast::Use>,
40 pub(super) record_lit_syntax: Option<ast::RecordLit>, 40 pub(super) record_lit_syntax: Option<ast::RecordExpr>,
41 pub(super) record_pat_syntax: Option<ast::RecordPat>, 41 pub(super) record_pat_syntax: Option<ast::RecordPat>,
42 pub(super) record_field_syntax: Option<ast::RecordField>, 42 pub(super) record_field_syntax: Option<ast::RecordExprField>,
43 pub(super) impl_def: Option<ast::ImplDef>, 43 pub(super) impl_def: Option<ast::Impl>,
44 /// FIXME: `ActiveParameter` is string-based, which is very very wrong 44 /// FIXME: `ActiveParameter` is string-based, which is very very wrong
45 pub(super) active_parameter: Option<ActiveParameter>, 45 pub(super) active_parameter: Option<ActiveParameter>,
46 pub(super) is_param: bool, 46 pub(super) is_param: bool,
@@ -316,7 +316,7 @@ impl<'a> CompletionContext<'a> {
316 self.name_ref_syntax = 316 self.name_ref_syntax =
317 find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); 317 find_node_at_offset(&original_file, name_ref.syntax().text_range().start());
318 let name_range = name_ref.syntax().text_range(); 318 let name_range = name_ref.syntax().text_range();
319 if ast::RecordField::for_field_name(&name_ref).is_some() { 319 if ast::RecordExprField::for_field_name(&name_ref).is_some() {
320 self.record_lit_syntax = 320 self.record_lit_syntax =
321 self.sema.find_node_at_offset_with_macros(&original_file, offset); 321 self.sema.find_node_at_offset_with_macros(&original_file, offset);
322 } 322 }
@@ -325,7 +325,7 @@ impl<'a> CompletionContext<'a> {
325 .sema 325 .sema
326 .ancestors_with_macros(self.token.parent()) 326 .ancestors_with_macros(self.token.parent())
327 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) 327 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
328 .find_map(ast::ImplDef::cast); 328 .find_map(ast::Impl::cast);
329 329
330 let top_node = name_ref 330 let top_node = name_ref
331 .syntax() 331 .syntax()
@@ -349,7 +349,7 @@ impl<'a> CompletionContext<'a> {
349 .sema 349 .sema
350 .ancestors_with_macros(self.token.parent()) 350 .ancestors_with_macros(self.token.parent())
351 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) 351 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
352 .find_map(ast::FnDef::cast); 352 .find_map(ast::Fn::cast);
353 353
354 self.record_field_syntax = self 354 self.record_field_syntax = self
355 .sema 355 .sema
@@ -357,7 +357,7 @@ impl<'a> CompletionContext<'a> {
357 .take_while(|it| { 357 .take_while(|it| {
358 it.kind() != SOURCE_FILE && it.kind() != MODULE && it.kind() != CALL_EXPR 358 it.kind() != SOURCE_FILE && it.kind() != MODULE && it.kind() != CALL_EXPR
359 }) 359 })
360 .find_map(ast::RecordField::cast); 360 .find_map(ast::RecordExprField::cast);
361 361
362 let parent = match name_ref.syntax().parent() { 362 let parent = match name_ref.syntax().parent() {
363 Some(it) => it, 363 Some(it) => it,
diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs
index 175209d8a..a68861e1c 100644
--- a/crates/ra_ide/src/completion/patterns.rs
+++ b/crates/ra_ide/src/completion/patterns.rs
@@ -15,7 +15,7 @@ pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool {
15 not_same_range_ancestor(element) 15 not_same_range_ancestor(element)
16 .filter(|it| it.kind() == ASSOC_ITEM_LIST) 16 .filter(|it| it.kind() == ASSOC_ITEM_LIST)
17 .and_then(|it| it.parent()) 17 .and_then(|it| it.parent())
18 .filter(|it| it.kind() == TRAIT_DEF) 18 .filter(|it| it.kind() == TRAIT)
19 .is_some() 19 .is_some()
20} 20}
21#[test] 21#[test]
@@ -27,7 +27,7 @@ pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool {
27 not_same_range_ancestor(element) 27 not_same_range_ancestor(element)
28 .filter(|it| it.kind() == ASSOC_ITEM_LIST) 28 .filter(|it| it.kind() == ASSOC_ITEM_LIST)
29 .and_then(|it| it.parent()) 29 .and_then(|it| it.parent())
30 .filter(|it| it.kind() == IMPL_DEF) 30 .filter(|it| it.kind() == IMPL)
31 .is_some() 31 .is_some()
32} 32}
33#[test] 33#[test]
@@ -113,7 +113,7 @@ fn test_if_is_prev() {
113} 113}
114 114
115pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool { 115pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool {
116 previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT_DEF).is_some() 116 previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT).is_some()
117} 117}
118#[test] 118#[test]
119fn test_has_trait_as_prev_sibling() { 119fn test_has_trait_as_prev_sibling() {
@@ -121,7 +121,7 @@ fn test_has_trait_as_prev_sibling() {
121} 121}
122 122
123pub(crate) fn has_impl_as_prev_sibling(element: SyntaxElement) -> bool { 123pub(crate) fn has_impl_as_prev_sibling(element: SyntaxElement) -> bool {
124 previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == IMPL_DEF).is_some() 124 previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == IMPL).is_some()
125} 125}
126#[test] 126#[test]
127fn test_has_impl_as_prev_sibling() { 127fn test_has_impl_as_prev_sibling() {
@@ -134,7 +134,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool {
134 NodeOrToken::Token(token) => token.parent(), 134 NodeOrToken::Token(token) => token.parent(),
135 }; 135 };
136 for node in leaf.ancestors() { 136 for node in leaf.ancestors() {
137 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { 137 if node.kind() == FN || node.kind() == LAMBDA_EXPR {
138 break; 138 break;
139 } 139 }
140 let loop_body = match_ast! { 140 let loop_body = match_ast! {