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 ++-- crates/ra_ide/src/file_structure.rs | 6 +++--- crates/ra_ide/src/references/rename.rs | 5 ++--- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) (limited to 'crates/ra_ide') 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() { diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 3fc972460..7d378f2d0 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -139,7 +139,7 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::RecordField(it) => decl_with_ascription(it), ast::Const(it) => decl_with_ascription(it), ast::Static(it) => decl_with_ascription(it), - ast::ImplDef(it) => { + ast::Impl(it) => { let target_type = it.target_type()?; let target_trait = it.target_trait(); let label = match target_trait { @@ -372,7 +372,7 @@ fn very_obsolete() {} label: "impl E", navigation_range: 239..240, node_range: 234..243, - kind: IMPL_DEF, + kind: IMPL, detail: None, deprecated: false, }, @@ -381,7 +381,7 @@ fn very_obsolete() {} label: "impl fmt::Debug for E", navigation_range: 265..266, node_range: 245..269, - kind: IMPL_DEF, + kind: IMPL, detail: None, deprecated: false, }, diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index d8ffb8c84..d330109f1 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -192,15 +192,14 @@ fn text_edit_from_self_param( self_param: &ast::SelfParam, new_name: &str, ) -> Option { - fn target_type_name(impl_def: &ast::ImplDef) -> Option { + fn target_type_name(impl_def: &ast::Impl) -> Option { if let Some(ast::TypeRef::PathType(p)) = impl_def.target_type() { return Some(p.path()?.segment()?.name_ref()?.text().to_string()); } None } - let impl_def = - find_node_at_offset::(syn, self_param.syntax().text_range().start())?; + let impl_def = find_node_at_offset::(syn, self_param.syntax().text_range().start())?; let type_name = target_type_name(&impl_def)?; let mut replacement_text = String::from(new_name); diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index a66453c04..e3a96f9d5 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -647,7 +647,7 @@ fn highlight_element( fn is_child_of_impl(element: &SyntaxElement) -> bool { match element.parent() { - Some(e) => e.kind() == IMPL_DEF, + Some(e) => e.kind() == IMPL, _ => false, } } -- cgit v1.2.3