From 2987e05f158207f63e2bc4ac87c0c2fbb7e61002 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 7 Jun 2021 20:45:17 +0200 Subject: simplify --- crates/ide_completion/src/completions/trait_impl.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'crates/ide_completion/src/completions/trait_impl.rs') diff --git a/crates/ide_completion/src/completions/trait_impl.rs b/crates/ide_completion/src/completions/trait_impl.rs index 968c0254d..a60e5f43c 100644 --- a/crates/ide_completion/src/completions/trait_impl.rs +++ b/crates/ide_completion/src/completions/trait_impl.rs @@ -34,20 +34,13 @@ use hir::{self, HasAttrs, HasSource}; use ide_db::{traits::get_missing_assoc_items, SymbolKind}; use syntax::{ - ast::{self, edit, Impl}, + ast::{self, edit}, display::function_declaration, - AstNode, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, T, + AstNode, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, T, }; use text_edit::TextEdit; -use crate::{ - CompletionContext, - CompletionItem, - CompletionItemKind, - CompletionKind, - Completions, - // display::function_declaration, -}; +use crate::{CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions}; #[derive(Debug, PartialEq, Eq)] enum ImplCompletionKind { @@ -58,7 +51,7 @@ enum ImplCompletionKind { } pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) { - if let Some((kind, trigger, impl_def)) = completion_match(ctx) { + if let Some((kind, trigger, impl_def)) = completion_match(ctx.token.clone()) { get_missing_assoc_items(&ctx.sema, &impl_def).into_iter().for_each(|item| match item { hir::AssocItem::Function(fn_item) if kind == ImplCompletionKind::All || kind == ImplCompletionKind::Fn => @@ -80,8 +73,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } } -fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, SyntaxNode, Impl)> { - let mut token = ctx.token.clone(); +fn completion_match(mut token: SyntaxToken) -> Option<(ImplCompletionKind, SyntaxNode, ast::Impl)> { // For keyword without name like `impl .. { fn $0 }`, the current position is inside // the whitespace token, which is outside `FN` syntax node. // We need to follow the previous token in this case. -- cgit v1.2.3