diff options
author | Kirill Bulatov <[email protected]> | 2020-01-27 12:42:45 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-01-27 12:42:45 +0000 |
commit | 9be1ab7ff948d89334a8acbc309c8235d4ab374f (patch) | |
tree | f67692bfdc8a89f3627507cbbc43d4bece823428 /crates/ra_assists | |
parent | 9a6b5c6183b2d7aa3d577c3fb12d519721f4a4d0 (diff) |
Code review fixes
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/assists/auto_import.rs | 10 | ||||
-rw-r--r-- | crates/ra_assists/src/lib.rs | 5 |
2 files changed, 8 insertions, 7 deletions
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs index 4c3793ac7..9163cc662 100644 --- a/crates/ra_assists/src/assists/auto_import.rs +++ b/crates/ra_assists/src/assists/auto_import.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use hir::{db::HirDatabase, AsName}; | 1 | use hir::db::HirDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, AstNode}, | 3 | ast::{self, AstNode}, |
4 | SmolStr, SyntaxElement, | 4 | SmolStr, SyntaxElement, |
@@ -48,7 +48,7 @@ pub(crate) fn auto_import<F: ImportsLocator>( | |||
48 | return None; | 48 | return None; |
49 | } | 49 | } |
50 | 50 | ||
51 | let name_to_import = &find_applicable_name_ref(ctx.covering_element())?.as_name(); | 51 | let name_to_import = &find_applicable_name_ref(ctx.covering_element())?.syntax().to_string(); |
52 | let proposed_imports = imports_locator | 52 | let proposed_imports = imports_locator |
53 | .find_imports(&name_to_import.to_string()) | 53 | .find_imports(&name_to_import.to_string()) |
54 | .into_iter() | 54 | .into_iter() |
@@ -64,7 +64,7 @@ pub(crate) fn auto_import<F: ImportsLocator>( | |||
64 | ctx.add_assist_group(AssistId("auto_import"), "auto import", || { | 64 | ctx.add_assist_group(AssistId("auto_import"), "auto import", || { |
65 | proposed_imports | 65 | proposed_imports |
66 | .into_iter() | 66 | .into_iter() |
67 | .map(|import| import_to_action(import, &position, &path_to_import)) | 67 | .map(|import| import_to_action(import, &position, &path_to_import.syntax())) |
68 | .collect() | 68 | .collect() |
69 | }) | 69 | }) |
70 | } | 70 | } |
@@ -84,12 +84,12 @@ fn find_applicable_name_ref(element: SyntaxElement) -> Option<ast::NameRef> { | |||
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | fn import_to_action(import: String, position: &SyntaxNode, path: &ast::Path) -> ActionBuilder { | 87 | fn import_to_action(import: String, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { |
88 | let mut action_builder = ActionBuilder::default(); | 88 | let mut action_builder = ActionBuilder::default(); |
89 | action_builder.label(format!("Import `{}`", &import)); | 89 | action_builder.label(format!("Import `{}`", &import)); |
90 | auto_import_text_edit( | 90 | auto_import_text_edit( |
91 | position, | 91 | position, |
92 | &path.syntax().clone(), | 92 | anchor, |
93 | &[SmolStr::new(import)], | 93 | &[SmolStr::new(import)], |
94 | action_builder.text_edit_builder(), | 94 | action_builder.text_edit_builder(), |
95 | ); | 95 | ); |
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 724bce191..625ebc4a2 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -234,6 +234,7 @@ mod helpers { | |||
234 | use crate::{test_db::TestDB, Assist, AssistCtx, ImportsLocator}; | 234 | use crate::{test_db::TestDB, Assist, AssistCtx, ImportsLocator}; |
235 | use std::sync::Arc; | 235 | use std::sync::Arc; |
236 | 236 | ||
237 | // FIXME remove the `ModuleDefId` reexport from `ra_hir` when this gets removed. | ||
237 | pub(crate) struct TestImportsLocator { | 238 | pub(crate) struct TestImportsLocator { |
238 | db: Arc<TestDB>, | 239 | db: Arc<TestDB>, |
239 | test_file_id: FileId, | 240 | test_file_id: FileId, |
@@ -248,13 +249,13 @@ mod helpers { | |||
248 | impl ImportsLocator for TestImportsLocator { | 249 | impl ImportsLocator for TestImportsLocator { |
249 | fn find_imports(&mut self, name_to_import: &str) -> Vec<hir::ModuleDef> { | 250 | fn find_imports(&mut self, name_to_import: &str) -> Vec<hir::ModuleDef> { |
250 | let crate_def_map = self.db.crate_def_map(self.db.test_crate()); | 251 | let crate_def_map = self.db.crate_def_map(self.db.test_crate()); |
251 | let mut findings = vec![]; | 252 | let mut findings = Vec::new(); |
252 | 253 | ||
253 | let mut module_ids_to_process = | 254 | let mut module_ids_to_process = |
254 | crate_def_map.modules_for_file(self.test_file_id).collect::<Vec<_>>(); | 255 | crate_def_map.modules_for_file(self.test_file_id).collect::<Vec<_>>(); |
255 | 256 | ||
256 | while !module_ids_to_process.is_empty() { | 257 | while !module_ids_to_process.is_empty() { |
257 | let mut more_ids_to_process = vec![]; | 258 | let mut more_ids_to_process = Vec::new(); |
258 | for local_module_id in module_ids_to_process.drain(..) { | 259 | for local_module_id in module_ids_to_process.drain(..) { |
259 | for (name, namespace_data) in | 260 | for (name, namespace_data) in |
260 | crate_def_map[local_module_id].scope.entries_without_primitives() | 261 | crate_def_map[local_module_id].scope.entries_without_primitives() |