Skip to content

Commit 895cdb5

Browse files
bors[bot]matklad
andauthored
Merge #3034
3034: Remove ImportLocator hack r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 8b957ca + d1e8b8d commit 895cdb5

35 files changed

+132
-350
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/assist_ctx.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
22
use either::Either;
3-
use hir::{db::HirDatabase, InFile, SourceAnalyzer, SourceBinder};
4-
use ra_db::FileRange;
3+
use hir::{InFile, SourceAnalyzer, SourceBinder};
4+
use ra_db::{FileRange, SourceDatabase};
55
use ra_fmt::{leading_indent, reindent};
6+
use ra_ide_db::RootDatabase;
67
use ra_syntax::{
78
algo::{self, find_covering_element, find_node_at_offset},
89
AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextUnit,
@@ -49,14 +50,14 @@ pub(crate) enum Assist {
4950
/// moment, because the LSP API is pretty awkward in this place, and it's much
5051
/// easier to just compute the edit eagerly :-)
5152
#[derive(Debug)]
52-
pub(crate) struct AssistCtx<'a, DB> {
53-
pub(crate) db: &'a DB,
53+
pub(crate) struct AssistCtx<'a> {
54+
pub(crate) db: &'a RootDatabase,
5455
pub(crate) frange: FileRange,
5556
source_file: SourceFile,
5657
should_compute_edit: bool,
5758
}
5859

59-
impl<'a, DB> Clone for AssistCtx<'a, DB> {
60+
impl<'a> Clone for AssistCtx<'a> {
6061
fn clone(&self) -> Self {
6162
AssistCtx {
6263
db: self.db,
@@ -67,17 +68,24 @@ impl<'a, DB> Clone for AssistCtx<'a, DB> {
6768
}
6869
}
6970

70-
impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
71-
pub(crate) fn with_ctx<F, T>(db: &DB, frange: FileRange, should_compute_edit: bool, f: F) -> T
71+
impl<'a> AssistCtx<'a> {
72+
pub(crate) fn with_ctx<F, T>(
73+
db: &RootDatabase,
74+
frange: FileRange,
75+
should_compute_edit: bool,
76+
f: F,
77+
) -> T
7278
where
73-
F: FnOnce(AssistCtx<DB>) -> T,
79+
F: FnOnce(AssistCtx) -> T,
7480
{
7581
let parse = db.parse(frange.file_id);
7682

7783
let ctx = AssistCtx { db, frange, source_file: parse.tree(), should_compute_edit };
7884
f(ctx)
7985
}
86+
}
8087

88+
impl<'a> AssistCtx<'a> {
8189
pub(crate) fn add_assist(
8290
self,
8391
id: AssistId,
@@ -141,7 +149,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
141149
pub(crate) fn covering_element(&self) -> SyntaxElement {
142150
find_covering_element(self.source_file.syntax(), self.frange.range)
143151
}
144-
pub(crate) fn source_binder(&self) -> SourceBinder<'a, DB> {
152+
pub(crate) fn source_binder(&self) -> SourceBinder<'a, RootDatabase> {
145153
SourceBinder::new(self.db)
146154
}
147155
pub(crate) fn source_analyzer(

crates/ra_assists/src/assists/add_custom_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! FIXME: write short doc here
22
33
use crate::{Assist, AssistCtx, AssistId};
4-
use hir::db::HirDatabase;
4+
55
use join_to_string::join;
66
use ra_syntax::{
77
ast::{self, AstNode},
@@ -29,7 +29,7 @@ const DERIVE_TRAIT: &str = "derive";
2929
//
3030
// }
3131
// ```
32-
pub(crate) fn add_custom_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
32+
pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
3333
let input = ctx.find_node_at_offset::<ast::AttrInput>()?;
3434
let attr = input.syntax().parent().and_then(ast::Attr::cast)?;
3535

crates/ra_assists/src/assists/add_derive.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use hir::db::HirDatabase;
21
use ra_syntax::{
32
ast::{self, AstNode, AttrsOwner},
43
SyntaxKind::{COMMENT, WHITESPACE},
@@ -25,7 +24,7 @@ use crate::{Assist, AssistCtx, AssistId};
2524
// y: u32,
2625
// }
2726
// ```
28-
pub(crate) fn add_derive(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
27+
pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> {
2928
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
3029
let node_start = derive_insertion_offset(&nominal)?;
3130
ctx.add_assist(AssistId("add_derive"), "Add `#[derive]`", |edit| {

crates/ra_assists/src/assists/add_explicit_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use hir::{db::HirDatabase, HirDisplay};
1+
use hir::HirDisplay;
22
use ra_syntax::{
33
ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner},
44
TextRange,
@@ -21,7 +21,7 @@ use crate::{Assist, AssistCtx, AssistId};
2121
// let x: i32 = 92;
2222
// }
2323
// ```
24-
pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
24+
pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option<Assist> {
2525
let stmt = ctx.find_node_at_offset::<LetStmt>()?;
2626
let expr = stmt.initializer()?;
2727
let pat = stmt.pat()?;

crates/ra_assists/src/assists/add_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use format_buf::format;
2-
use hir::db::HirDatabase;
2+
33
use join_to_string::join;
44
use ra_syntax::{
55
ast::{self, AstNode, NameOwner, TypeParamsOwner},
@@ -27,7 +27,7 @@ use crate::{Assist, AssistCtx, AssistId};
2727
//
2828
// }
2929
// ```
30-
pub(crate) fn add_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
30+
pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
3131
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
3232
let name = nominal.name()?;
3333
ctx.add_assist(AssistId("add_impl"), format!("Implement {}", name.text().as_str()), |edit| {

crates/ra_assists/src/assists/add_import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use hir::{self, db::HirDatabase, ModPath};
1+
use hir::{self, ModPath};
22
use ra_syntax::{
33
ast::{self, NameOwner},
44
AstNode, Direction, SmolStr,
@@ -50,7 +50,7 @@ pub fn auto_import_text_edit(
5050
//
5151
// fn process(map: HashMap<String, String>) {}
5252
// ```
53-
pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
53+
pub(crate) fn add_import(ctx: AssistCtx) -> Option<Assist> {
5454
let path: ast::Path = ctx.find_node_at_offset()?;
5555
// We don't want to mess with use statements
5656
if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() {

crates/ra_assists/src/assists/add_missing_impl_members.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum AddMissingImplMembersMode {
4343
//
4444
// }
4545
// ```
46-
pub(crate) fn add_missing_impl_members(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
46+
pub(crate) fn add_missing_impl_members(ctx: AssistCtx) -> Option<Assist> {
4747
add_missing_impl_members_inner(
4848
ctx,
4949
AddMissingImplMembersMode::NoDefaultMethods,
@@ -84,7 +84,7 @@ pub(crate) fn add_missing_impl_members(ctx: AssistCtx<impl HirDatabase>) -> Opti
8484
//
8585
// }
8686
// ```
87-
pub(crate) fn add_missing_default_members(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
87+
pub(crate) fn add_missing_default_members(ctx: AssistCtx) -> Option<Assist> {
8888
add_missing_impl_members_inner(
8989
ctx,
9090
AddMissingImplMembersMode::DefaultMethodsOnly,
@@ -94,7 +94,7 @@ pub(crate) fn add_missing_default_members(ctx: AssistCtx<impl HirDatabase>) -> O
9494
}
9595

9696
fn add_missing_impl_members_inner(
97-
ctx: AssistCtx<impl HirDatabase>,
97+
ctx: AssistCtx,
9898
mode: AddMissingImplMembersMode,
9999
assist_id: &'static str,
100100
label: &'static str,

crates/ra_assists/src/assists/add_new.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use format_buf::format;
2-
use hir::{db::HirDatabase, InFile};
2+
use hir::InFile;
33
use join_to_string::join;
44
use ra_syntax::{
55
ast::{
@@ -31,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId};
3131
// }
3232
//
3333
// ```
34-
pub(crate) fn add_new(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
34+
pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
3535
let strukt = ctx.find_node_at_offset::<ast::StructDef>()?;
3636

3737
// We want to only apply this to non-union structs with named fields
@@ -128,10 +128,7 @@ fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String {
128128
//
129129
// FIXME: change the new fn checking to a more semantic approach when that's more
130130
// viable (e.g. we process proc macros, etc)
131-
fn find_struct_impl(
132-
ctx: &AssistCtx<impl HirDatabase>,
133-
strukt: &ast::StructDef,
134-
) -> Option<Option<ast::ImplBlock>> {
131+
fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<ast::ImplBlock>> {
135132
let db = ctx.db;
136133
let module = strukt.syntax().ancestors().find(|node| {
137134
ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())

0 commit comments

Comments
 (0)