From db335a1bbf1d1bea2c761f67efb4b49831738e31 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 5 Jan 2021 10:34:03 +0200 Subject: Add flyimport completion for trait assoc items --- crates/completion/src/completions/flyimport.rs | 300 ++++++++++++++++++++++--- crates/completion/src/config.rs | 2 +- crates/completion/src/item.rs | 23 +- crates/completion/src/lib.rs | 3 +- crates/completion/src/render.rs | 22 +- crates/completion/src/test_utils.rs | 2 +- 6 files changed, 296 insertions(+), 56 deletions(-) (limited to 'crates/completion') diff --git a/crates/completion/src/completions/flyimport.rs b/crates/completion/src/completions/flyimport.rs index 222809638..9101e405c 100644 --- a/crates/completion/src/completions/flyimport.rs +++ b/crates/completion/src/completions/flyimport.rs @@ -45,9 +45,8 @@ //! Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corredponding //! capability enabled. -use either::Either; use hir::{ModPath, ScopeDef}; -use ide_db::{helpers::insert_use::ImportScope, imports_locator}; +use ide_db::helpers::{import_assets::ImportAssets, insert_use::ImportScope}; use syntax::AstNode; use test_utils::mark; @@ -60,7 +59,7 @@ use crate::{ use super::Completions; pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { - if !ctx.config.enable_autoimport_completions { + if !ctx.config.enable_imports_on_the_fly { return None; } if ctx.attribute_under_caret.is_some() || ctx.mod_declaration_under_caret.is_some() { @@ -72,46 +71,56 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) } let _p = profile::span("import_on_the_fly").detail(|| potential_import_name.to_string()); - let current_module = ctx.scope.module()?; - let anchor = ctx.name_ref_syntax.as_ref()?; - let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; - + let import_scope = + ImportScope::find_insert_use_container(ctx.name_ref_syntax.as_ref()?.syntax(), &ctx.sema)?; let user_input_lowercased = potential_import_name.to_lowercase(); - let mut all_mod_paths = imports_locator::find_similar_imports( - &ctx.sema, - ctx.krate?, - Some(40), - potential_import_name, - true, - true, - ) - .filter_map(|import_candidate| { - Some(match import_candidate { - Either::Left(module_def) => { - (current_module.find_use_path(ctx.db, module_def)?, ScopeDef::ModuleDef(module_def)) - } - Either::Right(macro_def) => { - (current_module.find_use_path(ctx.db, macro_def)?, ScopeDef::MacroDef(macro_def)) - } + let mut all_mod_paths = import_assets(ctx, potential_import_name)? + .search_for_relative_paths(&ctx.sema) + .into_iter() + .map(|(mod_path, item_in_ns)| { + let scope_item = match item_in_ns { + hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), + hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), + hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), + }; + (mod_path, scope_item) }) - }) - .filter(|(mod_path, _)| mod_path.len() > 1) - .collect::>(); - + .collect::>(); all_mod_paths.sort_by_cached_key(|(mod_path, _)| { compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased) }); acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| { - render_resolution_with_import( - RenderContext::new(ctx), - ImportEdit { import_path, import_scope: import_scope.clone() }, - &definition, - ) + let import_for_trait_assoc_item = match definition { + ScopeDef::ModuleDef(module_def) => module_def + .as_assoc_item(ctx.db) + .and_then(|assoc| assoc.containing_trait(ctx.db)) + .is_some(), + _ => false, + }; + let import_edit = ImportEdit { + import_path, + import_scope: import_scope.clone(), + import_for_trait_assoc_item, + }; + render_resolution_with_import(RenderContext::new(ctx), import_edit, &definition) })); Some(()) } +fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option { + let current_module = ctx.scope.module()?; + if let Some(dot_receiver) = &ctx.dot_receiver { + ImportAssets::for_fuzzy_method_call( + current_module, + ctx.sema.type_of_expr(dot_receiver)?, + fuzzy_name, + ) + } else { + ImportAssets::for_fuzzy_path(current_module, ctx.path_qual.clone(), fuzzy_name, &ctx.sema) + } +} + fn compute_fuzzy_completion_order_key( proposed_mod_path: &ModPath, user_input_lowercased: &str, @@ -258,6 +267,176 @@ fn main() { ); } + #[test] + fn trait_function_fuzzy_completion() { + let fixture = r#" + //- /lib.rs crate:dep + pub mod test_mod { + pub trait TestTrait { + const SPECIAL_CONST: u8; + type HumbleType; + fn weird_function(); + fn random_method(&self); + } + pub struct TestStruct {} + impl TestTrait for TestStruct { + const SPECIAL_CONST: u8 = 42; + type HumbleType = (); + fn weird_function() {} + fn random_method(&self) {} + } + } + + //- /main.rs crate:main deps:dep + fn main() { + dep::test_mod::TestStruct::wei$0 + } + "#; + + check( + fixture, + expect![[r#" + fn weird_function() (dep::test_mod::TestTrait) fn weird_function() + "#]], + ); + + check_edit( + "weird_function", + fixture, + r#" +use dep::test_mod::TestTrait; + +fn main() { + dep::test_mod::TestStruct::weird_function()$0 +} +"#, + ); + } + + #[test] + fn trait_const_fuzzy_completion() { + let fixture = r#" + //- /lib.rs crate:dep + pub mod test_mod { + pub trait TestTrait { + const SPECIAL_CONST: u8; + type HumbleType; + fn weird_function(); + fn random_method(&self); + } + pub struct TestStruct {} + impl TestTrait for TestStruct { + const SPECIAL_CONST: u8 = 42; + type HumbleType = (); + fn weird_function() {} + fn random_method(&self) {} + } + } + + //- /main.rs crate:main deps:dep + fn main() { + dep::test_mod::TestStruct::spe$0 + } + "#; + + check( + fixture, + expect![[r#" + ct SPECIAL_CONST (dep::test_mod::TestTrait) + "#]], + ); + + check_edit( + "SPECIAL_CONST", + fixture, + r#" +use dep::test_mod::TestTrait; + +fn main() { + dep::test_mod::TestStruct::SPECIAL_CONST +} +"#, + ); + } + + #[test] + fn trait_method_fuzzy_completion() { + let fixture = r#" + //- /lib.rs crate:dep + pub mod test_mod { + pub trait TestTrait { + const SPECIAL_CONST: u8; + type HumbleType; + fn weird_function(); + fn random_method(&self); + } + pub struct TestStruct {} + impl TestTrait for TestStruct { + const SPECIAL_CONST: u8 = 42; + type HumbleType = (); + fn weird_function() {} + fn random_method(&self) {} + } + } + + //- /main.rs crate:main deps:dep + fn main() { + let test_struct = dep::test_mod::TestStruct {}; + test_struct.ran$0 + } + "#; + + check( + fixture, + expect![[r#" + me random_method() (dep::test_mod::TestTrait) fn random_method(&self) + "#]], + ); + + check_edit( + "random_method", + fixture, + r#" +use dep::test_mod::TestTrait; + +fn main() { + let test_struct = dep::test_mod::TestStruct {}; + test_struct.random_method()$0 +} +"#, + ); + } + + #[test] + fn no_trait_type_fuzzy_completion() { + check( + r#" +//- /lib.rs crate:dep +pub mod test_mod { + pub trait TestTrait { + const SPECIAL_CONST: u8; + type HumbleType; + fn weird_function(); + fn random_method(&self); + } + pub struct TestStruct {} + impl TestTrait for TestStruct { + const SPECIAL_CONST: u8 = 42; + type HumbleType = (); + fn weird_function() {} + fn random_method(&self) {} + } +} + +//- /main.rs crate:main deps:dep +fn main() { + dep::test_mod::TestStruct::hum$0 +} +"#, + expect![[r#""#]], + ); + } + #[test] fn does_not_propose_names_in_scope() { check( @@ -288,4 +467,61 @@ fn main() { expect![[r#""#]], ); } + + #[test] + fn does_not_propose_traits_in_scope() { + check( + r#" +//- /lib.rs crate:dep +pub mod test_mod { + pub trait TestTrait { + const SPECIAL_CONST: u8; + type HumbleType; + fn weird_function(); + fn random_method(&self); + } + pub struct TestStruct {} + impl TestTrait for TestStruct { + const SPECIAL_CONST: u8 = 42; + type HumbleType = (); + fn weird_function() {} + fn random_method(&self) {} + } +} + +//- /main.rs crate:main deps:dep +use dep::test_mod::{TestStruct, TestTrait}; +fn main() { + dep::test_mod::TestStruct::hum$0 +} +"#, + expect![[r#""#]], + ); + } + + #[test] + fn blanket_trait_impl_import() { + check( + r#" +//- /lib.rs crate:dep +pub mod test_mod { + pub struct TestStruct {} + pub trait TestTrait { + fn another_function(); + } + impl TestTrait for T { + fn another_function() {} + } +} + +//- /main.rs crate:main deps:dep +fn main() { + dep::test_mod::TestStruct::ano$0 +} +"#, + expect![[r#" + fn another_function() (dep::test_mod::TestTrait) fn another_function() + "#]], + ); + } } diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs index 58fc700f3..d70ed6c1c 100644 --- a/crates/completion/src/config.rs +++ b/crates/completion/src/config.rs @@ -9,7 +9,7 @@ use ide_db::helpers::{insert_use::InsertUseConfig, SnippetCap}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct CompletionConfig { pub enable_postfix_completions: bool, - pub enable_autoimport_completions: bool, + pub enable_imports_on_the_fly: bool, pub add_call_parenthesis: bool, pub add_call_argument_snippets: bool, pub snippet_cap: Option, diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index 0134ff219..378bd2c70 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs @@ -270,6 +270,7 @@ impl CompletionItem { pub struct ImportEdit { pub import_path: ModPath, pub import_scope: ImportScope, + pub import_for_trait_assoc_item: bool, } impl ImportEdit { @@ -321,17 +322,19 @@ impl Builder { let mut insert_text = self.insert_text; if let Some(import_to_add) = self.import_to_add.as_ref() { - let mut import_path_without_last_segment = import_to_add.import_path.to_owned(); - let _ = import_path_without_last_segment.segments.pop(); - - if !import_path_without_last_segment.segments.is_empty() { - if lookup.is_none() { - lookup = Some(label.clone()); - } - if insert_text.is_none() { - insert_text = Some(label.clone()); + if import_to_add.import_for_trait_assoc_item { + lookup = lookup.or_else(|| Some(label.clone())); + insert_text = insert_text.or_else(|| Some(label.clone())); + label = format!("{} ({})", label, import_to_add.import_path); + } else { + let mut import_path_without_last_segment = import_to_add.import_path.to_owned(); + let _ = import_path_without_last_segment.segments.pop(); + + if !import_path_without_last_segment.segments.is_empty() { + lookup = lookup.or_else(|| Some(label.clone())); + insert_text = insert_text.or_else(|| Some(label.clone())); + label = format!("{}::{}", import_path_without_last_segment, label); } - label = format!("{}::{}", import_path_without_last_segment, label); } } diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index ee1b822e7..56ec13e8c 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs @@ -139,6 +139,7 @@ pub fn resolve_completion_edits( position: FilePosition, full_import_path: &str, imported_name: String, + import_for_trait_assoc_item: bool, ) -> Option> { let ctx = CompletionContext::new(db, position, config)?; let anchor = ctx.name_ref_syntax.as_ref()?; @@ -154,7 +155,7 @@ pub fn resolve_completion_edits( }) .find(|mod_path| mod_path.to_string() == full_import_path)?; - ImportEdit { import_path, import_scope } + ImportEdit { import_path, import_scope, import_for_trait_assoc_item } .to_text_edit(config.insert_use.merge) .map(|edit| vec![edit]) } diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index 820dd01d1..4b3c9702a 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -10,7 +10,7 @@ pub(crate) mod type_alias; mod builder_ext; -use hir::{Documentation, HasAttrs, HirDisplay, Mutability, ScopeDef, Type}; +use hir::{Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type}; use ide_db::{helpers::SnippetCap, RootDatabase}; use syntax::TextRange; use test_utils::mark; @@ -51,16 +51,16 @@ pub(crate) fn render_resolution_with_import<'a>( import_edit: ImportEdit, resolution: &ScopeDef, ) -> Option { - Render::new(ctx) - .render_resolution( - import_edit.import_path.segments.last()?.to_string(), - Some(import_edit), - resolution, - ) - .map(|mut item| { - item.completion_kind = CompletionKind::Magic; - item - }) + let local_name = match resolution { + ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(), + ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(), + ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(), + _ => import_edit.import_path.segments.last()?.to_string(), + }; + Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| { + item.completion_kind = CompletionKind::Magic; + item + }) } /// Interface for data and methods required for items rendering. diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs index 6ea6da989..3faf861b9 100644 --- a/crates/completion/src/test_utils.rs +++ b/crates/completion/src/test_utils.rs @@ -18,7 +18,7 @@ use crate::{item::CompletionKind, CompletionConfig, CompletionItem}; pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig { enable_postfix_completions: true, - enable_autoimport_completions: true, + enable_imports_on_the_fly: true, add_call_parenthesis: true, add_call_argument_snippets: true, snippet_cap: SnippetCap::new(true), -- cgit v1.2.3 From 68626e4ef5acfea05812b68f41efa2bcd5bea448 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 17 Jan 2021 00:53:15 +0200 Subject: Draft the working completion --- crates/completion/src/completions/flyimport.rs | 149 +++++++++++++++++++++++-- 1 file changed, 138 insertions(+), 11 deletions(-) (limited to 'crates/completion') diff --git a/crates/completion/src/completions/flyimport.rs b/crates/completion/src/completions/flyimport.rs index 9101e405c..a40843669 100644 --- a/crates/completion/src/completions/flyimport.rs +++ b/crates/completion/src/completions/flyimport.rs @@ -20,11 +20,14 @@ //! # pub mod std { pub mod marker { pub struct PhantomData { } } } //! ``` //! +//! Also completes associated items, that require trait imports. +//! //! .Fuzzy search details //! //! To avoid an excessive amount of the results returned, completion input is checked for inclusion in the names only //! (i.e. in `HashMap` in the `std::collections::HashMap` path). -//! For the same reasons, avoids searching for any imports for inputs with their length less that 2 symbols. +//! For the same reasons, avoids searching for any path imports for inputs with their length less that 2 symbols +//! (but shows all associated items for any input length). //! //! .Import configuration //! @@ -46,8 +49,11 @@ //! capability enabled. use hir::{ModPath, ScopeDef}; -use ide_db::helpers::{import_assets::ImportAssets, insert_use::ImportScope}; -use syntax::AstNode; +use ide_db::helpers::{ + import_assets::{ImportAssets, ImportCandidate}, + insert_use::ImportScope, +}; +use syntax::{AstNode, SyntaxNode, T}; use test_utils::mark; use crate::{ @@ -65,16 +71,24 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) if ctx.attribute_under_caret.is_some() || ctx.mod_declaration_under_caret.is_some() { return None; } - let potential_import_name = ctx.token.to_string(); - if potential_import_name.len() < 2 { - return None; - } + let potential_import_name = { + let token_kind = ctx.token.kind(); + if token_kind == T![.] || token_kind == T![::] { + String::new() + } else { + ctx.token.to_string() + } + }; + let _p = profile::span("import_on_the_fly").detail(|| potential_import_name.to_string()); - let import_scope = - ImportScope::find_insert_use_container(ctx.name_ref_syntax.as_ref()?.syntax(), &ctx.sema)?; let user_input_lowercased = potential_import_name.to_lowercase(); - let mut all_mod_paths = import_assets(ctx, potential_import_name)? + let import_assets = import_assets(ctx, potential_import_name)?; + let import_scope = ImportScope::find_insert_use_container( + position_for_import(ctx, import_assets.import_candidate())?, + &ctx.sema, + )?; + let mut all_mod_paths = import_assets .search_for_relative_paths(&ctx.sema) .into_iter() .map(|(mod_path, item_in_ns)| { @@ -108,6 +122,17 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) Some(()) } +fn position_for_import<'a>( + ctx: &'a CompletionContext, + import_candidate: &ImportCandidate, +) -> Option<&'a SyntaxNode> { + Some(match import_candidate { + ImportCandidate::Path(_) => ctx.name_ref_syntax.as_ref()?.syntax(), + ImportCandidate::TraitAssocItem(_) => ctx.path_qual.as_ref()?.syntax(), + ImportCandidate::TraitMethod(_) => ctx.dot_receiver.as_ref()?.syntax(), + }) +} + fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option { let current_module = ctx.scope.module()?; if let Some(dot_receiver) = &ctx.dot_receiver { @@ -117,7 +142,22 @@ fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option Date: Sun, 17 Jan 2021 02:52:36 +0200 Subject: Properly resolve completion edits for empty input --- crates/completion/src/completions/flyimport.rs | 73 +++++++++++++++----------- crates/completion/src/lib.rs | 8 +-- 2 files changed, 46 insertions(+), 35 deletions(-) (limited to 'crates/completion') diff --git a/crates/completion/src/completions/flyimport.rs b/crates/completion/src/completions/flyimport.rs index a40843669..5c04d5c41 100644 --- a/crates/completion/src/completions/flyimport.rs +++ b/crates/completion/src/completions/flyimport.rs @@ -85,7 +85,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) let user_input_lowercased = potential_import_name.to_lowercase(); let import_assets = import_assets(ctx, potential_import_name)?; let import_scope = ImportScope::find_insert_use_container( - position_for_import(ctx, import_assets.import_candidate())?, + position_for_import(ctx, Some(import_assets.import_candidate()))?, &ctx.sema, )?; let mut all_mod_paths = import_assets @@ -122,14 +122,20 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) Some(()) } -fn position_for_import<'a>( +pub(crate) fn position_for_import<'a>( ctx: &'a CompletionContext, - import_candidate: &ImportCandidate, + import_candidate: Option<&ImportCandidate>, ) -> Option<&'a SyntaxNode> { Some(match import_candidate { - ImportCandidate::Path(_) => ctx.name_ref_syntax.as_ref()?.syntax(), - ImportCandidate::TraitAssocItem(_) => ctx.path_qual.as_ref()?.syntax(), - ImportCandidate::TraitMethod(_) => ctx.dot_receiver.as_ref()?.syntax(), + Some(ImportCandidate::Path(_)) => ctx.name_ref_syntax.as_ref()?.syntax(), + Some(ImportCandidate::TraitAssocItem(_)) => ctx.path_qual.as_ref()?.syntax(), + Some(ImportCandidate::TraitMethod(_)) => ctx.dot_receiver.as_ref()?.syntax(), + None => ctx + .name_ref_syntax + .as_ref() + .map(|name_ref| name_ref.syntax()) + .or_else(|| ctx.path_qual.as_ref().map(|path| path.syntax())) + .or_else(|| ctx.dot_receiver.as_ref().map(|expr| expr.syntax()))?, }) } @@ -565,7 +571,8 @@ fn main() { #[test] fn blanket_trait_impl_import() { - check( + check_edit( + "another_function", r#" //- /lib.rs crate:dep pub mod test_mod { @@ -583,9 +590,13 @@ fn main() { dep::test_mod::TestStruct::ano$0 } "#, - expect![[r#" - fn another_function() (dep::test_mod::TestTrait) fn another_function() - "#]], + r#" +use dep::test_mod::TestTrait; + +fn main() { + dep::test_mod::TestStruct::another_function()$0 +} +"#, ); } @@ -593,28 +604,28 @@ fn main() { fn zero_input_assoc_item_completion() { check( r#" - //- /lib.rs crate:dep - pub mod test_mod { - pub trait TestTrait { - const SPECIAL_CONST: u8; - type HumbleType; - fn weird_function(); - fn random_method(&self); - } - pub struct TestStruct {} - impl TestTrait for TestStruct { - const SPECIAL_CONST: u8 = 42; - type HumbleType = (); - fn weird_function() {} - fn random_method(&self) {} - } - } +//- /lib.rs crate:dep +pub mod test_mod { + pub trait TestTrait { + const SPECIAL_CONST: u8; + type HumbleType; + fn weird_function(); + fn random_method(&self); + } + pub struct TestStruct {} + impl TestTrait for TestStruct { + const SPECIAL_CONST: u8 = 42; + type HumbleType = (); + fn weird_function() {} + fn random_method(&self) {} + } +} - //- /main.rs crate:main deps:dep - fn main() { - let test_struct = dep::test_mod::TestStruct {}; - test_struct.$0 - } +//- /main.rs crate:main deps:dep +fn main() { + let test_struct = dep::test_mod::TestStruct {}; + test_struct.$0 +} "#, expect![[r#" me random_method() (dep::test_mod::TestTrait) fn random_method(&self) diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index 56ec13e8c..2c4e54524 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs @@ -11,10 +11,10 @@ mod render; mod completions; +use completions::flyimport::position_for_import; use ide_db::{ base_db::FilePosition, helpers::insert_use::ImportScope, imports_locator, RootDatabase, }; -use syntax::AstNode; use text_edit::TextEdit; use crate::{completions::Completions, context::CompletionContext, item::CompletionKind}; @@ -142,10 +142,10 @@ pub fn resolve_completion_edits( import_for_trait_assoc_item: bool, ) -> Option> { let ctx = CompletionContext::new(db, position, config)?; - let anchor = ctx.name_ref_syntax.as_ref()?; - let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; + let position_for_import = position_for_import(&ctx, None)?; + let import_scope = ImportScope::find_insert_use_container(position_for_import, &ctx.sema)?; - let current_module = ctx.sema.scope(anchor.syntax()).module()?; + let current_module = ctx.sema.scope(position_for_import).module()?; let current_crate = current_module.krate(); let import_path = imports_locator::find_exact_imports(&ctx.sema, current_crate, imported_name) -- cgit v1.2.3 From f01cfe911410a2f35f95ec1e7befb51d51a5343e Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 18 Jan 2021 21:20:02 +0200 Subject: Small token fix Co-authored-by: Aleksey Kladov --- crates/completion/src/completions/flyimport.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/completion') diff --git a/crates/completion/src/completions/flyimport.rs b/crates/completion/src/completions/flyimport.rs index 5c04d5c41..47e797ac8 100644 --- a/crates/completion/src/completions/flyimport.rs +++ b/crates/completion/src/completions/flyimport.rs @@ -73,7 +73,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) } let potential_import_name = { let token_kind = ctx.token.kind(); - if token_kind == T![.] || token_kind == T![::] { + if matches!(token_kind, T![.] | T![::]) { String::new() } else { ctx.token.to_string() -- cgit v1.2.3