From 71f6d58e310af0f67fba8bb9f59ea9777ecf24d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 May 2020 15:07:09 +0200 Subject: Remove unnecessary condition No tests fail, and quick manual testing shows that there are no false-positives. In general, each completion contributor should be independent from the others. --- crates/ra_ide/src/completion.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs index a0e06faa2..8bdc43b1a 100644 --- a/crates/ra_ide/src/completion.rs +++ b/crates/ra_ide/src/completion.rs @@ -65,23 +65,20 @@ pub(crate) fn completions( let ctx = CompletionContext::new(db, position, config)?; let mut acc = Completions::default(); - if ctx.attribute_under_caret.is_some() { - complete_attribute::complete_attribute(&mut acc, &ctx); - } else { - complete_fn_param::complete_fn_param(&mut acc, &ctx); - complete_keyword::complete_expr_keyword(&mut acc, &ctx); - complete_keyword::complete_use_tree_keyword(&mut acc, &ctx); - complete_snippet::complete_expr_snippet(&mut acc, &ctx); - complete_snippet::complete_item_snippet(&mut acc, &ctx); - complete_qualified_path::complete_qualified_path(&mut acc, &ctx); - complete_unqualified_path::complete_unqualified_path(&mut acc, &ctx); - complete_dot::complete_dot(&mut acc, &ctx); - complete_record::complete_record(&mut acc, &ctx); - complete_pattern::complete_pattern(&mut acc, &ctx); - complete_postfix::complete_postfix(&mut acc, &ctx); - complete_macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx); - complete_trait_impl::complete_trait_impl(&mut acc, &ctx); - } + complete_attribute::complete_attribute(&mut acc, &ctx); + complete_fn_param::complete_fn_param(&mut acc, &ctx); + complete_keyword::complete_expr_keyword(&mut acc, &ctx); + complete_keyword::complete_use_tree_keyword(&mut acc, &ctx); + complete_snippet::complete_expr_snippet(&mut acc, &ctx); + complete_snippet::complete_item_snippet(&mut acc, &ctx); + complete_qualified_path::complete_qualified_path(&mut acc, &ctx); + complete_unqualified_path::complete_unqualified_path(&mut acc, &ctx); + complete_dot::complete_dot(&mut acc, &ctx); + complete_record::complete_record(&mut acc, &ctx); + complete_pattern::complete_pattern(&mut acc, &ctx); + complete_postfix::complete_postfix(&mut acc, &ctx); + complete_macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx); + complete_trait_impl::complete_trait_impl(&mut acc, &ctx); Some(acc) } -- cgit v1.2.3 From e9643ab74ca2559d38085a38f7d351991c896abb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 May 2020 15:07:51 +0200 Subject: Cleanup imports --- crates/ra_ide/src/completion/complete_attribute.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs index 20e6edc17..4eaaa0b6f 100644 --- a/crates/ra_ide/src/completion/complete_attribute.rs +++ b/crates/ra_ide/src/completion/complete_attribute.rs @@ -3,15 +3,17 @@ //! This module uses a bit of static metadata to provide completions //! for built-in attributes. -use super::completion_context::CompletionContext; -use super::completion_item::{CompletionItem, CompletionItemKind, CompletionKind, Completions}; -use ast::AttrInput; use ra_syntax::{ - ast::{self, AttrKind}, + ast::{self, AttrInput, AttrKind}, AstNode, SyntaxKind, }; use rustc_hash::FxHashSet; +use crate::completion::{ + completion_context::CompletionContext, + completion_item::{CompletionItem, CompletionItemKind, CompletionKind, Completions}, +}; + pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { let attribute = ctx.attribute_under_caret.as_ref()?; -- cgit v1.2.3 From 8f4478390e29f34c5530a25bd0338b689218677f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 May 2020 15:08:51 +0200 Subject: Qualify ast types --- crates/ra_ide/src/completion/complete_attribute.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs index 4eaaa0b6f..f17266221 100644 --- a/crates/ra_ide/src/completion/complete_attribute.rs +++ b/crates/ra_ide/src/completion/complete_attribute.rs @@ -3,10 +3,7 @@ //! This module uses a bit of static metadata to provide completions //! for built-in attributes. -use ra_syntax::{ - ast::{self, AttrInput, AttrKind}, - AstNode, SyntaxKind, -}; +use ra_syntax::{ast, AstNode, SyntaxKind}; use rustc_hash::FxHashSet; use crate::completion::{ @@ -18,7 +15,9 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) let attribute = ctx.attribute_under_caret.as_ref()?; match (attribute.path(), attribute.input()) { - (Some(path), Some(AttrInput::TokenTree(token_tree))) if path.to_string() == "derive" => { + (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) + if path.to_string() == "derive" => + { complete_derive(acc, ctx, token_tree) } _ => complete_attribute_start(acc, ctx, attribute), @@ -42,7 +41,7 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr _ => {} } - if attribute.kind() == AttrKind::Inner || !attr_completion.should_be_inner { + if attribute.kind() == ast::AttrKind::Inner || !attr_completion.should_be_inner { acc.add(item); } } -- cgit v1.2.3