Skip to content

Commit 9be1ab7

Browse files
Code review fixes
1 parent 9a6b5c6 commit 9be1ab7

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

crates/ra_assists/src/assists/auto_import.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use hir::{db::HirDatabase, AsName};
1+
use hir::db::HirDatabase;
22
use ra_syntax::{
33
ast::{self, AstNode},
44
SmolStr, SyntaxElement,
@@ -48,7 +48,7 @@ pub(crate) fn auto_import<F: ImportsLocator>(
4848
return None;
4949
}
5050

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();
5252
let proposed_imports = imports_locator
5353
.find_imports(&name_to_import.to_string())
5454
.into_iter()
@@ -64,7 +64,7 @@ pub(crate) fn auto_import<F: ImportsLocator>(
6464
ctx.add_assist_group(AssistId("auto_import"), "auto import", || {
6565
proposed_imports
6666
.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()))
6868
.collect()
6969
})
7070
}
@@ -84,12 +84,12 @@ fn find_applicable_name_ref(element: SyntaxElement) -> Option<ast::NameRef> {
8484
}
8585
}
8686

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 {
8888
let mut action_builder = ActionBuilder::default();
8989
action_builder.label(format!("Import `{}`", &import));
9090
auto_import_text_edit(
9191
position,
92-
&path.syntax().clone(),
92+
anchor,
9393
&[SmolStr::new(import)],
9494
action_builder.text_edit_builder(),
9595
);

crates/ra_assists/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ mod helpers {
234234
use crate::{test_db::TestDB, Assist, AssistCtx, ImportsLocator};
235235
use std::sync::Arc;
236236

237+
// FIXME remove the `ModuleDefId` reexport from `ra_hir` when this gets removed.
237238
pub(crate) struct TestImportsLocator {
238239
db: Arc<TestDB>,
239240
test_file_id: FileId,
@@ -248,13 +249,13 @@ mod helpers {
248249
impl ImportsLocator for TestImportsLocator {
249250
fn find_imports(&mut self, name_to_import: &str) -> Vec<hir::ModuleDef> {
250251
let crate_def_map = self.db.crate_def_map(self.db.test_crate());
251-
let mut findings = vec![];
252+
let mut findings = Vec::new();
252253

253254
let mut module_ids_to_process =
254255
crate_def_map.modules_for_file(self.test_file_id).collect::<Vec<_>>();
255256

256257
while !module_ids_to_process.is_empty() {
257-
let mut more_ids_to_process = vec![];
258+
let mut more_ids_to_process = Vec::new();
258259
for local_module_id in module_ids_to_process.drain(..) {
259260
for (name, namespace_data) in
260261
crate_def_map[local_module_id].scope.entries_without_primitives()

crates/ra_hir/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ pub use hir_def::{
5656
nameres::ModuleSource,
5757
path::{ModPath, Path, PathKind},
5858
type_ref::Mutability,
59-
ModuleDefId,
59+
ModuleDefId, // FIXME this is exposed and should be used for implementing the `TestImportsLocator` in `ra_assists` only, should be removed later along with the trait and the implementation.
6060
};
6161
pub use hir_expand::{
62-
name::{AsName, Name},
63-
HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
62+
name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
6463
};
6564
pub use hir_ty::{display::HirDisplay, CallableDef};

crates/ra_ide/src/imports_locator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a> ImportsLocatorIde<'a> {
4141
}
4242
}
4343

44-
impl<'a> ImportsLocator for ImportsLocatorIde<'a> {
44+
impl ImportsLocator for ImportsLocatorIde<'_> {
4545
fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> {
4646
let _p = profile("search_for_imports");
4747
let db = self.source_binder.db;

0 commit comments

Comments
 (0)