aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs16
-rw-r--r--crates/ra_assists/src/assists/add_custom_impl.rs4
-rw-r--r--crates/ra_assists/src/assists/add_derive.rs3
-rw-r--r--crates/ra_assists/src/assists/add_explicit_type.rs4
-rw-r--r--crates/ra_assists/src/assists/add_impl.rs4
-rw-r--r--crates/ra_assists/src/assists/add_import.rs4
-rw-r--r--crates/ra_assists/src/assists/add_missing_impl_members.rs6
-rw-r--r--crates/ra_assists/src/assists/add_new.rs9
-rw-r--r--crates/ra_assists/src/assists/apply_demorgan.rs3
-rw-r--r--crates/ra_assists/src/assists/auto_import.rs4
-rw-r--r--crates/ra_assists/src/assists/change_visibility.rs7
-rw-r--r--crates/ra_assists/src/assists/early_return.rs3
-rw-r--r--crates/ra_assists/src/assists/fill_match_arms.rs2
-rw-r--r--crates/ra_assists/src/assists/flip_binexpr.rs3
-rw-r--r--crates/ra_assists/src/assists/flip_comma.rs3
-rw-r--r--crates/ra_assists/src/assists/flip_trait_bound.rs3
-rw-r--r--crates/ra_assists/src/assists/inline_local_variable.rs3
-rw-r--r--crates/ra_assists/src/assists/introduce_variable.rs3
-rw-r--r--crates/ra_assists/src/assists/invert_if.rs3
-rw-r--r--crates/ra_assists/src/assists/merge_match_arms.rs3
-rw-r--r--crates/ra_assists/src/assists/move_bounds.rs3
-rw-r--r--crates/ra_assists/src/assists/move_guard.rs5
-rw-r--r--crates/ra_assists/src/assists/raw_string.rs9
-rw-r--r--crates/ra_assists/src/assists/remove_dbg.rs3
-rw-r--r--crates/ra_assists/src/assists/replace_if_let_with_match.rs3
-rw-r--r--crates/ra_assists/src/assists/split_import.rs3
-rw-r--r--crates/ra_assists/src/lib.rs27
27 files changed, 59 insertions, 84 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index b6cac96fa..f32072dbd 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -1,6 +1,6 @@
1//! This module defines `AssistCtx` -- the API surface that is exposed to assists. 1//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
2use either::Either; 2use either::Either;
3use hir::{db::HirDatabase, InFile, SourceAnalyzer, SourceBinder}; 3use hir::{InFile, SourceAnalyzer, SourceBinder};
4use ra_db::{FileRange, SourceDatabase}; 4use ra_db::{FileRange, SourceDatabase};
5use ra_fmt::{leading_indent, reindent}; 5use ra_fmt::{leading_indent, reindent};
6use ra_ide_db::RootDatabase; 6use ra_ide_db::RootDatabase;
@@ -50,14 +50,14 @@ pub(crate) enum Assist {
50/// moment, because the LSP API is pretty awkward in this place, and it's much 50/// moment, because the LSP API is pretty awkward in this place, and it's much
51/// easier to just compute the edit eagerly :-) 51/// easier to just compute the edit eagerly :-)
52#[derive(Debug)] 52#[derive(Debug)]
53pub(crate) struct AssistCtx<'a, DB> { 53pub(crate) struct AssistCtx<'a> {
54 pub(crate) db: &'a DB, 54 pub(crate) db: &'a RootDatabase,
55 pub(crate) frange: FileRange, 55 pub(crate) frange: FileRange,
56 source_file: SourceFile, 56 source_file: SourceFile,
57 should_compute_edit: bool, 57 should_compute_edit: bool,
58} 58}
59 59
60impl<'a, DB> Clone for AssistCtx<'a, DB> { 60impl<'a> Clone for AssistCtx<'a> {
61 fn clone(&self) -> Self { 61 fn clone(&self) -> Self {
62 AssistCtx { 62 AssistCtx {
63 db: self.db, 63 db: self.db,
@@ -68,7 +68,7 @@ impl<'a, DB> Clone for AssistCtx<'a, DB> {
68 } 68 }
69} 69}
70 70
71impl<'a> AssistCtx<'a, RootDatabase> { 71impl<'a> AssistCtx<'a> {
72 pub(crate) fn with_ctx<F, T>( 72 pub(crate) fn with_ctx<F, T>(
73 db: &RootDatabase, 73 db: &RootDatabase,
74 frange: FileRange, 74 frange: FileRange,
@@ -76,7 +76,7 @@ impl<'a> AssistCtx<'a, RootDatabase> {
76 f: F, 76 f: F,
77 ) -> T 77 ) -> T
78 where 78 where
79 F: FnOnce(AssistCtx<RootDatabase>) -> T, 79 F: FnOnce(AssistCtx) -> T,
80 { 80 {
81 let parse = db.parse(frange.file_id); 81 let parse = db.parse(frange.file_id);
82 82
@@ -85,7 +85,7 @@ impl<'a> AssistCtx<'a, RootDatabase> {
85 } 85 }
86} 86}
87 87
88impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { 88impl<'a> AssistCtx<'a> {
89 pub(crate) fn add_assist( 89 pub(crate) fn add_assist(
90 self, 90 self,
91 id: AssistId, 91 id: AssistId,
@@ -149,7 +149,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
149 pub(crate) fn covering_element(&self) -> SyntaxElement { 149 pub(crate) fn covering_element(&self) -> SyntaxElement {
150 find_covering_element(self.source_file.syntax(), self.frange.range) 150 find_covering_element(self.source_file.syntax(), self.frange.range)
151 } 151 }
152 pub(crate) fn source_binder(&self) -> SourceBinder<'a, DB> { 152 pub(crate) fn source_binder(&self) -> SourceBinder<'a, RootDatabase> {
153 SourceBinder::new(self.db) 153 SourceBinder::new(self.db)
154 } 154 }
155 pub(crate) fn source_analyzer( 155 pub(crate) fn source_analyzer(
diff --git a/crates/ra_assists/src/assists/add_custom_impl.rs b/crates/ra_assists/src/assists/add_custom_impl.rs
index f91034967..7fdd816bf 100644
--- a/crates/ra_assists/src/assists/add_custom_impl.rs
+++ b/crates/ra_assists/src/assists/add_custom_impl.rs
@@ -1,7 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use crate::{Assist, AssistCtx, AssistId}; 3use crate::{Assist, AssistCtx, AssistId};
4use hir::db::HirDatabase; 4
5use join_to_string::join; 5use join_to_string::join;
6use ra_syntax::{ 6use ra_syntax::{
7 ast::{self, AstNode}, 7 ast::{self, AstNode},
@@ -29,7 +29,7 @@ const DERIVE_TRAIT: &str = "derive";
29// 29//
30// } 30// }
31// ``` 31// ```
32pub(crate) fn add_custom_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 32pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
33 let input = ctx.find_node_at_offset::<ast::AttrInput>()?; 33 let input = ctx.find_node_at_offset::<ast::AttrInput>()?;
34 let attr = input.syntax().parent().and_then(ast::Attr::cast)?; 34 let attr = input.syntax().parent().and_then(ast::Attr::cast)?;
35 35
diff --git a/crates/ra_assists/src/assists/add_derive.rs b/crates/ra_assists/src/assists/add_derive.rs
index 6d9af3905..b0d1a0a80 100644
--- a/crates/ra_assists/src/assists/add_derive.rs
+++ b/crates/ra_assists/src/assists/add_derive.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{ 1use ra_syntax::{
3 ast::{self, AstNode, AttrsOwner}, 2 ast::{self, AstNode, AttrsOwner},
4 SyntaxKind::{COMMENT, WHITESPACE}, 3 SyntaxKind::{COMMENT, WHITESPACE},
@@ -25,7 +24,7 @@ use crate::{Assist, AssistCtx, AssistId};
25// y: u32, 24// y: u32,
26// } 25// }
27// ``` 26// ```
28pub(crate) fn add_derive(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 27pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> {
29 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; 28 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
30 let node_start = derive_insertion_offset(&nominal)?; 29 let node_start = derive_insertion_offset(&nominal)?;
31 ctx.add_assist(AssistId("add_derive"), "Add `#[derive]`", |edit| { 30 ctx.add_assist(AssistId("add_derive"), "Add `#[derive]`", |edit| {
diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs
index 2443d5541..2cb9d2f48 100644
--- a/crates/ra_assists/src/assists/add_explicit_type.rs
+++ b/crates/ra_assists/src/assists/add_explicit_type.rs
@@ -1,4 +1,4 @@
1use hir::{db::HirDatabase, HirDisplay}; 1use hir::HirDisplay;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner}, 3 ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner},
4 TextRange, 4 TextRange,
@@ -21,7 +21,7 @@ use crate::{Assist, AssistCtx, AssistId};
21// let x: i32 = 92; 21// let x: i32 = 92;
22// } 22// }
23// ``` 23// ```
24pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 24pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option<Assist> {
25 let stmt = ctx.find_node_at_offset::<LetStmt>()?; 25 let stmt = ctx.find_node_at_offset::<LetStmt>()?;
26 let expr = stmt.initializer()?; 26 let expr = stmt.initializer()?;
27 let pat = stmt.pat()?; 27 let pat = stmt.pat()?;
diff --git a/crates/ra_assists/src/assists/add_impl.rs b/crates/ra_assists/src/assists/add_impl.rs
index 4b326c837..241b085fd 100644
--- a/crates/ra_assists/src/assists/add_impl.rs
+++ b/crates/ra_assists/src/assists/add_impl.rs
@@ -1,5 +1,5 @@
1use format_buf::format; 1use format_buf::format;
2use hir::db::HirDatabase; 2
3use join_to_string::join; 3use join_to_string::join;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, AstNode, NameOwner, TypeParamsOwner}, 5 ast::{self, AstNode, NameOwner, TypeParamsOwner},
@@ -27,7 +27,7 @@ use crate::{Assist, AssistCtx, AssistId};
27// 27//
28// } 28// }
29// ``` 29// ```
30pub(crate) fn add_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 30pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
31 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; 31 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
32 let name = nominal.name()?; 32 let name = nominal.name()?;
33 ctx.add_assist(AssistId("add_impl"), format!("Implement {}", name.text().as_str()), |edit| { 33 ctx.add_assist(AssistId("add_impl"), format!("Implement {}", name.text().as_str()), |edit| {
diff --git a/crates/ra_assists/src/assists/add_import.rs b/crates/ra_assists/src/assists/add_import.rs
index fc038df78..f03dddac8 100644
--- a/crates/ra_assists/src/assists/add_import.rs
+++ b/crates/ra_assists/src/assists/add_import.rs
@@ -1,4 +1,4 @@
1use hir::{self, db::HirDatabase, ModPath}; 1use hir::{self, ModPath};
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, NameOwner}, 3 ast::{self, NameOwner},
4 AstNode, Direction, SmolStr, 4 AstNode, Direction, SmolStr,
@@ -50,7 +50,7 @@ pub fn auto_import_text_edit(
50// 50//
51// fn process(map: HashMap<String, String>) {} 51// fn process(map: HashMap<String, String>) {}
52// ``` 52// ```
53pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 53pub(crate) fn add_import(ctx: AssistCtx) -> Option<Assist> {
54 let path: ast::Path = ctx.find_node_at_offset()?; 54 let path: ast::Path = ctx.find_node_at_offset()?;
55 // We don't want to mess with use statements 55 // We don't want to mess with use statements
56 if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() { 56 if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() {
diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs
index e4c22ad55..448697d31 100644
--- a/crates/ra_assists/src/assists/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs
@@ -43,7 +43,7 @@ enum AddMissingImplMembersMode {
43// 43//
44// } 44// }
45// ``` 45// ```
46pub(crate) fn add_missing_impl_members(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 46pub(crate) fn add_missing_impl_members(ctx: AssistCtx) -> Option<Assist> {
47 add_missing_impl_members_inner( 47 add_missing_impl_members_inner(
48 ctx, 48 ctx,
49 AddMissingImplMembersMode::NoDefaultMethods, 49 AddMissingImplMembersMode::NoDefaultMethods,
@@ -84,7 +84,7 @@ pub(crate) fn add_missing_impl_members(ctx: AssistCtx<impl HirDatabase>) -> Opti
84// 84//
85// } 85// }
86// ``` 86// ```
87pub(crate) fn add_missing_default_members(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 87pub(crate) fn add_missing_default_members(ctx: AssistCtx) -> Option<Assist> {
88 add_missing_impl_members_inner( 88 add_missing_impl_members_inner(
89 ctx, 89 ctx,
90 AddMissingImplMembersMode::DefaultMethodsOnly, 90 AddMissingImplMembersMode::DefaultMethodsOnly,
@@ -94,7 +94,7 @@ pub(crate) fn add_missing_default_members(ctx: AssistCtx<impl HirDatabase>) -> O
94} 94}
95 95
96fn add_missing_impl_members_inner( 96fn add_missing_impl_members_inner(
97 ctx: AssistCtx<impl HirDatabase>, 97 ctx: AssistCtx,
98 mode: AddMissingImplMembersMode, 98 mode: AddMissingImplMembersMode,
99 assist_id: &'static str, 99 assist_id: &'static str,
100 label: &'static str, 100 label: &'static str,
diff --git a/crates/ra_assists/src/assists/add_new.rs b/crates/ra_assists/src/assists/add_new.rs
index 8db63f762..a08639311 100644
--- a/crates/ra_assists/src/assists/add_new.rs
+++ b/crates/ra_assists/src/assists/add_new.rs
@@ -1,5 +1,5 @@
1use format_buf::format; 1use format_buf::format;
2use hir::{db::HirDatabase, InFile}; 2use hir::InFile;
3use join_to_string::join; 3use join_to_string::join;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{ 5 ast::{
@@ -31,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId};
31// } 31// }
32// 32//
33// ``` 33// ```
34pub(crate) fn add_new(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 34pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
35 let strukt = ctx.find_node_at_offset::<ast::StructDef>()?; 35 let strukt = ctx.find_node_at_offset::<ast::StructDef>()?;
36 36
37 // We want to only apply this to non-union structs with named fields 37 // 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 {
128// 128//
129// FIXME: change the new fn checking to a more semantic approach when that's more 129// FIXME: change the new fn checking to a more semantic approach when that's more
130// viable (e.g. we process proc macros, etc) 130// viable (e.g. we process proc macros, etc)
131fn find_struct_impl( 131fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<ast::ImplBlock>> {
132 ctx: &AssistCtx<impl HirDatabase>,
133 strukt: &ast::StructDef,
134) -> Option<Option<ast::ImplBlock>> {
135 let db = ctx.db; 132 let db = ctx.db;
136 let module = strukt.syntax().ancestors().find(|node| { 133 let module = strukt.syntax().ancestors().find(|node| {
137 ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind()) 134 ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())
diff --git a/crates/ra_assists/src/assists/apply_demorgan.rs b/crates/ra_assists/src/assists/apply_demorgan.rs
index 666dce4e6..dac6280ad 100644
--- a/crates/ra_assists/src/assists/apply_demorgan.rs
+++ b/crates/ra_assists/src/assists/apply_demorgan.rs
@@ -1,5 +1,4 @@
1use super::invert_if::invert_boolean_expression; 1use super::invert_if::invert_boolean_expression;
2use hir::db::HirDatabase;
3use ra_syntax::ast::{self, AstNode}; 2use ra_syntax::ast::{self, AstNode};
4 3
5use crate::{Assist, AssistCtx, AssistId}; 4use crate::{Assist, AssistCtx, AssistId};
@@ -23,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId};
23// if !(x == 4 && y) {} 22// if !(x == 4 && y) {}
24// } 23// }
25// ``` 24// ```
26pub(crate) fn apply_demorgan(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 25pub(crate) fn apply_demorgan(ctx: AssistCtx) -> Option<Assist> {
27 let expr = ctx.find_node_at_offset::<ast::BinExpr>()?; 26 let expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
28 let op = expr.op_kind()?; 27 let op = expr.op_kind()?;
29 let op_range = expr.op_token()?.text_range(); 28 let op_range = expr.op_token()?.text_range();
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs
index 2068256b0..48ab336b1 100644
--- a/crates/ra_assists/src/assists/auto_import.rs
+++ b/crates/ra_assists/src/assists/auto_import.rs
@@ -1,4 +1,4 @@
1use hir::{db::HirDatabase, ModPath}; 1use hir::ModPath;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode}, 3 ast::{self, AstNode},
4 SyntaxNode, 4 SyntaxNode,
@@ -27,7 +27,7 @@ use crate::{
27// } 27// }
28// ``` 28// ```
29pub(crate) fn auto_import<F: ImportsLocator>( 29pub(crate) fn auto_import<F: ImportsLocator>(
30 ctx: AssistCtx<impl HirDatabase>, 30 ctx: AssistCtx,
31 imports_locator: &mut F, 31 imports_locator: &mut F,
32) -> Option<Assist> { 32) -> Option<Assist> {
33 let path_to_import: ast::Path = ctx.find_node_at_offset()?; 33 let path_to_import: ast::Path = ctx.find_node_at_offset()?;
diff --git a/crates/ra_assists/src/assists/change_visibility.rs b/crates/ra_assists/src/assists/change_visibility.rs
index fd766bb46..f325b6f92 100644
--- a/crates/ra_assists/src/assists/change_visibility.rs
+++ b/crates/ra_assists/src/assists/change_visibility.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{ 1use ra_syntax::{
3 ast::{self, NameOwner, VisibilityOwner}, 2 ast::{self, NameOwner, VisibilityOwner},
4 AstNode, 3 AstNode,
@@ -22,14 +21,14 @@ use crate::{Assist, AssistCtx, AssistId};
22// ``` 21// ```
23// pub(crate) fn frobnicate() {} 22// pub(crate) fn frobnicate() {}
24// ``` 23// ```
25pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 24pub(crate) fn change_visibility(ctx: AssistCtx) -> Option<Assist> {
26 if let Some(vis) = ctx.find_node_at_offset::<ast::Visibility>() { 25 if let Some(vis) = ctx.find_node_at_offset::<ast::Visibility>() {
27 return change_vis(ctx, vis); 26 return change_vis(ctx, vis);
28 } 27 }
29 add_vis(ctx) 28 add_vis(ctx)
30} 29}
31 30
32fn add_vis(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 31fn add_vis(ctx: AssistCtx) -> Option<Assist> {
33 let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { 32 let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() {
34 T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, 33 T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true,
35 _ => false, 34 _ => false,
@@ -75,7 +74,7 @@ fn vis_offset(node: &SyntaxNode) -> TextUnit {
75 .unwrap_or_else(|| node.text_range().start()) 74 .unwrap_or_else(|| node.text_range().start())
76} 75}
77 76
78fn change_vis(ctx: AssistCtx<impl HirDatabase>, vis: ast::Visibility) -> Option<Assist> { 77fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> {
79 if vis.syntax().text() == "pub" { 78 if vis.syntax().text() == "pub" {
80 return ctx.add_assist( 79 return ctx.add_assist(
81 AssistId("change_visibility"), 80 AssistId("change_visibility"),
diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/assists/early_return.rs
index 487ee9eef..7d510b055 100644
--- a/crates/ra_assists/src/assists/early_return.rs
+++ b/crates/ra_assists/src/assists/early_return.rs
@@ -1,6 +1,5 @@
1use std::{iter::once, ops::RangeInclusive}; 1use std::{iter::once, ops::RangeInclusive};
2 2
3use hir::db::HirDatabase;
4use ra_syntax::{ 3use ra_syntax::{
5 algo::replace_children, 4 algo::replace_children,
6 ast::{self, edit::IndentLevel, make, Block, Pat::TupleStructPat}, 5 ast::{self, edit::IndentLevel, make, Block, Pat::TupleStructPat},
@@ -36,7 +35,7 @@ use crate::{
36// bar(); 35// bar();
37// } 36// }
38// ``` 37// ```
39pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 38pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> {
40 let if_expr: ast::IfExpr = ctx.find_node_at_offset()?; 39 let if_expr: ast::IfExpr = ctx.find_node_at_offset()?;
41 if if_expr.else_branch().is_some() { 40 if if_expr.else_branch().is_some() {
42 return None; 41 return None;
diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs
index 01758d23a..0908fc246 100644
--- a/crates/ra_assists/src/assists/fill_match_arms.rs
+++ b/crates/ra_assists/src/assists/fill_match_arms.rs
@@ -31,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId};
31// } 31// }
32// } 32// }
33// ``` 33// ```
34pub(crate) fn fill_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 34pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
35 let match_expr = ctx.find_node_at_offset::<ast::MatchExpr>()?; 35 let match_expr = ctx.find_node_at_offset::<ast::MatchExpr>()?;
36 let match_arm_list = match_expr.match_arm_list()?; 36 let match_arm_list = match_expr.match_arm_list()?;
37 37
diff --git a/crates/ra_assists/src/assists/flip_binexpr.rs b/crates/ra_assists/src/assists/flip_binexpr.rs
index 2074087cd..bfcc09e90 100644
--- a/crates/ra_assists/src/assists/flip_binexpr.rs
+++ b/crates/ra_assists/src/assists/flip_binexpr.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::ast::{AstNode, BinExpr, BinOp}; 1use ra_syntax::ast::{AstNode, BinExpr, BinOp};
3 2
4use crate::{Assist, AssistCtx, AssistId}; 3use crate::{Assist, AssistCtx, AssistId};
@@ -18,7 +17,7 @@ use crate::{Assist, AssistCtx, AssistId};
18// let _ = 2 + 90; 17// let _ = 2 + 90;
19// } 18// }
20// ``` 19// ```
21pub(crate) fn flip_binexpr(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 20pub(crate) fn flip_binexpr(ctx: AssistCtx) -> Option<Assist> {
22 let expr = ctx.find_node_at_offset::<BinExpr>()?; 21 let expr = ctx.find_node_at_offset::<BinExpr>()?;
23 let lhs = expr.lhs()?.syntax().clone(); 22 let lhs = expr.lhs()?.syntax().clone();
24 let rhs = expr.rhs()?.syntax().clone(); 23 let rhs = expr.rhs()?.syntax().clone();
diff --git a/crates/ra_assists/src/assists/flip_comma.rs b/crates/ra_assists/src/assists/flip_comma.rs
index dd0c405ed..1dacf29f8 100644
--- a/crates/ra_assists/src/assists/flip_comma.rs
+++ b/crates/ra_assists/src/assists/flip_comma.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{algo::non_trivia_sibling, Direction, T}; 1use ra_syntax::{algo::non_trivia_sibling, Direction, T};
3 2
4use crate::{Assist, AssistCtx, AssistId}; 3use crate::{Assist, AssistCtx, AssistId};
@@ -18,7 +17,7 @@ use crate::{Assist, AssistCtx, AssistId};
18// ((3, 4), (1, 2)); 17// ((3, 4), (1, 2));
19// } 18// }
20// ``` 19// ```
21pub(crate) fn flip_comma(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 20pub(crate) fn flip_comma(ctx: AssistCtx) -> Option<Assist> {
22 let comma = ctx.find_token_at_offset(T![,])?; 21 let comma = ctx.find_token_at_offset(T![,])?;
23 let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?; 22 let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?;
24 let next = non_trivia_sibling(comma.clone().into(), Direction::Next)?; 23 let next = non_trivia_sibling(comma.clone().into(), Direction::Next)?;
diff --git a/crates/ra_assists/src/assists/flip_trait_bound.rs b/crates/ra_assists/src/assists/flip_trait_bound.rs
index 50b3fa492..f56769624 100644
--- a/crates/ra_assists/src/assists/flip_trait_bound.rs
+++ b/crates/ra_assists/src/assists/flip_trait_bound.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{ 1use ra_syntax::{
3 algo::non_trivia_sibling, 2 algo::non_trivia_sibling,
4 ast::{self, AstNode}, 3 ast::{self, AstNode},
@@ -18,7 +17,7 @@ use crate::{Assist, AssistCtx, AssistId};
18// ``` 17// ```
19// fn foo<T: Copy + Clone>() { } 18// fn foo<T: Copy + Clone>() { }
20// ``` 19// ```
21pub(crate) fn flip_trait_bound(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 20pub(crate) fn flip_trait_bound(ctx: AssistCtx) -> Option<Assist> {
22 // We want to replicate the behavior of `flip_binexpr` by only suggesting 21 // We want to replicate the behavior of `flip_binexpr` by only suggesting
23 // the assist when the cursor is on a `+` 22 // the assist when the cursor is on a `+`
24 let plus = ctx.find_token_at_offset(T![+])?; 23 let plus = ctx.find_token_at_offset(T![+])?;
diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/assists/inline_local_variable.rs
index 83527d904..91b588243 100644
--- a/crates/ra_assists/src/assists/inline_local_variable.rs
+++ b/crates/ra_assists/src/assists/inline_local_variable.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{ 1use ra_syntax::{
3 ast::{self, AstNode, AstToken}, 2 ast::{self, AstNode, AstToken},
4 TextRange, 3 TextRange,
@@ -23,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId};
23// (1 + 2) * 4; 22// (1 + 2) * 4;
24// } 23// }
25// ``` 24// ```
26pub(crate) fn inline_local_variable(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 25pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> {
27 let let_stmt = ctx.find_node_at_offset::<ast::LetStmt>()?; 26 let let_stmt = ctx.find_node_at_offset::<ast::LetStmt>()?;
28 let bind_pat = match let_stmt.pat()? { 27 let bind_pat = match let_stmt.pat()? {
29 ast::Pat::BindPat(pat) => pat, 28 ast::Pat::BindPat(pat) => pat,
diff --git a/crates/ra_assists/src/assists/introduce_variable.rs b/crates/ra_assists/src/assists/introduce_variable.rs
index 19e211e0f..7312ce687 100644
--- a/crates/ra_assists/src/assists/introduce_variable.rs
+++ b/crates/ra_assists/src/assists/introduce_variable.rs
@@ -1,5 +1,4 @@
1use format_buf::format; 1use format_buf::format;
2use hir::db::HirDatabase;
3use ra_syntax::{ 2use ra_syntax::{
4 ast::{self, AstNode}, 3 ast::{self, AstNode},
5 SyntaxKind::{ 4 SyntaxKind::{
@@ -28,7 +27,7 @@ use crate::{Assist, AssistCtx, AssistId};
28// var_name * 4; 27// var_name * 4;
29// } 28// }
30// ``` 29// ```
31pub(crate) fn introduce_variable(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 30pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option<Assist> {
32 if ctx.frange.range.is_empty() { 31 if ctx.frange.range.is_empty() {
33 return None; 32 return None;
34 } 33 }
diff --git a/crates/ra_assists/src/assists/invert_if.rs b/crates/ra_assists/src/assists/invert_if.rs
index 16352c040..694c3642c 100644
--- a/crates/ra_assists/src/assists/invert_if.rs
+++ b/crates/ra_assists/src/assists/invert_if.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::ast::{self, AstNode}; 1use ra_syntax::ast::{self, AstNode};
3use ra_syntax::T; 2use ra_syntax::T;
4 3
@@ -23,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId};
23// } 22// }
24// ``` 23// ```
25 24
26pub(crate) fn invert_if(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 25pub(crate) fn invert_if(ctx: AssistCtx) -> Option<Assist> {
27 let if_keyword = ctx.find_token_at_offset(T![if])?; 26 let if_keyword = ctx.find_token_at_offset(T![if])?;
28 let expr = ast::IfExpr::cast(if_keyword.parent())?; 27 let expr = ast::IfExpr::cast(if_keyword.parent())?;
29 let if_range = if_keyword.text_range(); 28 let if_range = if_keyword.text_range();
diff --git a/crates/ra_assists/src/assists/merge_match_arms.rs b/crates/ra_assists/src/assists/merge_match_arms.rs
index 64c9379da..670614dd8 100644
--- a/crates/ra_assists/src/assists/merge_match_arms.rs
+++ b/crates/ra_assists/src/assists/merge_match_arms.rs
@@ -1,6 +1,5 @@
1use std::iter::successors; 1use std::iter::successors;
2 2
3use hir::db::HirDatabase;
4use ra_syntax::{ 3use ra_syntax::{
5 ast::{self, AstNode}, 4 ast::{self, AstNode},
6 Direction, TextUnit, 5 Direction, TextUnit,
@@ -32,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId, TextRange};
32// } 31// }
33// } 32// }
34// ``` 33// ```
35pub(crate) fn merge_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 34pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option<Assist> {
36 let current_arm = ctx.find_node_at_offset::<ast::MatchArm>()?; 35 let current_arm = ctx.find_node_at_offset::<ast::MatchArm>()?;
37 // Don't try to handle arms with guards for now - can add support for this later 36 // Don't try to handle arms with guards for now - can add support for this later
38 if current_arm.guard().is_some() { 37 if current_arm.guard().is_some() {
diff --git a/crates/ra_assists/src/assists/move_bounds.rs b/crates/ra_assists/src/assists/move_bounds.rs
index 355adddc3..90793b5fc 100644
--- a/crates/ra_assists/src/assists/move_bounds.rs
+++ b/crates/ra_assists/src/assists/move_bounds.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{ 1use ra_syntax::{
3 ast::{self, edit, make, AstNode, NameOwner, TypeBoundsOwner}, 2 ast::{self, edit, make, AstNode, NameOwner, TypeBoundsOwner},
4 SyntaxElement, 3 SyntaxElement,
@@ -22,7 +21,7 @@ use crate::{Assist, AssistCtx, AssistId};
22// f(x) 21// f(x)
23// } 22// }
24// ``` 23// ```
25pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 24pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option<Assist> {
26 let type_param_list = ctx.find_node_at_offset::<ast::TypeParamList>()?; 25 let type_param_list = ctx.find_node_at_offset::<ast::TypeParamList>()?;
27 26
28 let mut type_params = type_param_list.type_params(); 27 let mut type_params = type_param_list.type_params();
diff --git a/crates/ra_assists/src/assists/move_guard.rs b/crates/ra_assists/src/assists/move_guard.rs
index 41a31e677..2b91ce7c4 100644
--- a/crates/ra_assists/src/assists/move_guard.rs
+++ b/crates/ra_assists/src/assists/move_guard.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{ 1use ra_syntax::{
3 ast, 2 ast,
4 ast::{AstNode, AstToken, IfExpr, MatchArm}, 3 ast::{AstNode, AstToken, IfExpr, MatchArm},
@@ -32,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId};
32// } 31// }
33// } 32// }
34// ``` 33// ```
35pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 34pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option<Assist> {
36 let match_arm = ctx.find_node_at_offset::<MatchArm>()?; 35 let match_arm = ctx.find_node_at_offset::<MatchArm>()?;
37 let guard = match_arm.guard()?; 36 let guard = match_arm.guard()?;
38 let space_before_guard = guard.syntax().prev_sibling_or_token(); 37 let space_before_guard = guard.syntax().prev_sibling_or_token();
@@ -89,7 +88,7 @@ pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx<impl HirDatabase>) -> Option
89// } 88// }
90// } 89// }
91// ``` 90// ```
92pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 91pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> {
93 let match_arm: MatchArm = ctx.find_node_at_offset::<MatchArm>()?; 92 let match_arm: MatchArm = ctx.find_node_at_offset::<MatchArm>()?;
94 let last_match_pat = match_arm.pats().last()?; 93 let last_match_pat = match_arm.pats().last()?;
95 94
diff --git a/crates/ra_assists/src/assists/raw_string.rs b/crates/ra_assists/src/assists/raw_string.rs
index e79c51673..2c0a1e126 100644
--- a/crates/ra_assists/src/assists/raw_string.rs
+++ b/crates/ra_assists/src/assists/raw_string.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{ 1use ra_syntax::{
3 ast, AstToken, 2 ast, AstToken,
4 SyntaxKind::{RAW_STRING, STRING}, 3 SyntaxKind::{RAW_STRING, STRING},
@@ -22,7 +21,7 @@ use crate::{Assist, AssistCtx, AssistId};
22// r#"Hello, World!"#; 21// r#"Hello, World!"#;
23// } 22// }
24// ``` 23// ```
25pub(crate) fn make_raw_string(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 24pub(crate) fn make_raw_string(ctx: AssistCtx) -> Option<Assist> {
26 let token = ctx.find_token_at_offset(STRING).and_then(ast::String::cast)?; 25 let token = ctx.find_token_at_offset(STRING).and_then(ast::String::cast)?;
27 let value = token.value()?; 26 let value = token.value()?;
28 ctx.add_assist(AssistId("make_raw_string"), "Rewrite as raw string", |edit| { 27 ctx.add_assist(AssistId("make_raw_string"), "Rewrite as raw string", |edit| {
@@ -51,7 +50,7 @@ pub(crate) fn make_raw_string(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist
51// "Hello, \"World!\""; 50// "Hello, \"World!\"";
52// } 51// }
53// ``` 52// ```
54pub(crate) fn make_usual_string(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 53pub(crate) fn make_usual_string(ctx: AssistCtx) -> Option<Assist> {
55 let token = ctx.find_token_at_offset(RAW_STRING).and_then(ast::RawString::cast)?; 54 let token = ctx.find_token_at_offset(RAW_STRING).and_then(ast::RawString::cast)?;
56 let value = token.value()?; 55 let value = token.value()?;
57 ctx.add_assist(AssistId("make_usual_string"), "Rewrite as regular string", |edit| { 56 ctx.add_assist(AssistId("make_usual_string"), "Rewrite as regular string", |edit| {
@@ -77,7 +76,7 @@ pub(crate) fn make_usual_string(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi
77// r##"Hello, World!"##; 76// r##"Hello, World!"##;
78// } 77// }
79// ``` 78// ```
80pub(crate) fn add_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 79pub(crate) fn add_hash(ctx: AssistCtx) -> Option<Assist> {
81 let token = ctx.find_token_at_offset(RAW_STRING)?; 80 let token = ctx.find_token_at_offset(RAW_STRING)?;
82 ctx.add_assist(AssistId("add_hash"), "Add # to raw string", |edit| { 81 ctx.add_assist(AssistId("add_hash"), "Add # to raw string", |edit| {
83 edit.target(token.text_range()); 82 edit.target(token.text_range());
@@ -101,7 +100,7 @@ pub(crate) fn add_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
101// r"Hello, World!"; 100// r"Hello, World!";
102// } 101// }
103// ``` 102// ```
104pub(crate) fn remove_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 103pub(crate) fn remove_hash(ctx: AssistCtx) -> Option<Assist> {
105 let token = ctx.find_token_at_offset(RAW_STRING)?; 104 let token = ctx.find_token_at_offset(RAW_STRING)?;
106 let text = token.text().as_str(); 105 let text = token.text().as_str();
107 if text.starts_with("r\"") { 106 if text.starts_with("r\"") {
diff --git a/crates/ra_assists/src/assists/remove_dbg.rs b/crates/ra_assists/src/assists/remove_dbg.rs
index cf211ab84..5085649b4 100644
--- a/crates/ra_assists/src/assists/remove_dbg.rs
+++ b/crates/ra_assists/src/assists/remove_dbg.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_syntax::{ 1use ra_syntax::{
3 ast::{self, AstNode}, 2 ast::{self, AstNode},
4 TextUnit, T, 3 TextUnit, T,
@@ -21,7 +20,7 @@ use crate::{Assist, AssistCtx, AssistId};
21// 92; 20// 92;
22// } 21// }
23// ``` 22// ```
24pub(crate) fn remove_dbg(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 23pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option<Assist> {
25 let macro_call = ctx.find_node_at_offset::<ast::MacroCall>()?; 24 let macro_call = ctx.find_node_at_offset::<ast::MacroCall>()?;
26 25
27 if !is_valid_macrocall(&macro_call, "dbg")? { 26 if !is_valid_macrocall(&macro_call, "dbg")? {
diff --git a/crates/ra_assists/src/assists/replace_if_let_with_match.rs b/crates/ra_assists/src/assists/replace_if_let_with_match.rs
index c8b13b7b3..e6cd50bc1 100644
--- a/crates/ra_assists/src/assists/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/assists/replace_if_let_with_match.rs
@@ -1,4 +1,3 @@
1use hir::db::HirDatabase;
2use ra_fmt::unwrap_trivial_block; 1use ra_fmt::unwrap_trivial_block;
3use ra_syntax::{ 2use ra_syntax::{
4 ast::{self, make}, 3 ast::{self, make},
@@ -34,7 +33,7 @@ use ast::edit::IndentLevel;
34// } 33// }
35// } 34// }
36// ``` 35// ```
37pub(crate) fn replace_if_let_with_match(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 36pub(crate) fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> {
38 let if_expr: ast::IfExpr = ctx.find_node_at_offset()?; 37 let if_expr: ast::IfExpr = ctx.find_node_at_offset()?;
39 let cond = if_expr.condition()?; 38 let cond = if_expr.condition()?;
40 let pat = cond.pat()?; 39 let pat = cond.pat()?;
diff --git a/crates/ra_assists/src/assists/split_import.rs b/crates/ra_assists/src/assists/split_import.rs
index 6038c4858..2c3f07a79 100644
--- a/crates/ra_assists/src/assists/split_import.rs
+++ b/crates/ra_assists/src/assists/split_import.rs
@@ -1,6 +1,5 @@
1use std::iter::successors; 1use std::iter::successors;
2 2
3use hir::db::HirDatabase;
4use ra_syntax::{ast, AstNode, TextUnit, T}; 3use ra_syntax::{ast, AstNode, TextUnit, T};
5 4
6use crate::{Assist, AssistCtx, AssistId}; 5use crate::{Assist, AssistCtx, AssistId};
@@ -16,7 +15,7 @@ use crate::{Assist, AssistCtx, AssistId};
16// ``` 15// ```
17// use std::{collections::HashMap}; 16// use std::{collections::HashMap};
18// ``` 17// ```
19pub(crate) fn split_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 18pub(crate) fn split_import(ctx: AssistCtx) -> Option<Assist> {
20 let colon_colon = ctx.find_token_at_offset(T![::])?; 19 let colon_colon = ctx.find_token_at_offset(T![::])?;
21 let path = ast::Path::cast(colon_colon.parent())?; 20 let path = ast::Path::cast(colon_colon.parent())?;
22 let top_path = successors(Some(path), |it| it.parent_path()).last()?; 21 let top_path = successors(Some(path), |it| it.parent_path()).last()?;
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index be6e06842..ad8438b6c 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -148,7 +148,6 @@ fn sort_assists(assists: &mut Vec<ResolvedAssist>) {
148 148
149mod assists { 149mod assists {
150 use crate::{Assist, AssistCtx, ImportsLocator}; 150 use crate::{Assist, AssistCtx, ImportsLocator};
151 use hir::db::HirDatabase;
152 151
153 mod add_derive; 152 mod add_derive;
154 mod add_explicit_type; 153 mod add_explicit_type;
@@ -176,7 +175,7 @@ mod assists {
176 mod move_bounds; 175 mod move_bounds;
177 mod early_return; 176 mod early_return;
178 177
179 pub(crate) fn all<DB: HirDatabase>() -> &'static [fn(AssistCtx<DB>) -> Option<Assist>] { 178 pub(crate) fn all() -> &'static [fn(AssistCtx) -> Option<Assist>] {
180 &[ 179 &[
181 add_derive::add_derive, 180 add_derive::add_derive,
182 add_explicit_type::add_explicit_type, 181 add_explicit_type::add_explicit_type,
@@ -210,8 +209,8 @@ mod assists {
210 ] 209 ]
211 } 210 }
212 211
213 pub(crate) fn all_with_imports_locator<'a, DB: HirDatabase, F: ImportsLocator>( 212 pub(crate) fn all_with_imports_locator<'a, F: ImportsLocator>(
214 ) -> &'a [fn(AssistCtx<DB>, &mut F) -> Option<Assist>] { 213 ) -> &'a [fn(AssistCtx, &mut F) -> Option<Assist>] {
215 &[auto_import::auto_import] 214 &[auto_import::auto_import]
216 } 215 }
217} 216}
@@ -274,11 +273,7 @@ mod helpers {
274 } 273 }
275 } 274 }
276 275
277 pub(crate) fn check_assist( 276 pub(crate) fn check_assist(assist: fn(AssistCtx) -> Option<Assist>, before: &str, after: &str) {
278 assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>,
279 before: &str,
280 after: &str,
281 ) {
282 let (before_cursor_pos, before) = extract_offset(before); 277 let (before_cursor_pos, before) = extract_offset(before);
283 let (db, file_id) = RootDatabase::with_single_file(&before); 278 let (db, file_id) = RootDatabase::with_single_file(&before);
284 let frange = 279 let frange =
@@ -303,7 +298,7 @@ mod helpers {
303 } 298 }
304 299
305 pub(crate) fn check_assist_with_imports_locator<F: ImportsLocator>( 300 pub(crate) fn check_assist_with_imports_locator<F: ImportsLocator>(
306 assist: fn(AssistCtx<RootDatabase>, &mut F) -> Option<Assist>, 301 assist: fn(AssistCtx, &mut F) -> Option<Assist>,
307 imports_locator_provider: fn(db: Arc<RootDatabase>, file_id: FileId) -> F, 302 imports_locator_provider: fn(db: Arc<RootDatabase>, file_id: FileId) -> F,
308 before: &str, 303 before: &str,
309 after: &str, 304 after: &str,
@@ -335,7 +330,7 @@ mod helpers {
335 } 330 }
336 331
337 pub(crate) fn check_assist_range( 332 pub(crate) fn check_assist_range(
338 assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>, 333 assist: fn(AssistCtx) -> Option<Assist>,
339 before: &str, 334 before: &str,
340 after: &str, 335 after: &str,
341 ) { 336 ) {
@@ -357,7 +352,7 @@ mod helpers {
357 } 352 }
358 353
359 pub(crate) fn check_assist_target( 354 pub(crate) fn check_assist_target(
360 assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>, 355 assist: fn(AssistCtx) -> Option<Assist>,
361 before: &str, 356 before: &str,
362 target: &str, 357 target: &str,
363 ) { 358 ) {
@@ -377,7 +372,7 @@ mod helpers {
377 } 372 }
378 373
379 pub(crate) fn check_assist_range_target( 374 pub(crate) fn check_assist_range_target(
380 assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>, 375 assist: fn(AssistCtx) -> Option<Assist>,
381 before: &str, 376 before: &str,
382 target: &str, 377 target: &str,
383 ) { 378 ) {
@@ -396,7 +391,7 @@ mod helpers {
396 } 391 }
397 392
398 pub(crate) fn check_assist_not_applicable( 393 pub(crate) fn check_assist_not_applicable(
399 assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>, 394 assist: fn(AssistCtx) -> Option<Assist>,
400 before: &str, 395 before: &str,
401 ) { 396 ) {
402 let (before_cursor_pos, before) = extract_offset(before); 397 let (before_cursor_pos, before) = extract_offset(before);
@@ -408,7 +403,7 @@ mod helpers {
408 } 403 }
409 404
410 pub(crate) fn check_assist_with_imports_locator_not_applicable<F: ImportsLocator>( 405 pub(crate) fn check_assist_with_imports_locator_not_applicable<F: ImportsLocator>(
411 assist: fn(AssistCtx<RootDatabase>, &mut F) -> Option<Assist>, 406 assist: fn(AssistCtx, &mut F) -> Option<Assist>,
412 imports_locator_provider: fn(db: Arc<RootDatabase>, file_id: FileId) -> F, 407 imports_locator_provider: fn(db: Arc<RootDatabase>, file_id: FileId) -> F,
413 before: &str, 408 before: &str,
414 ) { 409 ) {
@@ -424,7 +419,7 @@ mod helpers {
424 } 419 }
425 420
426 pub(crate) fn check_assist_range_not_applicable( 421 pub(crate) fn check_assist_range_not_applicable(
427 assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>, 422 assist: fn(AssistCtx) -> Option<Assist>,
428 before: &str, 423 before: &str,
429 ) { 424 ) {
430 let (range, before) = extract_range(before); 425 let (range, before) = extract_range(before);