diff --git a/crates/assists/src/handlers/extract_variable.rs b/crates/assists/src/handlers/extract_variable.rs index d2ae137cdd..9957012fe5 100644 --- a/crates/assists/src/handlers/extract_variable.rs +++ b/crates/assists/src/handlers/extract_variable.rs @@ -91,7 +91,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option // extra newlines in the indent block let text = indent.text(); if text.starts_with('\n') { - buf.push_str("\n"); + buf.push('\n'); buf.push_str(text.trim_start_matches('\n')); } else { buf.push_str(text); diff --git a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs index 4d6a1956bb..cb7a5c1042 100644 --- a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs @@ -62,21 +62,22 @@ pub(crate) fn replace_derive_with_manual_impl( let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; let current_crate = current_module.krate(); - let found_traits = - imports_locator::find_exact_imports(&ctx.sema, current_crate, trait_token.text()) - .filter_map( - |candidate: either::Either| match candidate { - either::Either::Left(hir::ModuleDef::Trait(trait_)) => Some(trait_), - _ => None, - }, - ) - .flat_map(|trait_| { - current_module - .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) - .as_ref() - .map(mod_path_to_ast) - .zip(Some(trait_)) - }); + let found_traits = imports_locator::find_exact_imports( + &ctx.sema, + current_crate, + trait_token.text().to_string(), + ) + .filter_map(|candidate: either::Either| match candidate { + either::Either::Left(hir::ModuleDef::Trait(trait_)) => Some(trait_), + _ => None, + }) + .flat_map(|trait_| { + current_module + .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) + .as_ref() + .map(mod_path_to_ast) + .zip(Some(trait_)) + }); let mut no_traits_found = true; for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) { diff --git a/crates/assists/src/utils/import_assets.rs b/crates/assists/src/utils/import_assets.rs index ff5c0e78ee..4ce82c1ba5 100644 --- a/crates/assists/src/utils/import_assets.rs +++ b/crates/assists/src/utils/import_assets.rs @@ -179,25 +179,24 @@ impl ImportAssets { } }; - let mut res = - imports_locator::find_exact_imports(sema, current_crate, &self.get_search_query()) - .filter_map(filter) - .filter_map(|candidate| { - let item: hir::ItemInNs = candidate.either(Into::into, Into::into); - if let Some(prefix_kind) = prefixed { - self.module_with_name_to_import.find_use_path_prefixed( - db, - item, - prefix_kind, - ) - } else { - self.module_with_name_to_import.find_use_path(db, item) - } - .map(|path| (path, item)) - }) - .filter(|(use_path, _)| use_path.len() > 1) - .take(20) - .collect::>(); + let mut res = imports_locator::find_exact_imports( + sema, + current_crate, + self.get_search_query().to_string(), + ) + .filter_map(filter) + .filter_map(|candidate| { + let item: hir::ItemInNs = candidate.either(Into::into, Into::into); + if let Some(prefix_kind) = prefixed { + self.module_with_name_to_import.find_use_path_prefixed(db, item, prefix_kind) + } else { + self.module_with_name_to_import.find_use_path(db, item) + } + .map(|path| (path, item)) + }) + .filter(|(use_path, _)| use_path.len() > 1) + .take(20) + .collect::>(); res.sort_by_key(|(path, _)| path.clone()); res } diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 59f9501895..81a6d00e2b 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -135,11 +135,12 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() let anchor = ctx.name_ref_syntax.as_ref()?; let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; + let user_input_lowercased = potential_import_name.to_lowercase(); let mut all_mod_paths = imports_locator::find_similar_imports( &ctx.sema, ctx.krate?, Some(40), - &potential_import_name, + potential_import_name, true, ) .filter_map(|import_candidate| { @@ -155,7 +156,6 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() .filter(|(mod_path, _)| mod_path.len() > 1) .collect::>(); - let user_input_lowercased = potential_import_name.to_lowercase(); all_mod_paths.sort_by_cached_key(|(mod_path, _)| { compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased) }); diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index 8e27bb1532..c57d05bbeb 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs @@ -137,7 +137,7 @@ pub fn resolve_completion_edits( config: &CompletionConfig, position: FilePosition, full_import_path: &str, - imported_name: &str, + imported_name: String, ) -> Option> { let ctx = CompletionContext::new(db, position, config)?; let anchor = ctx.name_ref_syntax.as_ref()?; diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs index fdc681d6ce..c4dc894df5 100644 --- a/crates/hir_def/src/import_map.rs +++ b/crates/hir_def/src/import_map.rs @@ -262,10 +262,11 @@ pub struct Query { } impl Query { - pub fn new(query: &str) -> Self { + pub fn new(query: String) -> Self { + let lowercased = query.to_lowercase(); Self { - query: query.to_string(), - lowercased: query.to_lowercase(), + query, + lowercased, name_only: false, search_mode: SearchMode::Contains, case_sensitive: false, @@ -774,7 +775,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt").search_mode(SearchMode::Fuzzy), + Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -789,7 +790,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt").search_mode(SearchMode::Equals), + Query::new("fmt".to_string()).search_mode(SearchMode::Equals), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -802,7 +803,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt").search_mode(SearchMode::Contains), + Query::new("fmt".to_string()).search_mode(SearchMode::Contains), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -843,7 +844,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt"), + Query::new("fmt".to_string()), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -857,7 +858,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt").name_only(), + Query::new("fmt".to_string()).name_only(), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -881,7 +882,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("FMT"), + Query::new("FMT".to_string()), expect![[r#" dep::fmt (t) dep::fmt (v) @@ -893,7 +894,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("FMT").case_sensitive(), + Query::new("FMT".to_string()).case_sensitive(), expect![[r#" dep::FMT (t) dep::FMT (v) @@ -922,7 +923,7 @@ mod tests { pub fn no() {} "#, "main", - Query::new("").limit(2), + Query::new("".to_string()).limit(2), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -943,7 +944,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("FMT"), + Query::new("FMT".to_string()), expect![[r#" dep::fmt (t) dep::fmt (v) @@ -955,7 +956,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("FMT").exclude_import_kind(ImportKind::Adt), + Query::new("FMT".to_string()).exclude_import_kind(ImportKind::Adt), expect![[r#""#]], ); } diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index ffd0381d43..9bf3587759 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -249,7 +249,7 @@ impl CrateDefMap { buf.push_str(" _"); } - buf.push_str("\n"); + buf.push('\n'); } for (name, child) in map.modules[module].children.iter() { diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 41eb139d16..b3331f03f1 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -475,7 +475,7 @@ impl Analysis { config: &CompletionConfig, position: FilePosition, full_import_path: &str, - imported_name: &str, + imported_name: String, ) -> Cancelable> { Ok(self .with_db(|db| { diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index b6355af4bd..0f4c2ca473 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs @@ -15,14 +15,14 @@ use rustc_hash::FxHashSet; pub fn find_exact_imports<'a>( sema: &Semantics<'a, RootDatabase>, krate: Crate, - name_to_import: &str, + name_to_import: String, ) -> impl Iterator> { let _p = profile::span("find_exact_imports"); find_imports( sema, krate, { - let mut local_query = symbol_index::Query::new(name_to_import.to_string()); + let mut local_query = symbol_index::Query::new(name_to_import.clone()); local_query.exact(); local_query.limit(40); local_query @@ -39,18 +39,18 @@ pub fn find_similar_imports<'a>( sema: &Semantics<'a, RootDatabase>, krate: Crate, limit: Option, - fuzzy_search_string: &str, + fuzzy_search_string: String, name_only: bool, ) -> impl Iterator> { let _p = profile::span("find_similar_imports"); - let mut external_query = - import_map::Query::new(fuzzy_search_string).search_mode(import_map::SearchMode::Fuzzy); + let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) + .search_mode(import_map::SearchMode::Fuzzy); if name_only { external_query = external_query.name_only(); } - let mut local_query = symbol_index::Query::new(fuzzy_search_string.to_string()); + let mut local_query = symbol_index::Query::new(fuzzy_search_string); if let Some(limit) = limit { local_query.limit(limit); diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 374fb5302b..23f323f556 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -681,7 +681,7 @@ pub(crate) fn handle_completion_resolve( &snap.config.completion, FilePosition { file_id, offset }, &resolve_data.full_import_path, - &resolve_data.imported_name, + resolve_data.imported_name, )? .into_iter() .flat_map(|edit| {