Skip to content

Commit cf812c1

Browse files
committed
Assists are not generic
1 parent f8965ff commit cf812c1

27 files changed

+59
-84
lines changed

crates/ra_assists/src/assist_ctx.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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};
3+
use hir::{InFile, SourceAnalyzer, SourceBinder};
44
use ra_db::{FileRange, SourceDatabase};
55
use ra_fmt::{leading_indent, reindent};
66
use ra_ide_db::RootDatabase;
@@ -50,14 +50,14 @@ pub(crate) enum Assist {
5050
/// moment, because the LSP API is pretty awkward in this place, and it's much
5151
/// easier to just compute the edit eagerly :-)
5252
#[derive(Debug)]
53-
pub(crate) struct AssistCtx<'a, DB> {
54-
pub(crate) db: &'a DB,
53+
pub(crate) struct AssistCtx<'a> {
54+
pub(crate) db: &'a RootDatabase,
5555
pub(crate) frange: FileRange,
5656
source_file: SourceFile,
5757
should_compute_edit: bool,
5858
}
5959

60-
impl<'a, DB> Clone for AssistCtx<'a, DB> {
60+
impl<'a> Clone for AssistCtx<'a> {
6161
fn clone(&self) -> Self {
6262
AssistCtx {
6363
db: self.db,
@@ -68,15 +68,15 @@ impl<'a, DB> Clone for AssistCtx<'a, DB> {
6868
}
6969
}
7070

71-
impl<'a> AssistCtx<'a, RootDatabase> {
71+
impl<'a> AssistCtx<'a> {
7272
pub(crate) fn with_ctx<F, T>(
7373
db: &RootDatabase,
7474
frange: FileRange,
7575
should_compute_edit: bool,
7676
f: F,
7777
) -> T
7878
where
79-
F: FnOnce(AssistCtx<RootDatabase>) -> T,
79+
F: FnOnce(AssistCtx) -> T,
8080
{
8181
let parse = db.parse(frange.file_id);
8282

@@ -85,7 +85,7 @@ impl<'a> AssistCtx<'a, RootDatabase> {
8585
}
8686
}
8787

88-
impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
88+
impl<'a> AssistCtx<'a> {
8989
pub(crate) fn add_assist(
9090
self,
9191
id: AssistId,
@@ -149,7 +149,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
149149
pub(crate) fn covering_element(&self) -> SyntaxElement {
150150
find_covering_element(self.source_file.syntax(), self.frange.range)
151151
}
152-
pub(crate) fn source_binder(&self) -> SourceBinder<'a, DB> {
152+
pub(crate) fn source_binder(&self) -> SourceBinder<'a, RootDatabase> {
153153
SourceBinder::new(self.db)
154154
}
155155
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())

crates/ra_assists/src/assists/apply_demorgan.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::invert_if::invert_boolean_expression;
2-
use hir::db::HirDatabase;
32
use ra_syntax::ast::{self, AstNode};
43

54
use crate::{Assist, AssistCtx, AssistId};
@@ -23,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId};
2322
// if !(x == 4 && y) {}
2423
// }
2524
// ```
26-
pub(crate) fn apply_demorgan(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
25+
pub(crate) fn apply_demorgan(ctx: AssistCtx) -> Option<Assist> {
2726
let expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
2827
let op = expr.op_kind()?;
2928
let op_range = expr.op_token()?.text_range();

crates/ra_assists/src/assists/auto_import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use hir::{db::HirDatabase, ModPath};
1+
use hir::ModPath;
22
use ra_syntax::{
33
ast::{self, AstNode},
44
SyntaxNode,
@@ -27,7 +27,7 @@ use crate::{
2727
// }
2828
// ```
2929
pub(crate) fn auto_import<F: ImportsLocator>(
30-
ctx: AssistCtx<impl HirDatabase>,
30+
ctx: AssistCtx,
3131
imports_locator: &mut F,
3232
) -> Option<Assist> {
3333
let path_to_import: ast::Path = ctx.find_node_at_offset()?;

0 commit comments

Comments
 (0)