Skip to content

Commit a173e31

Browse files
committed
Make assists use ImportsLocator directly
1 parent ff0f0fc commit a173e31

File tree

6 files changed

+34
-37
lines changed

6 files changed

+34
-37
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_assists/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ ra_text_edit = { path = "../ra_text_edit" }
1818
ra_fmt = { path = "../ra_fmt" }
1919
ra_prof = { path = "../ra_prof" }
2020
ra_db = { path = "../ra_db" }
21+
ra_ide_db = { path = "../ra_ide_db" }
2122
hir = { path = "../ra_hir", package = "ra_hir" }
2223
test_utils = { path = "../test_utils" }

crates/ra_assists/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub mod ast_transform;
1616
use either::Either;
1717
use hir::{db::HirDatabase, ModuleDef};
1818
use ra_db::FileRange;
19+
use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase};
1920
use ra_syntax::{TextRange, TextUnit};
2021
use ra_text_edit::TextEdit;
2122

@@ -88,20 +89,19 @@ pub trait ImportsLocator {
8889
fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef>;
8990
}
9091

92+
impl ImportsLocator for ImportsLocatorIde<'_> {
93+
fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> {
94+
self.find_imports(name_to_import)
95+
}
96+
}
97+
9198
/// Return all the assists applicable at the given position
9299
/// and additional assists that need the imports locator functionality to work.
93100
///
94101
/// Assists are returned in the "resolved" state, that is with edit fully
95102
/// computed.
96-
pub fn assists_with_imports_locator<H, F>(
97-
db: &H,
98-
range: FileRange,
99-
mut imports_locator: F,
100-
) -> Vec<ResolvedAssist>
101-
where
102-
H: HirDatabase + 'static,
103-
F: ImportsLocator,
104-
{
103+
pub fn assists_with_imports_locator(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> {
104+
let mut imports_locator = ImportsLocatorIde::new(db);
105105
AssistCtx::with_ctx(db, range, true, |ctx| {
106106
let mut assists = assists::all()
107107
.iter()

crates/ra_ide/src/assists.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use either::Either;
44
use ra_assists::{AssistAction, AssistLabel};
55
use ra_db::{FilePosition, FileRange};
6-
use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase};
6+
use ra_ide_db::RootDatabase;
77

88
use crate::{FileId, SourceChange, SourceFileEdit};
99

@@ -17,7 +17,7 @@ pub struct Assist {
1717
}
1818

1919
pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> {
20-
ra_assists::assists_with_imports_locator(db, frange, ImportsLocatorIde::new(db))
20+
ra_assists::assists_with_imports_locator(db, frange)
2121
.into_iter()
2222
.map(|assist| {
2323
let file_id = frange.file_id;

crates/ra_ide_db/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ ra_cfg = { path = "../ra_cfg" }
3232
ra_fmt = { path = "../ra_fmt" }
3333
ra_prof = { path = "../ra_prof" }
3434
test_utils = { path = "../test_utils" }
35-
ra_assists = { path = "../ra_assists" }
3635

3736
# ra_ide should depend only on the top-level `hir` package. if you need
3837
# something from some `hir_xxx` subpackage, reexport the API via `hir`.

crates/ra_ide_db/src/imports_locator.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! Later, this should be moved away to a separate crate that is accessible from the ra_assists module.
33
44
use hir::{db::HirDatabase, ModuleDef, SourceBinder};
5-
use ra_assists::ImportsLocator;
65
use ra_prof::profile;
76
use ra_syntax::{ast, AstNode, SyntaxKind::NAME};
87

@@ -22,29 +21,7 @@ impl<'a> ImportsLocatorIde<'a> {
2221
Self { source_binder: SourceBinder::new(db) }
2322
}
2423

25-
fn get_name_definition(
26-
&mut self,
27-
db: &impl HirDatabase,
28-
import_candidate: &FileSymbol,
29-
) -> Option<NameKind> {
30-
let _p = profile("get_name_definition");
31-
let file_id = import_candidate.file_id.into();
32-
let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?);
33-
let candidate_name_node = if candidate_node.kind() != NAME {
34-
candidate_node.children().find(|it| it.kind() == NAME)?
35-
} else {
36-
candidate_node
37-
};
38-
classify_name(
39-
&mut self.source_binder,
40-
hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? },
41-
)
42-
.map(|it| it.kind)
43-
}
44-
}
45-
46-
impl ImportsLocator for ImportsLocatorIde<'_> {
47-
fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> {
24+
pub fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> {
4825
let _p = profile("search_for_imports");
4926
let db = self.source_binder.db;
5027

@@ -72,4 +49,24 @@ impl ImportsLocator for ImportsLocatorIde<'_> {
7249
})
7350
.collect()
7451
}
52+
53+
fn get_name_definition(
54+
&mut self,
55+
db: &impl HirDatabase,
56+
import_candidate: &FileSymbol,
57+
) -> Option<NameKind> {
58+
let _p = profile("get_name_definition");
59+
let file_id = import_candidate.file_id.into();
60+
let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?);
61+
let candidate_name_node = if candidate_node.kind() != NAME {
62+
candidate_node.children().find(|it| it.kind() == NAME)?
63+
} else {
64+
candidate_node
65+
};
66+
classify_name(
67+
&mut self.source_binder,
68+
hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? },
69+
)
70+
.map(|it| it.kind)
71+
}
7572
}

0 commit comments

Comments
 (0)