mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Show case-insensitive exact matches instead of fuzzy flyimport for short paths
This commit is contained in:
parent
c469f8abcb
commit
143a30aa51
6 changed files with 55 additions and 33 deletions
|
@ -227,22 +227,18 @@ fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option<ImportAs
|
|||
)
|
||||
} else {
|
||||
let fuzzy_name_length = fuzzy_name.len();
|
||||
let assets_for_path = ImportAssets::for_fuzzy_path(
|
||||
let mut assets_for_path = ImportAssets::for_fuzzy_path(
|
||||
current_module,
|
||||
ctx.path_qual().cloned(),
|
||||
fuzzy_name,
|
||||
&ctx.sema,
|
||||
ctx.token.parent()?,
|
||||
)?;
|
||||
|
||||
if matches!(assets_for_path.import_candidate(), ImportCandidate::Path(_))
|
||||
&& fuzzy_name_length < 2
|
||||
{
|
||||
cov_mark::hit!(ignore_short_input_for_path);
|
||||
None
|
||||
} else {
|
||||
Some(assets_for_path)
|
||||
if fuzzy_name_length < 3 {
|
||||
cov_mark::hit!(flyimport_exact_on_short_path);
|
||||
assets_for_path.path_fuzzy_name_to_exact(false);
|
||||
}
|
||||
Some(assets_for_path)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ pub fn resolve_completion_edits(
|
|||
let items_with_name = items_locator::items_with_name(
|
||||
&ctx.sema,
|
||||
current_crate,
|
||||
NameToImport::Exact(imported_name),
|
||||
NameToImport::exact_case_sensitive(imported_name),
|
||||
items_locator::AssocItemSearch::Include,
|
||||
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT.inner()),
|
||||
);
|
||||
|
|
|
@ -96,25 +96,29 @@ fn main() {
|
|||
|
||||
#[test]
|
||||
fn short_paths_are_ignored() {
|
||||
cov_mark::check!(ignore_short_input_for_path);
|
||||
cov_mark::check!(flyimport_exact_on_short_path);
|
||||
|
||||
check(
|
||||
r#"
|
||||
//- /lib.rs crate:dep
|
||||
pub struct FirstStruct;
|
||||
pub struct Bar;
|
||||
pub struct Rcar;
|
||||
pub struct Rc;
|
||||
pub mod some_module {
|
||||
pub struct SecondStruct;
|
||||
pub struct ThirdStruct;
|
||||
pub struct Bar;
|
||||
pub struct Rcar;
|
||||
pub struct Rc;
|
||||
}
|
||||
|
||||
//- /main.rs crate:main deps:dep
|
||||
use dep::{FirstStruct, some_module::SecondStruct};
|
||||
|
||||
fn main() {
|
||||
t$0
|
||||
rc$0
|
||||
}
|
||||
"#,
|
||||
expect![[r#""#]],
|
||||
expect![[r#"
|
||||
st Rc (use dep::Rc)
|
||||
st Rc (use dep::some_module::Rc)
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -772,7 +776,7 @@ mod foo {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
TE$0
|
||||
TES$0
|
||||
}"#,
|
||||
expect![[r#"
|
||||
ct TEST_CONST (use foo::TEST_CONST)
|
||||
|
@ -789,7 +793,7 @@ mod foo {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
te$0
|
||||
tes$0
|
||||
}"#,
|
||||
expect![[r#"
|
||||
ct TEST_CONST (use foo::TEST_CONST)
|
||||
|
@ -846,7 +850,7 @@ struct Foo {
|
|||
some_field: i32,
|
||||
}
|
||||
fn main() {
|
||||
let _ = Foo { some_field: so$0 };
|
||||
let _ = Foo { some_field: som$0 };
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue