mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Use smart case in flyimport items lookup
This commit is contained in:
parent
09412d85fc
commit
ec731e19df
3 changed files with 80 additions and 6 deletions
|
@ -1,8 +1,10 @@
|
||||||
//! Feature: completion with imports-on-the-fly
|
//! Feature: completion with imports-on-the-fly
|
||||||
//!
|
//!
|
||||||
//! When completing names in the current scope, proposes additional imports from other modules or crates,
|
//! When completing names in the current scope, proposes additional imports from other modules or crates,
|
||||||
//! if they can be qualified in the scope and their name contains all symbols from the completion input
|
//! if they can be qualified in the scope and their name contains all symbols from the completion input.
|
||||||
//! (case-insensitive, in any order or places).
|
//!
|
||||||
|
//! To be considered applicable, the name must contain all input symbols in the given order, not necessarily adjacent.
|
||||||
|
//! If any input symbol is not lowercased, the name must contain all symbols in exact case; otherwise the contaning is checked case-insensitively.
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
|
@ -942,7 +944,7 @@ mod foo {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
bar::Ass$0
|
bar::ASS$0
|
||||||
}"#,
|
}"#,
|
||||||
expect![[]],
|
expect![[]],
|
||||||
)
|
)
|
||||||
|
@ -979,4 +981,57 @@ fn main() {
|
||||||
expect![[]],
|
expect![[]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn case_matters() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod foo {
|
||||||
|
pub const TEST_CONST: usize = 3;
|
||||||
|
pub fn test_function() -> i32 {
|
||||||
|
4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
TE$0
|
||||||
|
}"#,
|
||||||
|
expect![[r#"
|
||||||
|
ct foo::TEST_CONST
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod foo {
|
||||||
|
pub const TEST_CONST: usize = 3;
|
||||||
|
pub fn test_function() -> i32 {
|
||||||
|
4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
te$0
|
||||||
|
}"#,
|
||||||
|
expect![[r#"
|
||||||
|
ct foo::TEST_CONST
|
||||||
|
fn test_function() (foo::test_function) fn() -> i32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod foo {
|
||||||
|
pub const TEST_CONST: usize = 3;
|
||||||
|
pub fn test_function() -> i32 {
|
||||||
|
4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
Te$0
|
||||||
|
}"#,
|
||||||
|
expect![[]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ pub fn items_with_name(
|
||||||
(local_query, external_query)
|
(local_query, external_query)
|
||||||
}
|
}
|
||||||
NameToImport::Fuzzy(fuzzy_search_string) => {
|
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())
|
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();
|
.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)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ pub struct Query {
|
||||||
only_types: bool,
|
only_types: bool,
|
||||||
libs: bool,
|
libs: bool,
|
||||||
exact: bool,
|
exact: bool,
|
||||||
|
case_sensitive: bool,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +65,7 @@ impl Query {
|
||||||
only_types: false,
|
only_types: false,
|
||||||
libs: false,
|
libs: false,
|
||||||
exact: false,
|
exact: false,
|
||||||
|
case_sensitive: false,
|
||||||
limit: usize::max_value(),
|
limit: usize::max_value(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +82,10 @@ impl Query {
|
||||||
self.exact = true;
|
self.exact = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn case_sensitive(&mut self) {
|
||||||
|
self.case_sensitive = true;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn limit(&mut self, limit: usize) {
|
pub fn limit(&mut self, limit: usize) {
|
||||||
self.limit = limit
|
self.limit = limit
|
||||||
}
|
}
|
||||||
|
@ -326,9 +332,15 @@ impl Query {
|
||||||
if self.only_types && !symbol.kind.is_type() {
|
if self.only_types && !symbol.kind.is_type() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if self.exact && symbol.name != self.query {
|
if self.exact {
|
||||||
|
if symbol.name != self.query {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else if self.case_sensitive {
|
||||||
|
if self.query.chars().any(|c| !symbol.name.contains(c)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.push(symbol.clone());
|
res.push(symbol.clone());
|
||||||
if res.len() >= self.limit {
|
if res.len() >= self.limit {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue