aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/assists/src/handlers/extract_variable.rs2
-rw-r--r--crates/assists/src/handlers/replace_derive_with_manual_impl.rs31
-rw-r--r--crates/assists/src/utils/import_assets.rs37
-rw-r--r--crates/completion/src/completions/unqualified_path.rs4
-rw-r--r--crates/completion/src/lib.rs2
-rw-r--r--crates/hir_def/src/import_map.rs27
-rw-r--r--crates/hir_def/src/nameres.rs2
-rw-r--r--crates/ide/src/lib.rs2
-rw-r--r--crates/ide_db/src/imports_locator.rs12
-rw-r--r--crates/rust-analyzer/src/handlers.rs2
10 files changed, 61 insertions, 60 deletions
diff --git a/crates/assists/src/handlers/extract_variable.rs b/crates/assists/src/handlers/extract_variable.rs
index d2ae137cd..9957012fe 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
91 // extra newlines in the indent block 91 // extra newlines in the indent block
92 let text = indent.text(); 92 let text = indent.text();
93 if text.starts_with('\n') { 93 if text.starts_with('\n') {
94 buf.push_str("\n"); 94 buf.push('\n');
95 buf.push_str(text.trim_start_matches('\n')); 95 buf.push_str(text.trim_start_matches('\n'));
96 } else { 96 } else {
97 buf.push_str(text); 97 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 4d6a1956b..cb7a5c104 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(
62 let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; 62 let current_module = ctx.sema.scope(annotated_name.syntax()).module()?;
63 let current_crate = current_module.krate(); 63 let current_crate = current_module.krate();
64 64
65 let found_traits = 65 let found_traits = imports_locator::find_exact_imports(
66 imports_locator::find_exact_imports(&ctx.sema, current_crate, trait_token.text()) 66 &ctx.sema,
67 .filter_map( 67 current_crate,
68 |candidate: either::Either<hir::ModuleDef, hir::MacroDef>| match candidate { 68 trait_token.text().to_string(),
69 either::Either::Left(hir::ModuleDef::Trait(trait_)) => Some(trait_), 69 )
70 _ => None, 70 .filter_map(|candidate: either::Either<hir::ModuleDef, hir::MacroDef>| match candidate {
71 }, 71 either::Either::Left(hir::ModuleDef::Trait(trait_)) => Some(trait_),
72 ) 72 _ => None,
73 .flat_map(|trait_| { 73 })
74 current_module 74 .flat_map(|trait_| {
75 .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) 75 current_module
76 .as_ref() 76 .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_))
77 .map(mod_path_to_ast) 77 .as_ref()
78 .zip(Some(trait_)) 78 .map(mod_path_to_ast)
79 }); 79 .zip(Some(trait_))
80 });
80 81
81 let mut no_traits_found = true; 82 let mut no_traits_found = true;
82 for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) { 83 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 ff5c0e78e..4ce82c1ba 100644
--- a/crates/assists/src/utils/import_assets.rs
+++ b/crates/assists/src/utils/import_assets.rs
@@ -179,25 +179,24 @@ impl ImportAssets {
179 } 179 }
180 }; 180 };
181 181
182 let mut res = 182 let mut res = imports_locator::find_exact_imports(
183 imports_locator::find_exact_imports(sema, current_crate, &self.get_search_query()) 183 sema,
184 .filter_map(filter) 184 current_crate,
185 .filter_map(|candidate| { 185 self.get_search_query().to_string(),
186 let item: hir::ItemInNs = candidate.either(Into::into, Into::into); 186 )
187 if let Some(prefix_kind) = prefixed { 187 .filter_map(filter)
188 self.module_with_name_to_import.find_use_path_prefixed( 188 .filter_map(|candidate| {
189 db, 189 let item: hir::ItemInNs = candidate.either(Into::into, Into::into);
190 item, 190 if let Some(prefix_kind) = prefixed {
191 prefix_kind, 191 self.module_with_name_to_import.find_use_path_prefixed(db, item, prefix_kind)
192 ) 192 } else {
193 } else { 193 self.module_with_name_to_import.find_use_path(db, item)
194 self.module_with_name_to_import.find_use_path(db, item) 194 }
195 } 195 .map(|path| (path, item))
196 .map(|path| (path, item)) 196 })
197 }) 197 .filter(|(use_path, _)| use_path.len() > 1)
198 .filter(|(use_path, _)| use_path.len() > 1) 198 .take(20)
199 .take(20) 199 .collect::<Vec<_>>();
200 .collect::<Vec<_>>();
201 res.sort_by_key(|(path, _)| path.clone()); 200 res.sort_by_key(|(path, _)| path.clone());
202 res 201 res
203 } 202 }
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs
index 59f950189..81a6d00e2 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<()
135 let anchor = ctx.name_ref_syntax.as_ref()?; 135 let anchor = ctx.name_ref_syntax.as_ref()?;
136 let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; 136 let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
137 137
138 let user_input_lowercased = potential_import_name.to_lowercase();
138 let mut all_mod_paths = imports_locator::find_similar_imports( 139 let mut all_mod_paths = imports_locator::find_similar_imports(
139 &ctx.sema, 140 &ctx.sema,
140 ctx.krate?, 141 ctx.krate?,
141 Some(40), 142 Some(40),
142 &potential_import_name, 143 potential_import_name,
143 true, 144 true,
144 ) 145 )
145 .filter_map(|import_candidate| { 146 .filter_map(|import_candidate| {
@@ -155,7 +156,6 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
155 .filter(|(mod_path, _)| mod_path.len() > 1) 156 .filter(|(mod_path, _)| mod_path.len() > 1)
156 .collect::<Vec<_>>(); 157 .collect::<Vec<_>>();
157 158
158 let user_input_lowercased = potential_import_name.to_lowercase();
159 all_mod_paths.sort_by_cached_key(|(mod_path, _)| { 159 all_mod_paths.sort_by_cached_key(|(mod_path, _)| {
160 compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased) 160 compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased)
161 }); 161 });
diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs
index 8e27bb153..c57d05bbe 100644
--- a/crates/completion/src/lib.rs
+++ b/crates/completion/src/lib.rs
@@ -137,7 +137,7 @@ pub fn resolve_completion_edits(
137 config: &CompletionConfig, 137 config: &CompletionConfig,
138 position: FilePosition, 138 position: FilePosition,
139 full_import_path: &str, 139 full_import_path: &str,
140 imported_name: &str, 140 imported_name: String,
141) -> Option<Vec<TextEdit>> { 141) -> Option<Vec<TextEdit>> {
142 let ctx = CompletionContext::new(db, position, config)?; 142 let ctx = CompletionContext::new(db, position, config)?;
143 let anchor = ctx.name_ref_syntax.as_ref()?; 143 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 fdc681d6c..c4dc894df 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -262,10 +262,11 @@ pub struct Query {
262} 262}
263 263
264impl Query { 264impl Query {
265 pub fn new(query: &str) -> Self { 265 pub fn new(query: String) -> Self {
266 let lowercased = query.to_lowercase();
266 Self { 267 Self {
267 query: query.to_string(), 268 query,
268 lowercased: query.to_lowercase(), 269 lowercased,
269 name_only: false, 270 name_only: false,
270 search_mode: SearchMode::Contains, 271 search_mode: SearchMode::Contains,
271 case_sensitive: false, 272 case_sensitive: false,
@@ -774,7 +775,7 @@ mod tests {
774 check_search( 775 check_search(
775 ra_fixture, 776 ra_fixture,
776 "main", 777 "main",
777 Query::new("fmt").search_mode(SearchMode::Fuzzy), 778 Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
778 expect![[r#" 779 expect![[r#"
779 dep::fmt (t) 780 dep::fmt (t)
780 dep::Fmt (t) 781 dep::Fmt (t)
@@ -789,7 +790,7 @@ mod tests {
789 check_search( 790 check_search(
790 ra_fixture, 791 ra_fixture,
791 "main", 792 "main",
792 Query::new("fmt").search_mode(SearchMode::Equals), 793 Query::new("fmt".to_string()).search_mode(SearchMode::Equals),
793 expect![[r#" 794 expect![[r#"
794 dep::fmt (t) 795 dep::fmt (t)
795 dep::Fmt (t) 796 dep::Fmt (t)
@@ -802,7 +803,7 @@ mod tests {
802 check_search( 803 check_search(
803 ra_fixture, 804 ra_fixture,
804 "main", 805 "main",
805 Query::new("fmt").search_mode(SearchMode::Contains), 806 Query::new("fmt".to_string()).search_mode(SearchMode::Contains),
806 expect![[r#" 807 expect![[r#"
807 dep::fmt (t) 808 dep::fmt (t)
808 dep::Fmt (t) 809 dep::Fmt (t)
@@ -843,7 +844,7 @@ mod tests {
843 check_search( 844 check_search(
844 ra_fixture, 845 ra_fixture,
845 "main", 846 "main",
846 Query::new("fmt"), 847 Query::new("fmt".to_string()),
847 expect![[r#" 848 expect![[r#"
848 dep::fmt (t) 849 dep::fmt (t)
849 dep::Fmt (t) 850 dep::Fmt (t)
@@ -857,7 +858,7 @@ mod tests {
857 check_search( 858 check_search(
858 ra_fixture, 859 ra_fixture,
859 "main", 860 "main",
860 Query::new("fmt").name_only(), 861 Query::new("fmt".to_string()).name_only(),
861 expect![[r#" 862 expect![[r#"
862 dep::fmt (t) 863 dep::fmt (t)
863 dep::Fmt (t) 864 dep::Fmt (t)
@@ -881,7 +882,7 @@ mod tests {
881 check_search( 882 check_search(
882 ra_fixture, 883 ra_fixture,
883 "main", 884 "main",
884 Query::new("FMT"), 885 Query::new("FMT".to_string()),
885 expect![[r#" 886 expect![[r#"
886 dep::fmt (t) 887 dep::fmt (t)
887 dep::fmt (v) 888 dep::fmt (v)
@@ -893,7 +894,7 @@ mod tests {
893 check_search( 894 check_search(
894 ra_fixture, 895 ra_fixture,
895 "main", 896 "main",
896 Query::new("FMT").case_sensitive(), 897 Query::new("FMT".to_string()).case_sensitive(),
897 expect![[r#" 898 expect![[r#"
898 dep::FMT (t) 899 dep::FMT (t)
899 dep::FMT (v) 900 dep::FMT (v)
@@ -922,7 +923,7 @@ mod tests {
922 pub fn no() {} 923 pub fn no() {}
923 "#, 924 "#,
924 "main", 925 "main",
925 Query::new("").limit(2), 926 Query::new("".to_string()).limit(2),
926 expect![[r#" 927 expect![[r#"
927 dep::fmt (t) 928 dep::fmt (t)
928 dep::Fmt (t) 929 dep::Fmt (t)
@@ -943,7 +944,7 @@ mod tests {
943 check_search( 944 check_search(
944 ra_fixture, 945 ra_fixture,
945 "main", 946 "main",
946 Query::new("FMT"), 947 Query::new("FMT".to_string()),
947 expect![[r#" 948 expect![[r#"
948 dep::fmt (t) 949 dep::fmt (t)
949 dep::fmt (v) 950 dep::fmt (v)
@@ -955,7 +956,7 @@ mod tests {
955 check_search( 956 check_search(
956 ra_fixture, 957 ra_fixture,
957 "main", 958 "main",
958 Query::new("FMT").exclude_import_kind(ImportKind::Adt), 959 Query::new("FMT".to_string()).exclude_import_kind(ImportKind::Adt),
959 expect![[r#""#]], 960 expect![[r#""#]],
960 ); 961 );
961 } 962 }
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index ffd0381d4..9bf358775 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -249,7 +249,7 @@ impl CrateDefMap {
249 buf.push_str(" _"); 249 buf.push_str(" _");
250 } 250 }
251 251
252 buf.push_str("\n"); 252 buf.push('\n');
253 } 253 }
254 254
255 for (name, child) in map.modules[module].children.iter() { 255 for (name, child) in map.modules[module].children.iter() {
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 41eb139d1..b3331f03f 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -475,7 +475,7 @@ impl Analysis {
475 config: &CompletionConfig, 475 config: &CompletionConfig,
476 position: FilePosition, 476 position: FilePosition,
477 full_import_path: &str, 477 full_import_path: &str,
478 imported_name: &str, 478 imported_name: String,
479 ) -> Cancelable<Vec<TextEdit>> { 479 ) -> Cancelable<Vec<TextEdit>> {
480 Ok(self 480 Ok(self
481 .with_db(|db| { 481 .with_db(|db| {
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs
index b6355af4b..0f4c2ca47 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;
15pub fn find_exact_imports<'a>( 15pub fn find_exact_imports<'a>(
16 sema: &Semantics<'a, RootDatabase>, 16 sema: &Semantics<'a, RootDatabase>,
17 krate: Crate, 17 krate: Crate,
18 name_to_import: &str, 18 name_to_import: String,
19) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { 19) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
20 let _p = profile::span("find_exact_imports"); 20 let _p = profile::span("find_exact_imports");
21 find_imports( 21 find_imports(
22 sema, 22 sema,
23 krate, 23 krate,
24 { 24 {
25 let mut local_query = symbol_index::Query::new(name_to_import.to_string()); 25 let mut local_query = symbol_index::Query::new(name_to_import.clone());
26 local_query.exact(); 26 local_query.exact();
27 local_query.limit(40); 27 local_query.limit(40);
28 local_query 28 local_query
@@ -39,18 +39,18 @@ pub fn find_similar_imports<'a>(
39 sema: &Semantics<'a, RootDatabase>, 39 sema: &Semantics<'a, RootDatabase>,
40 krate: Crate, 40 krate: Crate,
41 limit: Option<usize>, 41 limit: Option<usize>,
42 fuzzy_search_string: &str, 42 fuzzy_search_string: String,
43 name_only: bool, 43 name_only: bool,
44) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { 44) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
45 let _p = profile::span("find_similar_imports"); 45 let _p = profile::span("find_similar_imports");
46 46
47 let mut external_query = 47 let mut external_query = import_map::Query::new(fuzzy_search_string.clone())
48 import_map::Query::new(fuzzy_search_string).search_mode(import_map::SearchMode::Fuzzy); 48 .search_mode(import_map::SearchMode::Fuzzy);
49 if name_only { 49 if name_only {
50 external_query = external_query.name_only(); 50 external_query = external_query.name_only();
51 } 51 }
52 52
53 let mut local_query = symbol_index::Query::new(fuzzy_search_string.to_string()); 53 let mut local_query = symbol_index::Query::new(fuzzy_search_string);
54 54
55 if let Some(limit) = limit { 55 if let Some(limit) = limit {
56 local_query.limit(limit); 56 local_query.limit(limit);
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 374fb5302..23f323f55 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(
681 &snap.config.completion, 681 &snap.config.completion,
682 FilePosition { file_id, offset }, 682 FilePosition { file_id, offset },
683 &resolve_data.full_import_path, 683 &resolve_data.full_import_path,
684 &resolve_data.imported_name, 684 resolve_data.imported_name,
685 )? 685 )?
686 .into_iter() 686 .into_iter()
687 .flat_map(|edit| { 687 .flat_map(|edit| {