From 6636f56e79b55f22b88094b7edaed6ec88880500 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 00:23:03 +0200 Subject: Rename ModuleItem -> Item --- crates/ra_ide/src/completion/complete_fn_param.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index db2abb4f1..7a53083f5 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -28,7 +28,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) } }; for item in items { - if let ast::ModuleItem::FnDef(func) = item { + if let ast::Item::FnDef(func) = item { if Some(&func) == me.as_ref() { continue; } -- cgit v1.2.3 From 2984da672e0c73d56501c6b6e4d19fd28152b5eb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 11:42:51 +0200 Subject: Split ItemList & AssocItemList --- crates/ra_ide/src/completion/complete_fn_param.rs | 38 ++++++++++++++--------- crates/ra_ide/src/completion/complete_keyword.rs | 36 ++++++++++----------- crates/ra_ide/src/completion/patterns.rs | 6 ++-- 3 files changed, 43 insertions(+), 37 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 7a53083f5..d4b6112a5 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -18,26 +18,36 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) } let mut params = FxHashMap::default(); + let me = ctx.token.ancestors().find_map(ast::FnDef::cast); + let mut process_fn = |func: ast::FnDef| { + if Some(&func) == me.as_ref() { + return; + } + func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { + let text = param.syntax().text().to_string(); + params.entry(text).or_insert(param); + }) + }; + for node in ctx.token.parent().ancestors() { - let items = match_ast! { + match_ast! { match node { - ast::SourceFile(it) => it.items(), - ast::ItemList(it) => it.items(), + ast::SourceFile(it) => it.items().filter_map(|item| match item { + ast::Item::FnDef(it) => Some(it), + _ => None, + }).for_each(&mut process_fn), + ast::ItemList(it) => it.items().filter_map(|item| match item { + ast::Item::FnDef(it) => Some(it), + _ => None, + }).for_each(&mut process_fn), + ast::AssocItemList(it) => it.assoc_items().filter_map(|item| match item { + ast::AssocItem::FnDef(it) => Some(it), + _ => None, + }).for_each(&mut process_fn), _ => continue, } }; - for item in items { - if let ast::Item::FnDef(func) = item { - if Some(&func) == me.as_ref() { - continue; - } - func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { - let text = param.syntax().text().to_string(); - params.entry(text).or_insert(param); - }) - } - } } params diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index fcdaeef49..1581b2d5d 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs @@ -66,27 +66,24 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte add_keyword(ctx, acc, "fn", "fn $0() {}") } - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "trait", "trait $0 {}"); add_keyword(ctx, acc, "impl", "impl $0 {}"); } return; } - if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { + if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent + { add_keyword(ctx, acc, "fn", "fn $0() {}"); } - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "use", "use "); add_keyword(ctx, acc, "impl", "impl $0 {}"); add_keyword(ctx, acc, "trait", "trait $0 {}"); } - if ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent { + if ctx.has_item_list_or_source_file_parent { add_keyword(ctx, acc, "enum", "enum $0 {}"); add_keyword(ctx, acc, "struct", "struct $0"); add_keyword(ctx, acc, "union", "union $0 {}"); @@ -108,29 +105,28 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte add_keyword(ctx, acc, "else", "else {$0}"); add_keyword(ctx, acc, "else if", "else if $0 {}"); } - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "mod", "mod $0 {}"); } if ctx.bind_pat_parent || ctx.ref_pat_parent { add_keyword(ctx, acc, "mut", "mut "); } - if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { + if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent + { add_keyword(ctx, acc, "const", "const "); add_keyword(ctx, acc, "type", "type "); } - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "static", "static "); }; - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "extern", "extern "); } - if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent || ctx.is_match_arm { + if ctx.has_item_list_or_source_file_parent + || has_trait_or_impl_parent + || ctx.block_expr_parent + || ctx.is_match_arm + { add_keyword(ctx, acc, "unsafe", "unsafe "); } if ctx.in_loop_body { @@ -142,7 +138,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte add_keyword(ctx, acc, "break", "break"); } } - if ctx.has_item_list_or_source_file_parent && !ctx.has_trait_parent { + if ctx.has_item_list_or_source_file_parent || ctx.has_impl_parent { add_keyword(ctx, acc, "pub", "pub ") } diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index b2fe13280..175209d8a 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -13,7 +13,7 @@ use crate::completion::test_utils::check_pattern_is_applicable; pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element) - .filter(|it| it.kind() == ITEM_LIST) + .filter(|it| it.kind() == ASSOC_ITEM_LIST) .and_then(|it| it.parent()) .filter(|it| it.kind() == TRAIT_DEF) .is_some() @@ -25,7 +25,7 @@ fn test_has_trait_parent() { pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element) - .filter(|it| it.kind() == ITEM_LIST) + .filter(|it| it.kind() == ASSOC_ITEM_LIST) .and_then(|it| it.parent()) .filter(|it| it.kind() == IMPL_DEF) .is_some() @@ -73,7 +73,7 @@ pub(crate) fn has_item_list_or_source_file_parent(element: SyntaxElement) -> boo #[test] fn test_has_item_list_or_source_file_parent() { check_pattern_is_applicable(r"i<|>", has_item_list_or_source_file_parent); - check_pattern_is_applicable(r"impl { f<|> }", has_item_list_or_source_file_parent); + check_pattern_is_applicable(r"mod foo { f<|> }", has_item_list_or_source_file_parent); } pub(crate) fn is_match_arm(element: SyntaxElement) -> bool { -- cgit v1.2.3 From b1332670c7c471a59f3da113b366e74ac194c38b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:12:04 +0200 Subject: Rename UseItem -> Use --- crates/ra_ide/src/completion/completion_context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index c84d43d77..cc55f6dd6 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -36,7 +36,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) expected_type: Option, pub(super) name_ref_syntax: Option, pub(super) function_syntax: Option, - pub(super) use_item_syntax: Option, + pub(super) use_item_syntax: Option, pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, pub(super) record_field_syntax: Option, @@ -343,7 +343,7 @@ impl<'a> CompletionContext<'a> { } self.use_item_syntax = - self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::UseItem::cast); + self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::Use::cast); self.function_syntax = self .sema -- cgit v1.2.3 From 1142112c70b705f59b7d559d9d72cdc831865158 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:51:08 +0200 Subject: Rename FnDef -> Fn --- crates/ra_ide/src/completion/complete_fn_param.rs | 10 +++++----- crates/ra_ide/src/completion/complete_keyword.rs | 2 +- crates/ra_ide/src/completion/complete_trait_impl.rs | 6 +++--- crates/ra_ide/src/completion/completion_context.rs | 4 ++-- crates/ra_ide/src/completion/patterns.rs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'crates/ra_ide/src/completion') 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) let mut params = FxHashMap::default(); - let me = ctx.token.ancestors().find_map(ast::FnDef::cast); - let mut process_fn = |func: ast::FnDef| { + let me = ctx.token.ancestors().find_map(ast::Fn::cast); + let mut process_fn = |func: ast::Fn| { if Some(&func) == me.as_ref() { return; } @@ -34,15 +34,15 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) match_ast! { match node { ast::SourceFile(it) => it.items().filter_map(|item| match item { - ast::Item::FnDef(it) => Some(it), + ast::Item::Fn(it) => Some(it), _ => None, }).for_each(&mut process_fn), ast::ItemList(it) => it.items().filter_map(|item| match item { - ast::Item::FnDef(it) => Some(it), + ast::Item::Fn(it) => Some(it), _ => None, }).for_each(&mut process_fn), ast::AssocItemList(it) => it.assoc_items().filter_map(|item| match item { - ast::AssocItem::FnDef(it) => Some(it), + ast::AssocItem::Fn(it) => Some(it), _ => None, }).for_each(&mut process_fn), _ => 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 fn complete_return( ctx: &CompletionContext, - fn_def: &ast::FnDef, + fn_def: &ast::Fn, can_be_stmt: bool, ) -> Option { 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..dbb9eecc6 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -2,7 +2,7 @@ //! //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node -//! must be within either a `FN_DEF`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node +//! must be within either a `FN`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node //! and an direct child of an `IMPL_DEF`. //! //! # Examples @@ -63,7 +63,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } }), - SyntaxKind::FN_DEF => { + SyntaxKind::FN => { for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) .into_iter() .filter_map(|item| match item { @@ -106,7 +106,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { - SyntaxKind::FN_DEF + SyntaxKind::FN | SyntaxKind::TYPE_ALIAS_DEF | SyntaxKind::CONST_DEF | SyntaxKind::BLOCK_EXPR => Some((p, 2)), diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index cc55f6dd6..221d7847e 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -35,7 +35,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) krate: Option, pub(super) expected_type: Option, pub(super) name_ref_syntax: Option, - pub(super) function_syntax: Option, + pub(super) function_syntax: Option, pub(super) use_item_syntax: Option, pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, @@ -349,7 +349,7 @@ impl<'a> CompletionContext<'a> { .sema .ancestors_with_macros(self.token.parent()) .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) - .find_map(ast::FnDef::cast); + .find_map(ast::Fn::cast); self.record_field_syntax = self .sema diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index 175209d8a..b8408da4e 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -134,7 +134,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { NodeOrToken::Token(token) => token.parent(), }; for node in leaf.ancestors() { - if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { + if node.kind() == FN || node.kind() == LAMBDA_EXPR { break; } let loop_body = match_ast! { -- cgit v1.2.3 From eb2f8063444b11257111f4f8ade990ec810e0361 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 15:25:46 +0200 Subject: Rename TypeAliasDef -> TypeAlias --- crates/ra_ide/src/completion/complete_trait_impl.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index dbb9eecc6..7d9050a6b 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -2,7 +2,7 @@ //! //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node -//! must be within either a `FN`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node +//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST_DEF` node //! and an direct child of an `IMPL_DEF`. //! //! # Examples @@ -75,7 +75,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } } - SyntaxKind::TYPE_ALIAS_DEF => { + SyntaxKind::TYPE_ALIAS => { for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) .into_iter() .filter_map(|item| match item { @@ -107,7 +107,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { SyntaxKind::FN - | SyntaxKind::TYPE_ALIAS_DEF + | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST_DEF | SyntaxKind::BLOCK_EXPR => Some((p, 2)), SyntaxKind::NAME_REF => Some((p, 5)), -- cgit v1.2.3 From 6f8aa75329d0a4e588e58b8f22f7932bf3d3a706 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 16:21:30 +0200 Subject: Rename RecordLit -> RecordExpr --- crates/ra_ide/src/completion/completion_context.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 221d7847e..c8704eb3e 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -37,9 +37,9 @@ pub(crate) struct CompletionContext<'a> { pub(super) name_ref_syntax: Option, pub(super) function_syntax: Option, pub(super) use_item_syntax: Option, - pub(super) record_lit_syntax: Option, + pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, - pub(super) record_field_syntax: Option, + pub(super) record_field_syntax: Option, pub(super) impl_def: Option, /// FIXME: `ActiveParameter` is string-based, which is very very wrong pub(super) active_parameter: Option, @@ -316,7 +316,7 @@ impl<'a> CompletionContext<'a> { self.name_ref_syntax = find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); let name_range = name_ref.syntax().text_range(); - if ast::RecordField::for_field_name(&name_ref).is_some() { + if ast::RecordExprField::for_field_name(&name_ref).is_some() { self.record_lit_syntax = self.sema.find_node_at_offset_with_macros(&original_file, offset); } @@ -357,7 +357,7 @@ impl<'a> CompletionContext<'a> { .take_while(|it| { it.kind() != SOURCE_FILE && it.kind() != MODULE && it.kind() != CALL_EXPR }) - .find_map(ast::RecordField::cast); + .find_map(ast::RecordExprField::cast); let parent = match name_ref.syntax().parent() { Some(it) => it, -- cgit v1.2.3 From 3cd4112bdc924c132cb0eab9d064511a215421ec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:02:20 +0200 Subject: Finalize const&static grammar --- crates/ra_ide/src/completion/complete_trait_impl.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 7d9050a6b..88679f3bd 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -2,7 +2,7 @@ //! //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node -//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST_DEF` node +//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST` node //! and an direct child of an `IMPL_DEF`. //! //! # Examples @@ -87,7 +87,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } } - SyntaxKind::CONST_DEF => { + SyntaxKind::CONST => { for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) .into_iter() .filter_map(|item| match item { @@ -108,7 +108,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { SyntaxKind::FN | SyntaxKind::TYPE_ALIAS - | SyntaxKind::CONST_DEF + | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => Some((p, 2)), SyntaxKind::NAME_REF => Some((p, 5)), _ => None, @@ -201,7 +201,7 @@ fn add_const_impl( } } -fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { +fn make_const_compl_syntax(const_: &ast::Const) -> String { let const_ = edit::remove_attrs_and_docs(const_); let const_start = const_.syntax().text_range().start(); -- cgit v1.2.3 From ba71f05438a93991aff6970488a720c90774d35b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:10:07 +0200 Subject: fmt --- crates/ra_ide/src/completion/complete_trait_impl.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 88679f3bd..87221d964 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -106,10 +106,9 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { - SyntaxKind::FN - | SyntaxKind::TYPE_ALIAS - | SyntaxKind::CONST - | SyntaxKind::BLOCK_EXPR => Some((p, 2)), + SyntaxKind::FN | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => { + Some((p, 2)) + } SyntaxKind::NAME_REF => Some((p, 5)), _ => None, })?; -- cgit v1.2.3 From c83467796b6c7365ea4f41900d74444384a9e618 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:17:28 +0200 Subject: Finalize Trait grammar --- crates/ra_ide/src/completion/patterns.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index b8408da4e..6c11f5830 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 { not_same_range_ancestor(element) .filter(|it| it.kind() == ASSOC_ITEM_LIST) .and_then(|it| it.parent()) - .filter(|it| it.kind() == TRAIT_DEF) + .filter(|it| it.kind() == TRAIT) .is_some() } #[test] @@ -113,7 +113,7 @@ fn test_if_is_prev() { } pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool { - previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT_DEF).is_some() + previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT).is_some() } #[test] fn test_has_trait_as_prev_sibling() { -- cgit v1.2.3 From c5798c4d75aa807aec47208a49101bdec3affcca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:28:28 +0200 Subject: Finalize impl Grammar --- crates/ra_ide/src/completion/complete_trait_impl.rs | 8 ++++---- crates/ra_ide/src/completion/completion_context.rs | 4 ++-- crates/ra_ide/src/completion/patterns.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 87221d964..d9a0ef167 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -3,7 +3,7 @@ //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node //! must be within either a `FN`, `TYPE_ALIAS`, or `CONST` node -//! and an direct child of an `IMPL_DEF`. +//! and an direct child of an `IMPL`. //! //! # Examples //! @@ -34,7 +34,7 @@ use hir::{self, Docs, HasSource}; use ra_assists::utils::get_missing_assoc_items; use ra_syntax::{ - ast::{self, edit, ImplDef}, + ast::{self, edit, Impl}, AstNode, SyntaxKind, SyntaxNode, TextRange, T, }; use ra_text_edit::TextEdit; @@ -104,7 +104,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } } -fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { +fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, Impl)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { SyntaxKind::FN | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => { Some((p, 2)) @@ -114,7 +114,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { })?; let impl_def = (0..impl_def_offset - 1) .try_fold(trigger.parent()?, |t, _| t.parent()) - .and_then(ast::ImplDef::cast)?; + .and_then(ast::Impl::cast)?; Some((trigger, impl_def)) } diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index c8704eb3e..2113abbb2 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -40,7 +40,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, pub(super) record_field_syntax: Option, - pub(super) impl_def: Option, + pub(super) impl_def: Option, /// FIXME: `ActiveParameter` is string-based, which is very very wrong pub(super) active_parameter: Option, pub(super) is_param: bool, @@ -325,7 +325,7 @@ impl<'a> CompletionContext<'a> { .sema .ancestors_with_macros(self.token.parent()) .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) - .find_map(ast::ImplDef::cast); + .find_map(ast::Impl::cast); let top_node = name_ref .syntax() diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index 6c11f5830..a68861e1c 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -27,7 +27,7 @@ pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element) .filter(|it| it.kind() == ASSOC_ITEM_LIST) .and_then(|it| it.parent()) - .filter(|it| it.kind() == IMPL_DEF) + .filter(|it| it.kind() == IMPL) .is_some() } #[test] @@ -121,7 +121,7 @@ fn test_has_trait_as_prev_sibling() { } pub(crate) fn has_impl_as_prev_sibling(element: SyntaxElement) -> bool { - previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == IMPL_DEF).is_some() + previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == IMPL).is_some() } #[test] fn test_has_impl_as_prev_sibling() { -- cgit v1.2.3 From fcce07d2d1b07cf4578af65b00a243e743a67f05 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 20:16:04 +0200 Subject: Finalize attribute grammar --- crates/ra_ide/src/completion/complete_attribute.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide/src/completion') 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::{ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { let attribute = ctx.attribute_under_caret.as_ref()?; - match (attribute.path(), attribute.input()) { - (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) - if path.to_string() == "derive" => - { + match (attribute.path(), attribute.token_tree()) { + (Some(path), Some(token_tree)) if path.to_string() == "derive" => { complete_derive(acc, ctx, token_tree) } - (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) + (Some(path), Some(token_tree)) if ["allow", "warn", "deny", "forbid"] .iter() .any(|lint_level| lint_level == &path.to_string()) => { complete_lint(acc, ctx, token_tree) } - (_, Some(ast::AttrInput::TokenTree(_token_tree))) => {} + (_, Some(_token_tree)) => {} _ => complete_attribute_start(acc, ctx, attribute), } Some(()) -- cgit v1.2.3 From 633aace41108b74fe6c93c5ab04272067db033f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 17:08:58 +0200 Subject: Rename LambdaExpr -> ClosureExpr --- crates/ra_ide/src/completion/patterns.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index a68861e1c..9e654b373 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -134,7 +134,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { NodeOrToken::Token(token) => token.parent(), }; for node in leaf.ancestors() { - if node.kind() == FN || node.kind() == LAMBDA_EXPR { + if node.kind() == FN || node.kind() == CLOSURE_EXPR { break; } let loop_body = match_ast! { -- cgit v1.2.3 From 91781c7ce8201b28afd56b4e35eba47e076a8498 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 18:29:29 +0200 Subject: Rename TypeArgList -> GenericArgList --- crates/ra_ide/src/completion/completion_context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 2113abbb2..2a5f3c3d2 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -377,7 +377,7 @@ impl<'a> CompletionContext<'a> { path.syntax().parent().and_then(ast::TupleStructPat::cast).is_some(); self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some(); - self.has_type_args = segment.type_arg_list().is_some(); + self.has_type_args = segment.generic_arg_list().is_some(); #[allow(deprecated)] if let Some(path) = hir::Path::from_ast(path.clone()) { -- cgit v1.2.3 From 14cb96ec0e6be3b99bfe4ea373c058dcbd2a4f79 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 19:54:16 +0200 Subject: Allign RecordPat with RecordExpr --- crates/ra_ide/src/completion/completion_context.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 2a5f3c3d2..29955754c 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -265,7 +265,7 @@ impl<'a> CompletionContext<'a> { return; } // FIXME: remove this (V) duplication and make the check more precise - if name_ref.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { + if name_ref.syntax().ancestors().find_map(ast::RecordPatFieldList::cast).is_some() { self.record_pat_syntax = self.sema.find_node_at_offset_with_macros(&original_file, offset); } @@ -283,7 +283,7 @@ impl<'a> CompletionContext<'a> { { self.is_pat_binding_or_const = false; } - if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() { + if bind_pat.syntax().parent().and_then(ast::RecordPatFieldList::cast).is_some() { self.is_pat_binding_or_const = false; } if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) { @@ -300,7 +300,7 @@ impl<'a> CompletionContext<'a> { return; } // FIXME: remove this (^) duplication and make the check more precise - if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { + if name.syntax().ancestors().find_map(ast::RecordPatFieldList::cast).is_some() { self.record_pat_syntax = self.sema.find_node_at_offset_with_macros(&original_file, offset); } -- cgit v1.2.3 From 98181087984157e27faba0b969e384f3c62c39d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:09:09 +0200 Subject: Rename BindPat -> IdentPat --- crates/ra_ide/src/completion/completion_context.rs | 2 +- crates/ra_ide/src/completion/patterns.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 29955754c..6b03b30bb 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -275,7 +275,7 @@ impl<'a> CompletionContext<'a> { // Otherwise, see if this is a declaration. We can use heuristics to // suggest declaration names, see `CompletionKind::Magic`. if let Some(name) = find_node_at_offset::(&file_with_fake_ident, offset) { - if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { + if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::IdentPat::cast) { self.is_pat_binding_or_const = true; if bind_pat.at_token().is_some() || bind_pat.ref_token().is_some() diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index 9e654b373..7c4feff6d 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -44,7 +44,7 @@ fn test_has_block_expr_parent() { } pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool { - element.ancestors().find(|it| it.kind() == BIND_PAT).is_some() + element.ancestors().find(|it| it.kind() == IDENT_PAT).is_some() } #[test] fn test_has_bind_pat_parent() { -- cgit v1.2.3