From cf812c12d1ac7944d1c18877ee93bea02d91e99f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 16:58:57 +0100 Subject: Assists are not generic --- crates/ra_assists/src/assist_ctx.rs | 16 ++++++------- crates/ra_assists/src/assists/add_custom_impl.rs | 4 ++-- crates/ra_assists/src/assists/add_derive.rs | 3 +-- crates/ra_assists/src/assists/add_explicit_type.rs | 4 ++-- crates/ra_assists/src/assists/add_impl.rs | 4 ++-- crates/ra_assists/src/assists/add_import.rs | 4 ++-- .../src/assists/add_missing_impl_members.rs | 6 ++--- crates/ra_assists/src/assists/add_new.rs | 9 +++----- crates/ra_assists/src/assists/apply_demorgan.rs | 3 +-- crates/ra_assists/src/assists/auto_import.rs | 4 ++-- crates/ra_assists/src/assists/change_visibility.rs | 7 +++--- crates/ra_assists/src/assists/early_return.rs | 3 +-- crates/ra_assists/src/assists/fill_match_arms.rs | 2 +- crates/ra_assists/src/assists/flip_binexpr.rs | 3 +-- crates/ra_assists/src/assists/flip_comma.rs | 3 +-- crates/ra_assists/src/assists/flip_trait_bound.rs | 3 +-- .../src/assists/inline_local_variable.rs | 3 +-- .../ra_assists/src/assists/introduce_variable.rs | 3 +-- crates/ra_assists/src/assists/invert_if.rs | 3 +-- crates/ra_assists/src/assists/merge_match_arms.rs | 3 +-- crates/ra_assists/src/assists/move_bounds.rs | 3 +-- crates/ra_assists/src/assists/move_guard.rs | 5 ++-- crates/ra_assists/src/assists/raw_string.rs | 9 ++++---- crates/ra_assists/src/assists/remove_dbg.rs | 3 +-- .../src/assists/replace_if_let_with_match.rs | 3 +-- crates/ra_assists/src/assists/split_import.rs | 3 +-- crates/ra_assists/src/lib.rs | 27 +++++++++------------- 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 @@ //! 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( db: &RootDatabase, frange: FileRange, @@ -76,7 +76,7 @@ impl<'a> AssistCtx<'a, RootDatabase> { f: F, ) -> T where - F: FnOnce(AssistCtx) -> 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( 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 @@ //! 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) -> Option { +pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { let input = ctx.find_node_at_offset::()?; let attr = input.syntax().parent().and_then(ast::Attr::cast)?; 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 @@ -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) -> Option { +pub(crate) fn add_derive(ctx: AssistCtx) -> Option { let nominal = ctx.find_node_at_offset::()?; let node_start = derive_insertion_offset(&nominal)?; 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 @@ -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) -> Option { +pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option { let stmt = ctx.find_node_at_offset::()?; let expr = stmt.initializer()?; 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 @@ 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) -> Option { +pub(crate) fn add_impl(ctx: AssistCtx) -> Option { let nominal = ctx.find_node_at_offset::()?; let name = nominal.name()?; 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 @@ -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) {} // ``` -pub(crate) fn add_import(ctx: AssistCtx) -> Option { +pub(crate) fn add_import(ctx: AssistCtx) -> Option { 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() { 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 { // // } // ``` -pub(crate) fn add_missing_impl_members(ctx: AssistCtx) -> Option { +pub(crate) fn add_missing_impl_members(ctx: AssistCtx) -> Option { add_missing_impl_members_inner( ctx, AddMissingImplMembersMode::NoDefaultMethods, @@ -84,7 +84,7 @@ pub(crate) fn add_missing_impl_members(ctx: AssistCtx) -> Opti // // } // ``` -pub(crate) fn add_missing_default_members(ctx: AssistCtx) -> Option { +pub(crate) fn add_missing_default_members(ctx: AssistCtx) -> Option { add_missing_impl_members_inner( ctx, AddMissingImplMembersMode::DefaultMethodsOnly, @@ -94,7 +94,7 @@ pub(crate) fn add_missing_default_members(ctx: AssistCtx) -> O } fn add_missing_impl_members_inner( - ctx: AssistCtx, + ctx: AssistCtx, mode: AddMissingImplMembersMode, assist_id: &'static str, 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 @@ 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) -> Option { +pub(crate) fn add_new(ctx: AssistCtx) -> Option { let strukt = ctx.find_node_at_offset::()?; // 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, - strukt: &ast::StructDef, -) -> Option> { +fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option> { let db = ctx.db; let module = strukt.syntax().ancestors().find(|node| { 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 @@ 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) -> Option { +pub(crate) fn apply_demorgan(ctx: AssistCtx) -> Option { let expr = ctx.find_node_at_offset::()?; let op = expr.op_kind()?; 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 @@ -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( - ctx: AssistCtx, + ctx: AssistCtx, imports_locator: &mut F, ) -> Option { 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 @@ -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) -> Option { +pub(crate) fn change_visibility(ctx: AssistCtx) -> Option { if let Some(vis) = ctx.find_node_at_offset::() { return change_vis(ctx, vis); } add_vis(ctx) } -fn add_vis(ctx: AssistCtx) -> Option { +fn add_vis(ctx: AssistCtx) -> Option { 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, vis: ast::Visibility) -> Option { +fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option { if vis.syntax().text() == "pub" { return ctx.add_assist( 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 @@ 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) -> Option { +pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option { let if_expr: ast::IfExpr = ctx.find_node_at_offset()?; if if_expr.else_branch().is_some() { 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}; // } // } // ``` -pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option { +pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option { let match_expr = ctx.find_node_at_offset::()?; let match_arm_list = match_expr.match_arm_list()?; 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 @@ -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) -> Option { +pub(crate) fn flip_binexpr(ctx: AssistCtx) -> Option { let expr = ctx.find_node_at_offset::()?; let lhs = expr.lhs()?.syntax().clone(); 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 @@ -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) -> Option { +pub(crate) fn flip_comma(ctx: AssistCtx) -> Option { 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)?; 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 @@ -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() { } // ``` -pub(crate) fn flip_trait_bound(ctx: AssistCtx) -> Option { +pub(crate) fn flip_trait_bound(ctx: AssistCtx) -> Option { // 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![+])?; 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 @@ -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) -> Option { +pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option { let let_stmt = ctx.find_node_at_offset::()?; let bind_pat = match let_stmt.pat()? { 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 @@ 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) -> Option { +pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option { if ctx.frange.range.is_empty() { return None; } 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 @@ -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) -> Option { +pub(crate) fn invert_if(ctx: AssistCtx) -> Option { 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(); 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 @@ 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) -> Option { +pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option { let current_arm = ctx.find_node_at_offset::()?; // Don't try to handle arms with guards for now - can add support for this later 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 @@ -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) -> Option { +pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option { let type_param_list = ctx.find_node_at_offset::()?; 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 @@ -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) -> Option { +pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option { let match_arm = ctx.find_node_at_offset::()?; 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) -> Option // } // } // ``` -pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option { +pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option { let match_arm: MatchArm = ctx.find_node_at_offset::()?; let last_match_pat = match_arm.pats().last()?; 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 @@ -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) -> Option { +pub(crate) fn make_raw_string(ctx: AssistCtx) -> Option { 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) -> Option) -> Option { +pub(crate) fn make_usual_string(ctx: AssistCtx) -> Option { 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) -> Option) -> Option { +pub(crate) fn add_hash(ctx: AssistCtx) -> Option { 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) -> Option { // r"Hello, World!"; // } // ``` -pub(crate) fn remove_hash(ctx: AssistCtx) -> Option { +pub(crate) fn remove_hash(ctx: AssistCtx) -> Option { let token = ctx.find_token_at_offset(RAW_STRING)?; let text = token.text().as_str(); 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 @@ -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) -> Option { +pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option { let macro_call = ctx.find_node_at_offset::()?; if !is_valid_macrocall(¯o_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 @@ -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) -> Option { +pub(crate) fn replace_if_let_with_match(ctx: AssistCtx) -> Option { let if_expr: ast::IfExpr = ctx.find_node_at_offset()?; let cond = if_expr.condition()?; 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 @@ 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) -> Option { +pub(crate) fn split_import(ctx: AssistCtx) -> Option { 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()?; 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) { 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() -> &'static [fn(AssistCtx) -> Option] { + pub(crate) fn all() -> &'static [fn(AssistCtx) -> Option] { &[ 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, &mut F) -> Option] { + pub(crate) fn all_with_imports_locator<'a, F: ImportsLocator>( + ) -> &'a [fn(AssistCtx, &mut F) -> Option] { &[auto_import::auto_import] } } @@ -274,11 +273,7 @@ mod helpers { } } - pub(crate) fn check_assist( - assist: fn(AssistCtx) -> Option, - before: &str, - after: &str, - ) { + pub(crate) fn check_assist(assist: fn(AssistCtx) -> Option, 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( - assist: fn(AssistCtx, &mut F) -> Option, + assist: fn(AssistCtx, &mut F) -> Option, imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, before: &str, after: &str, @@ -335,7 +330,7 @@ mod helpers { } pub(crate) fn check_assist_range( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, after: &str, ) { @@ -357,7 +352,7 @@ mod helpers { } pub(crate) fn check_assist_target( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, target: &str, ) { @@ -377,7 +372,7 @@ mod helpers { } pub(crate) fn check_assist_range_target( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, target: &str, ) { @@ -396,7 +391,7 @@ mod helpers { } pub(crate) fn check_assist_not_applicable( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, 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( - assist: fn(AssistCtx, &mut F) -> Option, + assist: fn(AssistCtx, &mut F) -> Option, imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, before: &str, ) { @@ -424,7 +419,7 @@ mod helpers { } pub(crate) fn check_assist_range_not_applicable( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, ) { let (range, before) = extract_range(before); -- cgit v1.2.3