Assists are not generic

This commit is contained in:
Aleksey Kladov 2020-02-06 16:58:57 +01:00
parent f8965ffafd
commit cf812c12d1
27 changed files with 59 additions and 84 deletions

View File

@ -1,6 +1,6 @@
//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
use either::Either;
use hir::{db::HirDatabase, InFile, SourceAnalyzer, SourceBinder};
use hir::{InFile, SourceAnalyzer, SourceBinder};
use ra_db::{FileRange, SourceDatabase};
use ra_fmt::{leading_indent, reindent};
use ra_ide_db::RootDatabase;
@ -50,14 +50,14 @@ pub(crate) enum Assist {
/// moment, because the LSP API is pretty awkward in this place, and it's much
/// easier to just compute the edit eagerly :-)
#[derive(Debug)]
pub(crate) struct AssistCtx<'a, DB> {
pub(crate) db: &'a DB,
pub(crate) struct AssistCtx<'a> {
pub(crate) db: &'a RootDatabase,
pub(crate) frange: FileRange,
source_file: SourceFile,
should_compute_edit: bool,
}
impl<'a, DB> Clone for AssistCtx<'a, DB> {
impl<'a> Clone for AssistCtx<'a> {
fn clone(&self) -> Self {
AssistCtx {
db: self.db,
@ -68,7 +68,7 @@ impl<'a, DB> Clone for AssistCtx<'a, DB> {
}
}
impl<'a> AssistCtx<'a, RootDatabase> {
impl<'a> AssistCtx<'a> {
pub(crate) fn with_ctx<F, T>(
db: &RootDatabase,
frange: FileRange,
@ -76,7 +76,7 @@ impl<'a> AssistCtx<'a, RootDatabase> {
f: F,
) -> T
where
F: FnOnce(AssistCtx<RootDatabase>) -> T,
F: FnOnce(AssistCtx) -> T,
{
let parse = db.parse(frange.file_id);
@ -85,7 +85,7 @@ impl<'a> AssistCtx<'a, RootDatabase> {
}
}
impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
impl<'a> AssistCtx<'a> {
pub(crate) fn add_assist(
self,
id: AssistId,
@ -149,7 +149,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
pub(crate) fn covering_element(&self) -> SyntaxElement {
find_covering_element(self.source_file.syntax(), self.frange.range)
}
pub(crate) fn source_binder(&self) -> SourceBinder<'a, DB> {
pub(crate) fn source_binder(&self) -> SourceBinder<'a, RootDatabase> {
SourceBinder::new(self.db)
}
pub(crate) fn source_analyzer(

View File

@ -1,7 +1,7 @@
//! FIXME: write short doc here
use crate::{Assist, AssistCtx, AssistId};
use hir::db::HirDatabase;
use join_to_string::join;
use ra_syntax::{
ast::{self, AstNode},
@ -29,7 +29,7 @@ const DERIVE_TRAIT: &str = "derive";
//
// }
// ```
pub(crate) fn add_custom_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
let input = ctx.find_node_at_offset::<ast::AttrInput>()?;
let attr = input.syntax().parent().and_then(ast::Attr::cast)?;

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{
ast::{self, AstNode, AttrsOwner},
SyntaxKind::{COMMENT, WHITESPACE},
@ -25,7 +24,7 @@ use crate::{Assist, AssistCtx, AssistId};
// y: u32,
// }
// ```
pub(crate) fn add_derive(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> {
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
let node_start = derive_insertion_offset(&nominal)?;
ctx.add_assist(AssistId("add_derive"), "Add `#[derive]`", |edit| {

View File

@ -1,4 +1,4 @@
use hir::{db::HirDatabase, HirDisplay};
use hir::HirDisplay;
use ra_syntax::{
ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner},
TextRange,
@ -21,7 +21,7 @@ use crate::{Assist, AssistCtx, AssistId};
// let x: i32 = 92;
// }
// ```
pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option<Assist> {
let stmt = ctx.find_node_at_offset::<LetStmt>()?;
let expr = stmt.initializer()?;
let pat = stmt.pat()?;

View File

@ -1,5 +1,5 @@
use format_buf::format;
use hir::db::HirDatabase;
use join_to_string::join;
use ra_syntax::{
ast::{self, AstNode, NameOwner, TypeParamsOwner},
@ -27,7 +27,7 @@ use crate::{Assist, AssistCtx, AssistId};
//
// }
// ```
pub(crate) fn add_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
let name = nominal.name()?;
ctx.add_assist(AssistId("add_impl"), format!("Implement {}", name.text().as_str()), |edit| {

View File

@ -1,4 +1,4 @@
use hir::{self, db::HirDatabase, ModPath};
use hir::{self, ModPath};
use ra_syntax::{
ast::{self, NameOwner},
AstNode, Direction, SmolStr,
@ -50,7 +50,7 @@ pub fn auto_import_text_edit(
//
// fn process(map: HashMap<String, String>) {}
// ```
pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_import(ctx: AssistCtx) -> Option<Assist> {
let path: ast::Path = ctx.find_node_at_offset()?;
// We don't want to mess with use statements
if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() {

View File

@ -43,7 +43,7 @@ enum AddMissingImplMembersMode {
//
// }
// ```
pub(crate) fn add_missing_impl_members(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_missing_impl_members(ctx: AssistCtx) -> Option<Assist> {
add_missing_impl_members_inner(
ctx,
AddMissingImplMembersMode::NoDefaultMethods,
@ -84,7 +84,7 @@ pub(crate) fn add_missing_impl_members(ctx: AssistCtx<impl HirDatabase>) -> Opti
//
// }
// ```
pub(crate) fn add_missing_default_members(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_missing_default_members(ctx: AssistCtx) -> Option<Assist> {
add_missing_impl_members_inner(
ctx,
AddMissingImplMembersMode::DefaultMethodsOnly,
@ -94,7 +94,7 @@ pub(crate) fn add_missing_default_members(ctx: AssistCtx<impl HirDatabase>) -> O
}
fn add_missing_impl_members_inner(
ctx: AssistCtx<impl HirDatabase>,
ctx: AssistCtx,
mode: AddMissingImplMembersMode,
assist_id: &'static str,
label: &'static str,

View File

@ -1,5 +1,5 @@
use format_buf::format;
use hir::{db::HirDatabase, InFile};
use hir::InFile;
use join_to_string::join;
use ra_syntax::{
ast::{
@ -31,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId};
// }
//
// ```
pub(crate) fn add_new(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
let strukt = ctx.find_node_at_offset::<ast::StructDef>()?;
// 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 {
//
// FIXME: change the new fn checking to a more semantic approach when that's more
// viable (e.g. we process proc macros, etc)
fn find_struct_impl(
ctx: &AssistCtx<impl HirDatabase>,
strukt: &ast::StructDef,
) -> Option<Option<ast::ImplBlock>> {
fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<ast::ImplBlock>> {
let db = ctx.db;
let module = strukt.syntax().ancestors().find(|node| {
ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())

View File

@ -1,5 +1,4 @@
use super::invert_if::invert_boolean_expression;
use hir::db::HirDatabase;
use ra_syntax::ast::{self, AstNode};
use crate::{Assist, AssistCtx, AssistId};
@ -23,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId};
// if !(x == 4 && y) {}
// }
// ```
pub(crate) fn apply_demorgan(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn apply_demorgan(ctx: AssistCtx) -> Option<Assist> {
let expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
let op = expr.op_kind()?;
let op_range = expr.op_token()?.text_range();

View File

@ -1,4 +1,4 @@
use hir::{db::HirDatabase, ModPath};
use hir::ModPath;
use ra_syntax::{
ast::{self, AstNode},
SyntaxNode,
@ -27,7 +27,7 @@ use crate::{
// }
// ```
pub(crate) fn auto_import<F: ImportsLocator>(
ctx: AssistCtx<impl HirDatabase>,
ctx: AssistCtx,
imports_locator: &mut F,
) -> Option<Assist> {
let path_to_import: ast::Path = ctx.find_node_at_offset()?;

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{
ast::{self, NameOwner, VisibilityOwner},
AstNode,
@ -22,14 +21,14 @@ use crate::{Assist, AssistCtx, AssistId};
// ```
// pub(crate) fn frobnicate() {}
// ```
pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn change_visibility(ctx: AssistCtx) -> Option<Assist> {
if let Some(vis) = ctx.find_node_at_offset::<ast::Visibility>() {
return change_vis(ctx, vis);
}
add_vis(ctx)
}
fn add_vis(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
fn add_vis(ctx: AssistCtx) -> Option<Assist> {
let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() {
T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true,
_ => false,
@ -75,7 +74,7 @@ fn vis_offset(node: &SyntaxNode) -> TextUnit {
.unwrap_or_else(|| node.text_range().start())
}
fn change_vis(ctx: AssistCtx<impl HirDatabase>, vis: ast::Visibility) -> Option<Assist> {
fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> {
if vis.syntax().text() == "pub" {
return ctx.add_assist(
AssistId("change_visibility"),

View File

@ -1,6 +1,5 @@
use std::{iter::once, ops::RangeInclusive};
use hir::db::HirDatabase;
use ra_syntax::{
algo::replace_children,
ast::{self, edit::IndentLevel, make, Block, Pat::TupleStructPat},
@ -36,7 +35,7 @@ use crate::{
// bar();
// }
// ```
pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> {
let if_expr: ast::IfExpr = ctx.find_node_at_offset()?;
if if_expr.else_branch().is_some() {
return None;

View File

@ -31,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId};
// }
// }
// ```
pub(crate) fn fill_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
let match_expr = ctx.find_node_at_offset::<ast::MatchExpr>()?;
let match_arm_list = match_expr.match_arm_list()?;

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::ast::{AstNode, BinExpr, BinOp};
use crate::{Assist, AssistCtx, AssistId};
@ -18,7 +17,7 @@ use crate::{Assist, AssistCtx, AssistId};
// let _ = 2 + 90;
// }
// ```
pub(crate) fn flip_binexpr(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn flip_binexpr(ctx: AssistCtx) -> Option<Assist> {
let expr = ctx.find_node_at_offset::<BinExpr>()?;
let lhs = expr.lhs()?.syntax().clone();
let rhs = expr.rhs()?.syntax().clone();

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{algo::non_trivia_sibling, Direction, T};
use crate::{Assist, AssistCtx, AssistId};
@ -18,7 +17,7 @@ use crate::{Assist, AssistCtx, AssistId};
// ((3, 4), (1, 2));
// }
// ```
pub(crate) fn flip_comma(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn flip_comma(ctx: AssistCtx) -> Option<Assist> {
let comma = ctx.find_token_at_offset(T![,])?;
let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?;
let next = non_trivia_sibling(comma.clone().into(), Direction::Next)?;

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{
algo::non_trivia_sibling,
ast::{self, AstNode},
@ -18,7 +17,7 @@ use crate::{Assist, AssistCtx, AssistId};
// ```
// fn foo<T: Copy + Clone>() { }
// ```
pub(crate) fn flip_trait_bound(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn flip_trait_bound(ctx: AssistCtx) -> Option<Assist> {
// We want to replicate the behavior of `flip_binexpr` by only suggesting
// the assist when the cursor is on a `+`
let plus = ctx.find_token_at_offset(T![+])?;

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{
ast::{self, AstNode, AstToken},
TextRange,
@ -23,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId};
// (1 + 2) * 4;
// }
// ```
pub(crate) fn inline_local_variable(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> {
let let_stmt = ctx.find_node_at_offset::<ast::LetStmt>()?;
let bind_pat = match let_stmt.pat()? {
ast::Pat::BindPat(pat) => pat,

View File

@ -1,5 +1,4 @@
use format_buf::format;
use hir::db::HirDatabase;
use ra_syntax::{
ast::{self, AstNode},
SyntaxKind::{
@ -28,7 +27,7 @@ use crate::{Assist, AssistCtx, AssistId};
// var_name * 4;
// }
// ```
pub(crate) fn introduce_variable(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option<Assist> {
if ctx.frange.range.is_empty() {
return None;
}

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::ast::{self, AstNode};
use ra_syntax::T;
@ -23,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId};
// }
// ```
pub(crate) fn invert_if(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn invert_if(ctx: AssistCtx) -> Option<Assist> {
let if_keyword = ctx.find_token_at_offset(T![if])?;
let expr = ast::IfExpr::cast(if_keyword.parent())?;
let if_range = if_keyword.text_range();

View File

@ -1,6 +1,5 @@
use std::iter::successors;
use hir::db::HirDatabase;
use ra_syntax::{
ast::{self, AstNode},
Direction, TextUnit,
@ -32,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId, TextRange};
// }
// }
// ```
pub(crate) fn merge_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option<Assist> {
let current_arm = ctx.find_node_at_offset::<ast::MatchArm>()?;
// Don't try to handle arms with guards for now - can add support for this later
if current_arm.guard().is_some() {

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{
ast::{self, edit, make, AstNode, NameOwner, TypeBoundsOwner},
SyntaxElement,
@ -22,7 +21,7 @@ use crate::{Assist, AssistCtx, AssistId};
// f(x)
// }
// ```
pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option<Assist> {
let type_param_list = ctx.find_node_at_offset::<ast::TypeParamList>()?;
let mut type_params = type_param_list.type_params();

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{
ast,
ast::{AstNode, AstToken, IfExpr, MatchArm},
@ -32,7 +31,7 @@ use crate::{Assist, AssistCtx, AssistId};
// }
// }
// ```
pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option<Assist> {
let match_arm = ctx.find_node_at_offset::<MatchArm>()?;
let guard = match_arm.guard()?;
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
// }
// }
// ```
pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> {
let match_arm: MatchArm = ctx.find_node_at_offset::<MatchArm>()?;
let last_match_pat = match_arm.pats().last()?;

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{
ast, AstToken,
SyntaxKind::{RAW_STRING, STRING},
@ -22,7 +21,7 @@ use crate::{Assist, AssistCtx, AssistId};
// r#"Hello, World!"#;
// }
// ```
pub(crate) fn make_raw_string(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn make_raw_string(ctx: AssistCtx) -> Option<Assist> {
let token = ctx.find_token_at_offset(STRING).and_then(ast::String::cast)?;
let value = token.value()?;
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
// "Hello, \"World!\"";
// }
// ```
pub(crate) fn make_usual_string(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn make_usual_string(ctx: AssistCtx) -> Option<Assist> {
let token = ctx.find_token_at_offset(RAW_STRING).and_then(ast::RawString::cast)?;
let value = token.value()?;
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
// r##"Hello, World!"##;
// }
// ```
pub(crate) fn add_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn add_hash(ctx: AssistCtx) -> Option<Assist> {
let token = ctx.find_token_at_offset(RAW_STRING)?;
ctx.add_assist(AssistId("add_hash"), "Add # to raw string", |edit| {
edit.target(token.text_range());
@ -101,7 +100,7 @@ pub(crate) fn add_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
// r"Hello, World!";
// }
// ```
pub(crate) fn remove_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn remove_hash(ctx: AssistCtx) -> Option<Assist> {
let token = ctx.find_token_at_offset(RAW_STRING)?;
let text = token.text().as_str();
if text.starts_with("r\"") {

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_syntax::{
ast::{self, AstNode},
TextUnit, T,
@ -21,7 +20,7 @@ use crate::{Assist, AssistCtx, AssistId};
// 92;
// }
// ```
pub(crate) fn remove_dbg(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option<Assist> {
let macro_call = ctx.find_node_at_offset::<ast::MacroCall>()?;
if !is_valid_macrocall(&macro_call, "dbg")? {

View File

@ -1,4 +1,3 @@
use hir::db::HirDatabase;
use ra_fmt::unwrap_trivial_block;
use ra_syntax::{
ast::{self, make},
@ -34,7 +33,7 @@ use ast::edit::IndentLevel;
// }
// }
// ```
pub(crate) fn replace_if_let_with_match(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> {
let if_expr: ast::IfExpr = ctx.find_node_at_offset()?;
let cond = if_expr.condition()?;
let pat = cond.pat()?;

View File

@ -1,6 +1,5 @@
use std::iter::successors;
use hir::db::HirDatabase;
use ra_syntax::{ast, AstNode, TextUnit, T};
use crate::{Assist, AssistCtx, AssistId};
@ -16,7 +15,7 @@ use crate::{Assist, AssistCtx, AssistId};
// ```
// use std::{collections::HashMap};
// ```
pub(crate) fn split_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
pub(crate) fn split_import(ctx: AssistCtx) -> Option<Assist> {
let colon_colon = ctx.find_token_at_offset(T![::])?;
let path = ast::Path::cast(colon_colon.parent())?;
let top_path = successors(Some(path), |it| it.parent_path()).last()?;

View File

@ -148,7 +148,6 @@ fn sort_assists(assists: &mut Vec<ResolvedAssist>) {
mod assists {
use crate::{Assist, AssistCtx, ImportsLocator};
use hir::db::HirDatabase;
mod add_derive;
mod add_explicit_type;
@ -176,7 +175,7 @@ mod assists {
mod move_bounds;
mod early_return;
pub(crate) fn all<DB: HirDatabase>() -> &'static [fn(AssistCtx<DB>) -> Option<Assist>] {
pub(crate) fn all() -> &'static [fn(AssistCtx) -> Option<Assist>] {
&[
add_derive::add_derive,
add_explicit_type::add_explicit_type,
@ -210,8 +209,8 @@ mod assists {
]
}
pub(crate) fn all_with_imports_locator<'a, DB: HirDatabase, F: ImportsLocator>(
) -> &'a [fn(AssistCtx<DB>, &mut F) -> Option<Assist>] {
pub(crate) fn all_with_imports_locator<'a, F: ImportsLocator>(
) -> &'a [fn(AssistCtx, &mut F) -> Option<Assist>] {
&[auto_import::auto_import]
}
}
@ -274,11 +273,7 @@ mod helpers {
}
}
pub(crate) fn check_assist(
assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>,
before: &str,
after: &str,
) {
pub(crate) fn check_assist(assist: fn(AssistCtx) -> Option<Assist>, before: &str, after: &str) {
let (before_cursor_pos, before) = extract_offset(before);
let (db, file_id) = RootDatabase::with_single_file(&before);
let frange =
@ -303,7 +298,7 @@ mod helpers {
}
pub(crate) fn check_assist_with_imports_locator<F: ImportsLocator>(
assist: fn(AssistCtx<RootDatabase>, &mut F) -> Option<Assist>,
assist: fn(AssistCtx, &mut F) -> Option<Assist>,
imports_locator_provider: fn(db: Arc<RootDatabase>, file_id: FileId) -> F,
before: &str,
after: &str,
@ -335,7 +330,7 @@ mod helpers {
}
pub(crate) fn check_assist_range(
assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>,
assist: fn(AssistCtx) -> Option<Assist>,
before: &str,
after: &str,
) {
@ -357,7 +352,7 @@ mod helpers {
}
pub(crate) fn check_assist_target(
assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>,
assist: fn(AssistCtx) -> Option<Assist>,
before: &str,
target: &str,
) {
@ -377,7 +372,7 @@ mod helpers {
}
pub(crate) fn check_assist_range_target(
assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>,
assist: fn(AssistCtx) -> Option<Assist>,
before: &str,
target: &str,
) {
@ -396,7 +391,7 @@ mod helpers {
}
pub(crate) fn check_assist_not_applicable(
assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>,
assist: fn(AssistCtx) -> Option<Assist>,
before: &str,
) {
let (before_cursor_pos, before) = extract_offset(before);
@ -408,7 +403,7 @@ mod helpers {
}
pub(crate) fn check_assist_with_imports_locator_not_applicable<F: ImportsLocator>(
assist: fn(AssistCtx<RootDatabase>, &mut F) -> Option<Assist>,
assist: fn(AssistCtx, &mut F) -> Option<Assist>,
imports_locator_provider: fn(db: Arc<RootDatabase>, file_id: FileId) -> F,
before: &str,
) {
@ -424,7 +419,7 @@ mod helpers {
}
pub(crate) fn check_assist_range_not_applicable(
assist: fn(AssistCtx<RootDatabase>) -> Option<Assist>,
assist: fn(AssistCtx) -> Option<Assist>,
before: &str,
) {
let (range, before) = extract_range(before);