mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Code review fixes
This commit is contained in:
parent
9a6b5c6183
commit
9be1ab7ff9
4 changed files with 11 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
|||
use hir::{db::HirDatabase, AsName};
|
||||
use hir::db::HirDatabase;
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode},
|
||||
SmolStr, SyntaxElement,
|
||||
|
@ -48,7 +48,7 @@ pub(crate) fn auto_import<F: ImportsLocator>(
|
|||
return None;
|
||||
}
|
||||
|
||||
let name_to_import = &find_applicable_name_ref(ctx.covering_element())?.as_name();
|
||||
let name_to_import = &find_applicable_name_ref(ctx.covering_element())?.syntax().to_string();
|
||||
let proposed_imports = imports_locator
|
||||
.find_imports(&name_to_import.to_string())
|
||||
.into_iter()
|
||||
|
@ -64,7 +64,7 @@ pub(crate) fn auto_import<F: ImportsLocator>(
|
|||
ctx.add_assist_group(AssistId("auto_import"), "auto import", || {
|
||||
proposed_imports
|
||||
.into_iter()
|
||||
.map(|import| import_to_action(import, &position, &path_to_import))
|
||||
.map(|import| import_to_action(import, &position, &path_to_import.syntax()))
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
@ -84,12 +84,12 @@ fn find_applicable_name_ref(element: SyntaxElement) -> Option<ast::NameRef> {
|
|||
}
|
||||
}
|
||||
|
||||
fn import_to_action(import: String, position: &SyntaxNode, path: &ast::Path) -> ActionBuilder {
|
||||
fn import_to_action(import: String, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder {
|
||||
let mut action_builder = ActionBuilder::default();
|
||||
action_builder.label(format!("Import `{}`", &import));
|
||||
auto_import_text_edit(
|
||||
position,
|
||||
&path.syntax().clone(),
|
||||
anchor,
|
||||
&[SmolStr::new(import)],
|
||||
action_builder.text_edit_builder(),
|
||||
);
|
||||
|
|
|
@ -234,6 +234,7 @@ mod helpers {
|
|||
use crate::{test_db::TestDB, Assist, AssistCtx, ImportsLocator};
|
||||
use std::sync::Arc;
|
||||
|
||||
// FIXME remove the `ModuleDefId` reexport from `ra_hir` when this gets removed.
|
||||
pub(crate) struct TestImportsLocator {
|
||||
db: Arc<TestDB>,
|
||||
test_file_id: FileId,
|
||||
|
@ -248,13 +249,13 @@ mod helpers {
|
|||
impl ImportsLocator for TestImportsLocator {
|
||||
fn find_imports(&mut self, name_to_import: &str) -> Vec<hir::ModuleDef> {
|
||||
let crate_def_map = self.db.crate_def_map(self.db.test_crate());
|
||||
let mut findings = vec![];
|
||||
let mut findings = Vec::new();
|
||||
|
||||
let mut module_ids_to_process =
|
||||
crate_def_map.modules_for_file(self.test_file_id).collect::<Vec<_>>();
|
||||
|
||||
while !module_ids_to_process.is_empty() {
|
||||
let mut more_ids_to_process = vec![];
|
||||
let mut more_ids_to_process = Vec::new();
|
||||
for local_module_id in module_ids_to_process.drain(..) {
|
||||
for (name, namespace_data) in
|
||||
crate_def_map[local_module_id].scope.entries_without_primitives()
|
||||
|
|
|
@ -56,10 +56,9 @@ pub use hir_def::{
|
|||
nameres::ModuleSource,
|
||||
path::{ModPath, Path, PathKind},
|
||||
type_ref::Mutability,
|
||||
ModuleDefId,
|
||||
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.
|
||||
};
|
||||
pub use hir_expand::{
|
||||
name::{AsName, Name},
|
||||
HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
|
||||
name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
|
||||
};
|
||||
pub use hir_ty::{display::HirDisplay, CallableDef};
|
||||
|
|
|
@ -41,7 +41,7 @@ impl<'a> ImportsLocatorIde<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> ImportsLocator for ImportsLocatorIde<'a> {
|
||||
impl ImportsLocator for ImportsLocatorIde<'_> {
|
||||
fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> {
|
||||
let _p = profile("search_for_imports");
|
||||
let db = self.source_binder.db;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue