mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Remove name_only
from import map query
This commit is contained in:
parent
f96442aa90
commit
97b725e269
@ -318,7 +318,6 @@ pub enum SearchMode {
|
|||||||
pub struct Query {
|
pub struct Query {
|
||||||
query: String,
|
query: String,
|
||||||
lowercased: String,
|
lowercased: String,
|
||||||
name_only: bool,
|
|
||||||
assoc_items_only: bool,
|
assoc_items_only: bool,
|
||||||
search_mode: SearchMode,
|
search_mode: SearchMode,
|
||||||
case_sensitive: bool,
|
case_sensitive: bool,
|
||||||
@ -332,7 +331,6 @@ impl Query {
|
|||||||
Self {
|
Self {
|
||||||
query,
|
query,
|
||||||
lowercased,
|
lowercased,
|
||||||
name_only: false,
|
|
||||||
assoc_items_only: false,
|
assoc_items_only: false,
|
||||||
search_mode: SearchMode::Contains,
|
search_mode: SearchMode::Contains,
|
||||||
case_sensitive: false,
|
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.
|
/// Matches only the entries that are associated items, ignoring the rest.
|
||||||
pub fn assoc_items_only(self) -> Self {
|
pub fn assoc_items_only(self) -> Self {
|
||||||
Self { assoc_items_only: true, ..self }
|
Self { assoc_items_only: true, ..self }
|
||||||
@ -389,17 +380,13 @@ impl Query {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut input = if import.is_trait_assoc_item || self.name_only {
|
let mut input = import.path.segments.last().unwrap().display(db.upcast()).to_string();
|
||||||
import.path.segments.last().unwrap().display(db.upcast()).to_string()
|
let case_insensitive = enforce_lowercase || !self.case_sensitive;
|
||||||
} else {
|
if case_insensitive {
|
||||||
import.path.display(db).to_string()
|
|
||||||
};
|
|
||||||
if enforce_lowercase || !self.case_sensitive {
|
|
||||||
input.make_ascii_lowercase();
|
input.make_ascii_lowercase();
|
||||||
}
|
}
|
||||||
|
|
||||||
let query_string =
|
let query_string = if case_insensitive { &self.lowercased } else { &self.query };
|
||||||
if !enforce_lowercase && self.case_sensitive { &self.query } else { &self.lowercased };
|
|
||||||
|
|
||||||
match self.search_mode {
|
match self.search_mode {
|
||||||
SearchMode::Equals => &input == query_string,
|
SearchMode::Equals => &input == query_string,
|
||||||
@ -875,7 +862,6 @@ mod tests {
|
|||||||
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
|
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
dep::fmt (t)
|
dep::fmt (t)
|
||||||
dep::fmt::Display (t)
|
|
||||||
dep::fmt::Display::FMT_CONST (a)
|
dep::fmt::Display::FMT_CONST (a)
|
||||||
dep::fmt::Display::format_function (a)
|
dep::fmt::Display::format_function (a)
|
||||||
dep::fmt::Display::format_method (a)
|
dep::fmt::Display::format_method (a)
|
||||||
@ -917,9 +903,8 @@ mod tests {
|
|||||||
.search_mode(SearchMode::Fuzzy)
|
.search_mode(SearchMode::Fuzzy)
|
||||||
.exclude_import_kind(ImportKind::AssociatedItem),
|
.exclude_import_kind(ImportKind::AssociatedItem),
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
dep::fmt (t)
|
dep::fmt (t)
|
||||||
dep::fmt::Display (t)
|
"#]],
|
||||||
"#]],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
check_search(
|
check_search(
|
||||||
@ -968,7 +953,6 @@ mod tests {
|
|||||||
dep::Fmt (t)
|
dep::Fmt (t)
|
||||||
dep::Fmt (v)
|
dep::Fmt (v)
|
||||||
dep::fmt (t)
|
dep::fmt (t)
|
||||||
dep::fmt::Display (t)
|
|
||||||
dep::fmt::Display::fmt (a)
|
dep::fmt::Display::fmt (a)
|
||||||
dep::format (f)
|
dep::format (f)
|
||||||
"#]],
|
"#]],
|
||||||
@ -996,7 +980,6 @@ mod tests {
|
|||||||
dep::Fmt (t)
|
dep::Fmt (t)
|
||||||
dep::Fmt (v)
|
dep::Fmt (v)
|
||||||
dep::fmt (t)
|
dep::fmt (t)
|
||||||
dep::fmt::Display (t)
|
|
||||||
dep::fmt::Display::fmt (a)
|
dep::fmt::Display::fmt (a)
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -1037,7 +1020,6 @@ mod tests {
|
|||||||
dep::Fmt (t)
|
dep::Fmt (t)
|
||||||
dep::Fmt (v)
|
dep::Fmt (v)
|
||||||
dep::fmt (t)
|
dep::fmt (t)
|
||||||
dep::fmt::Display (t)
|
|
||||||
dep::fmt::Display::fmt (a)
|
dep::fmt::Display::fmt (a)
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -1045,7 +1027,7 @@ mod tests {
|
|||||||
check_search(
|
check_search(
|
||||||
ra_fixture,
|
ra_fixture,
|
||||||
"main",
|
"main",
|
||||||
Query::new("fmt".to_string()).name_only(),
|
Query::new("fmt".to_string()),
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
dep::Fmt (m)
|
dep::Fmt (m)
|
||||||
dep::Fmt (t)
|
dep::Fmt (t)
|
||||||
|
@ -48,9 +48,8 @@ pub fn items_with_name<'a>(
|
|||||||
let mut local_query = symbol_index::Query::new(exact_name.clone());
|
let mut local_query = symbol_index::Query::new(exact_name.clone());
|
||||||
local_query.exact();
|
local_query.exact();
|
||||||
|
|
||||||
let external_query = import_map::Query::new(exact_name)
|
let external_query =
|
||||||
.name_only()
|
import_map::Query::new(exact_name).search_mode(import_map::SearchMode::Equals);
|
||||||
.search_mode(import_map::SearchMode::Equals);
|
|
||||||
|
|
||||||
(
|
(
|
||||||
local_query,
|
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 local_query = symbol_index::Query::new(fuzzy_search_string.clone());
|
||||||
|
|
||||||
let mut external_query = import_map::Query::new(fuzzy_search_string.clone())
|
let mut external_query = import_map::Query::new(fuzzy_search_string.clone())
|
||||||
.search_mode(import_map::SearchMode::Fuzzy)
|
.search_mode(import_map::SearchMode::Fuzzy);
|
||||||
.name_only();
|
|
||||||
match assoc_item_search {
|
match assoc_item_search {
|
||||||
AssocItemSearch::Include => {}
|
AssocItemSearch::Include => {}
|
||||||
AssocItemSearch::Exclude => {
|
AssocItemSearch::Exclude => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user