From f62e8616c879255e70052ae35ce7f98bffedac11 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 18 Sep 2020 23:40:11 +0300 Subject: Add imports in auto completion --- crates/ide_db/src/imports_locator.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index df74be00b..e4f4b5427 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs @@ -1,12 +1,12 @@ //! This module contains an import search funcionality that is provided to the assists module. //! Later, this should be moved away to a separate crate that is accessible from the assists module. -use hir::{Crate, MacroDef, ModuleDef, Semantics}; +use hir::{Crate, MacroDef, ModuleDef, Query as ImportMapQuery, Semantics}; use syntax::{ast, AstNode, SyntaxKind::NAME}; use crate::{ defs::{Definition, NameClass}, - symbol_index::{self, FileSymbol, Query}, + symbol_index::{self, FileSymbol, Query as SymbolQuery}, RootDatabase, }; use either::Either; @@ -21,12 +21,16 @@ pub fn find_imports<'a>( let db = sema.db; // Query dependencies first. - let mut candidates: FxHashSet<_> = - krate.query_external_importables(db, name_to_import).collect(); + let mut candidates: FxHashSet<_> = krate + .query_external_importables( + db, + ImportMapQuery::new(name_to_import).anchor_end().case_sensitive().limit(40), + ) + .collect(); // Query the local crate using the symbol index. let local_results = { - let mut query = Query::new(name_to_import.to_string()); + let mut query = SymbolQuery::new(name_to_import.to_string()); query.exact(); query.limit(40); symbol_index::crate_symbols(db, krate.into(), query) -- cgit v1.2.3 From 4c8edd003aa447bd2da10fd81b24f582deacdc11 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 13 Nov 2020 19:16:56 +0200 Subject: Use imports_locator --- crates/ide_db/src/imports_locator.rs | 65 ++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 18 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index e4f4b5427..71fb7207b 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs @@ -1,40 +1,69 @@ //! This module contains an import search funcionality that is provided to the assists module. //! Later, this should be moved away to a separate crate that is accessible from the assists module. -use hir::{Crate, MacroDef, ModuleDef, Query as ImportMapQuery, Semantics}; +use hir::{Crate, ExternalImportablesQuery, MacroDef, ModuleDef, Semantics}; use syntax::{ast, AstNode, SyntaxKind::NAME}; use crate::{ defs::{Definition, NameClass}, - symbol_index::{self, FileSymbol, Query as SymbolQuery}, + symbol_index::{self, FileSymbol, Query as LocalImportablesQuery}, RootDatabase, }; use either::Either; use rustc_hash::FxHashSet; -pub fn find_imports<'a>( +pub fn find_exact_imports<'a>( sema: &Semantics<'a, RootDatabase>, krate: Crate, name_to_import: &str, -) -> Vec> { - let _p = profile::span("search_for_imports"); +) -> impl Iterator> { + let _p = profile::span("find_exact_imports"); + find_imports( + sema, + krate, + { + let mut local_query = LocalImportablesQuery::new(name_to_import.to_string()); + local_query.exact(); + local_query.limit(40); + local_query + }, + ExternalImportablesQuery::new(name_to_import).anchor_end().case_sensitive().limit(40), + ) +} + +pub fn find_similar_imports<'a>( + sema: &Semantics<'a, RootDatabase>, + krate: Crate, + name_to_import: &str, +) -> impl Iterator> { + let _p = profile::span("find_similar_imports"); + find_imports( + sema, + krate, + { + let mut local_query = LocalImportablesQuery::new(name_to_import.to_string()); + local_query.limit(40); + local_query + }, + ExternalImportablesQuery::new(name_to_import).limit(40), + ) +} + +fn find_imports<'a>( + sema: &Semantics<'a, RootDatabase>, + krate: Crate, + local_query: LocalImportablesQuery, + external_query: ExternalImportablesQuery, +) -> impl Iterator> { + let _p = profile::span("find_similar_imports"); let db = sema.db; // Query dependencies first. - let mut candidates: FxHashSet<_> = krate - .query_external_importables( - db, - ImportMapQuery::new(name_to_import).anchor_end().case_sensitive().limit(40), - ) - .collect(); + let mut candidates: FxHashSet<_> = + krate.query_external_importables(db, external_query).collect(); // Query the local crate using the symbol index. - let local_results = { - let mut query = SymbolQuery::new(name_to_import.to_string()); - query.exact(); - query.limit(40); - symbol_index::crate_symbols(db, krate.into(), query) - }; + let local_results = symbol_index::crate_symbols(db, krate.into(), local_query); candidates.extend( local_results @@ -47,7 +76,7 @@ pub fn find_imports<'a>( }), ); - candidates.into_iter().collect() + candidates.into_iter() } fn get_name_definition<'a>( -- cgit v1.2.3 From 46514448b740b82e4f5f9cf742c6f8c6caec1d38 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 13 Nov 2020 22:31:41 +0200 Subject: Tweak the search limits a bit --- crates/ide_db/src/imports_locator.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index 71fb7207b..1b21f76ac 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs @@ -35,6 +35,7 @@ pub fn find_similar_imports<'a>( sema: &Semantics<'a, RootDatabase>, krate: Crate, name_to_import: &str, + limit: usize, ) -> impl Iterator> { let _p = profile::span("find_similar_imports"); find_imports( @@ -42,10 +43,10 @@ pub fn find_similar_imports<'a>( krate, { let mut local_query = LocalImportablesQuery::new(name_to_import.to_string()); - local_query.limit(40); + local_query.limit(limit); local_query }, - ExternalImportablesQuery::new(name_to_import).limit(40), + ExternalImportablesQuery::new(name_to_import).limit(limit), ) } -- cgit v1.2.3 From 410996893489f6c64b472e6128f099f1de229806 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 16 Nov 2020 21:24:54 +0200 Subject: Remove query aliases --- crates/ide_db/src/imports_locator.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index 1b21f76ac..9d8ea7368 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs @@ -1,12 +1,12 @@ //! This module contains an import search funcionality that is provided to the assists module. //! Later, this should be moved away to a separate crate that is accessible from the assists module. -use hir::{Crate, ExternalImportablesQuery, MacroDef, ModuleDef, Semantics}; +use hir::{import_map, Crate, MacroDef, ModuleDef, Semantics}; use syntax::{ast, AstNode, SyntaxKind::NAME}; use crate::{ defs::{Definition, NameClass}, - symbol_index::{self, FileSymbol, Query as LocalImportablesQuery}, + symbol_index::{self, FileSymbol}, RootDatabase, }; use either::Either; @@ -22,12 +22,12 @@ pub fn find_exact_imports<'a>( sema, krate, { - let mut local_query = LocalImportablesQuery::new(name_to_import.to_string()); + let mut local_query = symbol_index::Query::new(name_to_import.to_string()); local_query.exact(); local_query.limit(40); local_query }, - ExternalImportablesQuery::new(name_to_import).anchor_end().case_sensitive().limit(40), + import_map::Query::new(name_to_import).anchor_end().case_sensitive().limit(40), ) } @@ -42,19 +42,19 @@ pub fn find_similar_imports<'a>( sema, krate, { - let mut local_query = LocalImportablesQuery::new(name_to_import.to_string()); + let mut local_query = symbol_index::Query::new(name_to_import.to_string()); local_query.limit(limit); local_query }, - ExternalImportablesQuery::new(name_to_import).limit(limit), + import_map::Query::new(name_to_import).limit(limit), ) } fn find_imports<'a>( sema: &Semantics<'a, RootDatabase>, krate: Crate, - local_query: LocalImportablesQuery, - external_query: ExternalImportablesQuery, + local_query: symbol_index::Query, + external_query: import_map::Query, ) -> impl Iterator> { let _p = profile::span("find_similar_imports"); let db = sema.db; -- cgit v1.2.3