Unnamed repository; edit this file 'description' to name the repository.
Remove `name_only` from import map query
Ryo Yoshida 2023-06-30
parent f96442a · commit 97b725e
-rw-r--r--crates/hir-def/src/import_map.rs32
-rw-r--r--crates/ide-db/src/items_locator.rs8
2 files changed, 10 insertions, 30 deletions
diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs
index ec150dc068..1124302182 100644
--- a/crates/hir-def/src/import_map.rs
+++ b/crates/hir-def/src/import_map.rs
@@ -318,7 +318,6 @@ pub enum SearchMode {
pub struct Query {
query: String,
lowercased: String,
- name_only: bool,
assoc_items_only: bool,
search_mode: SearchMode,
case_sensitive: bool,
@@ -332,7 +331,6 @@ impl Query {
Self {
query,
lowercased,
- name_only: false,
assoc_items_only: false,
search_mode: SearchMode::Contains,
case_sensitive: false,
@@ -341,13 +339,6 @@ impl Query {
}
}
- /// Matches entries' names only, ignoring the rest of
- /// the qualifier.
- /// Example: for `std::marker::PhantomData`, the name is `PhantomData`.
- pub fn name_only(self) -> Self {
- Self { name_only: true, ..self }
- }
-
/// Matches only the entries that are associated items, ignoring the rest.
pub fn assoc_items_only(self) -> Self {
Self { assoc_items_only: true, ..self }
@@ -389,17 +380,13 @@ impl Query {
return false;
}
- let mut input = if import.is_trait_assoc_item || self.name_only {
- import.path.segments.last().unwrap().display(db.upcast()).to_string()
- } else {
- import.path.display(db).to_string()
- };
- if enforce_lowercase || !self.case_sensitive {
+ let mut input = import.path.segments.last().unwrap().display(db.upcast()).to_string();
+ let case_insensitive = enforce_lowercase || !self.case_sensitive;
+ if case_insensitive {
input.make_ascii_lowercase();
}
- let query_string =
- if !enforce_lowercase && self.case_sensitive { &self.query } else { &self.lowercased };
+ let query_string = if case_insensitive { &self.lowercased } else { &self.query };
match self.search_mode {
SearchMode::Equals => &input == query_string,
@@ -875,7 +862,6 @@ mod tests {
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
expect![[r#"
dep::fmt (t)
- dep::fmt::Display (t)
dep::fmt::Display::FMT_CONST (a)
dep::fmt::Display::format_function (a)
dep::fmt::Display::format_method (a)
@@ -917,9 +903,8 @@ mod tests {
.search_mode(SearchMode::Fuzzy)
.exclude_import_kind(ImportKind::AssociatedItem),
expect![[r#"
- dep::fmt (t)
- dep::fmt::Display (t)
- "#]],
+ dep::fmt (t)
+ "#]],
);
check_search(
@@ -968,7 +953,6 @@ mod tests {
dep::Fmt (t)
dep::Fmt (v)
dep::fmt (t)
- dep::fmt::Display (t)
dep::fmt::Display::fmt (a)
dep::format (f)
"#]],
@@ -996,7 +980,6 @@ mod tests {
dep::Fmt (t)
dep::Fmt (v)
dep::fmt (t)
- dep::fmt::Display (t)
dep::fmt::Display::fmt (a)
"#]],
);
@@ -1037,7 +1020,6 @@ mod tests {
dep::Fmt (t)
dep::Fmt (v)
dep::fmt (t)
- dep::fmt::Display (t)
dep::fmt::Display::fmt (a)
"#]],
);
@@ -1045,7 +1027,7 @@ mod tests {
check_search(
ra_fixture,
"main",
- Query::new("fmt".to_string()).name_only(),
+ Query::new("fmt".to_string()),
expect![[r#"
dep::Fmt (m)
dep::Fmt (t)
diff --git a/crates/ide-db/src/items_locator.rs b/crates/ide-db/src/items_locator.rs
index 46f1353e2e..5ba6df3694 100644
--- a/crates/ide-db/src/items_locator.rs
+++ b/crates/ide-db/src/items_locator.rs
@@ -48,9 +48,8 @@ pub fn items_with_name<'a>(
let mut local_query = symbol_index::Query::new(exact_name.clone());
local_query.exact();
- let external_query = import_map::Query::new(exact_name)
- .name_only()
- .search_mode(import_map::SearchMode::Equals);
+ let external_query =
+ import_map::Query::new(exact_name).search_mode(import_map::SearchMode::Equals);
(
local_query,
@@ -61,8 +60,7 @@ pub fn items_with_name<'a>(
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();
+ .search_mode(import_map::SearchMode::Fuzzy);
match assoc_item_search {
AssocItemSearch::Include => {}
AssocItemSearch::Exclude => {