From ec731e19df6444b2113c273fc740fd3d5c866b18 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 20 Mar 2021 23:55:16 +0200 Subject: Use smart case in flyimport items lookup --- crates/ide_db/src/items_locator.rs | 9 ++++++++- crates/ide_db/src/symbol_index.rs | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/items_locator.rs b/crates/ide_db/src/items_locator.rs index 518cddd74..b9d5852e2 100644 --- a/crates/ide_db/src/items_locator.rs +++ b/crates/ide_db/src/items_locator.rs @@ -62,6 +62,8 @@ pub fn items_with_name( (local_query, external_query) } NameToImport::Fuzzy(fuzzy_search_string) => { + let mut local_query = symbol_index::Query::new(fuzzy_search_string.clone()); + let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) .search_mode(import_map::SearchMode::Fuzzy) .name_only(); @@ -75,7 +77,12 @@ pub fn items_with_name( } } - (symbol_index::Query::new(fuzzy_search_string), external_query) + if fuzzy_search_string.to_lowercase() != fuzzy_search_string { + local_query.case_sensitive(); + external_query = external_query.case_sensitive(); + } + + (local_query, external_query) } }; diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs index 9ed9568ce..35e382b5c 100644 --- a/crates/ide_db/src/symbol_index.rs +++ b/crates/ide_db/src/symbol_index.rs @@ -52,6 +52,7 @@ pub struct Query { only_types: bool, libs: bool, exact: bool, + case_sensitive: bool, limit: usize, } @@ -64,6 +65,7 @@ impl Query { only_types: false, libs: false, exact: false, + case_sensitive: false, limit: usize::max_value(), } } @@ -80,6 +82,10 @@ impl Query { self.exact = true; } + pub fn case_sensitive(&mut self) { + self.case_sensitive = true; + } + pub fn limit(&mut self, limit: usize) { self.limit = limit } @@ -326,8 +332,14 @@ impl Query { if self.only_types && !symbol.kind.is_type() { continue; } - if self.exact && symbol.name != self.query { - continue; + if self.exact { + if symbol.name != self.query { + continue; + } + } else if self.case_sensitive { + if self.query.chars().any(|c| !symbol.name.contains(c)) { + continue; + } } res.push(symbol.clone()); -- cgit v1.2.3