Speed up resolving "Generate delegate method" assist (part 2)

Make it compile by adding a `None` subtype to rest of the AssistId
instantiations.
This commit is contained in:
Felicián Németh 2025-03-15 08:42:30 +01:00
parent 7aa70a86d1
commit f2ad0fcb21
133 changed files with 530 additions and 568 deletions

View File

@ -3,7 +3,7 @@ use syntax::{
ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory}, ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: add_braces // Assist: add_braces
// //
@ -32,7 +32,7 @@ pub(crate) fn add_braces(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
let (expr_type, expr) = get_replacement_node(ctx)?; let (expr_type, expr) = get_replacement_node(ctx)?;
acc.add( acc.add(
AssistId("add_braces", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("add_braces"),
match expr_type { match expr_type {
ParentType::ClosureExpr => "Add braces to closure body", ParentType::ClosureExpr => "Add braces to closure body",
ParentType::MatchArmExpr => "Add braces to arm expression", ParentType::MatchArmExpr => "Add braces to arm expression",

View File

@ -1,9 +1,5 @@
use hir::Semantics; use hir::Semantics;
use ide_db::{ use ide_db::{RootDatabase, assists::AssistId, source_change::SourceChangeBuilder};
RootDatabase,
assists::{AssistId, AssistKind},
source_change::SourceChangeBuilder,
};
use syntax::{AstNode, ast}; use syntax::{AstNode, ast};
use crate::{AssistContext, Assists}; use crate::{AssistContext, Assists};
@ -53,7 +49,7 @@ pub(crate) fn add_explicit_enum_discriminant(
} }
acc.add( acc.add(
AssistId("add_explicit_enum_discriminant", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("add_explicit_enum_discriminant"),
"Add explicit enum discriminants", "Add explicit enum discriminants",
enum_node.syntax().text_range(), enum_node.syntax().text_range(),
|builder| { |builder| {

View File

@ -2,7 +2,7 @@ use hir::HirDisplay;
use ide_db::syntax_helpers::node_ext::walk_ty; use ide_db::syntax_helpers::node_ext::walk_ty;
use syntax::ast::{self, AstNode, LetStmt, Param}; use syntax::ast::{self, AstNode, LetStmt, Param};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: add_explicit_type // Assist: add_explicit_type
// //
@ -71,7 +71,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
let inferred_type = ty.display_source_code(ctx.db(), module.into(), false).ok()?; let inferred_type = ty.display_source_code(ctx.db(), module.into(), false).ok()?;
acc.add( acc.add(
AssistId("add_explicit_type", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("add_explicit_type"),
format!("Insert explicit type `{inferred_type}`"), format!("Insert explicit type `{inferred_type}`"),
pat_range, pat_range,
|builder| match ascribed_ty { |builder| match ascribed_ty {

View File

@ -4,7 +4,7 @@ use syntax::{
ast::{self, AstNode, HasLoopBody}, ast::{self, AstNode, HasLoopBody},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: add_label_to_loop // Assist: add_label_to_loop
// //
@ -35,7 +35,7 @@ pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
} }
acc.add( acc.add(
AssistId("add_label_to_loop", AssistKind::Generate), AssistId::generate("add_label_to_loop"),
"Add Label", "Add Label",
loop_expr.syntax().text_range(), loop_expr.syntax().text_range(),
|builder| { |builder| {

View File

@ -1,6 +1,6 @@
use syntax::ast::{self, AstNode, HasGenericParams, HasName}; use syntax::ast::{self, AstNode, HasGenericParams, HasName};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: add_lifetime_to_type // Assist: add_lifetime_to_type
// //
@ -37,31 +37,26 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext<'_>) -
let ref_types = fetch_borrowed_types(&node)?; let ref_types = fetch_borrowed_types(&node)?;
let target = node.syntax().text_range(); let target = node.syntax().text_range();
acc.add( acc.add(AssistId::generate("add_lifetime_to_type"), "Add lifetime", target, |builder| {
AssistId("add_lifetime_to_type", AssistKind::Generate), match node.generic_param_list() {
"Add lifetime", Some(gen_param) => {
target, if let Some(left_angle) = gen_param.l_angle_token() {
|builder| { builder.insert(left_angle.text_range().end(), "'a, ");
match node.generic_param_list() {
Some(gen_param) => {
if let Some(left_angle) = gen_param.l_angle_token() {
builder.insert(left_angle.text_range().end(), "'a, ");
}
}
None => {
if let Some(name) = node.name() {
builder.insert(name.syntax().text_range().end(), "<'a>");
}
} }
} }
None => {
if let Some(name) = node.name() {
builder.insert(name.syntax().text_range().end(), "<'a>");
}
}
}
for ref_type in ref_types { for ref_type in ref_types {
if let Some(amp_token) = ref_type.amp_token() { if let Some(amp_token) = ref_type.amp_token() {
builder.insert(amp_token.text_range().end(), "'a "); builder.insert(amp_token.text_range().end(), "'a ");
}
} }
}, }
) })
} }
fn fetch_borrowed_types(node: &ast::Adt) -> Option<Vec<ast::RefType>> { fn fetch_borrowed_types(node: &ast::Adt) -> Option<Vec<ast::RefType>> {

View File

@ -5,7 +5,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
utils::{ utils::{
DefaultMethods, IgnoreAssocItems, add_trait_assoc_items_to_impl, filter_assoc_items, DefaultMethods, IgnoreAssocItems, add_trait_assoc_items_to_impl, filter_assoc_items,
@ -146,7 +146,7 @@ fn add_missing_impl_members_inner(
} }
let target = impl_def.syntax().text_range(); let target = impl_def.syntax().text_range();
acc.add(AssistId(assist_id, AssistKind::QuickFix), label, target, |edit| { acc.add(AssistId::quick_fix(assist_id), label, target, |edit| {
let new_impl_def = edit.make_mut(impl_def.clone()); let new_impl_def = edit.make_mut(impl_def.clone());
let first_new_item = add_trait_assoc_items_to_impl( let first_new_item = add_trait_assoc_items_to_impl(
&ctx.sema, &ctx.sema,

View File

@ -12,7 +12,7 @@ use syntax::ast::edit_in_place::Indent;
use syntax::ast::syntax_factory::SyntaxFactory; use syntax::ast::syntax_factory::SyntaxFactory;
use syntax::ast::{self, AstNode, MatchArmList, MatchExpr, Pat, make}; use syntax::ast::{self, AstNode, MatchArmList, MatchExpr, Pat, make};
use crate::{AssistContext, AssistId, AssistKind, Assists, utils}; use crate::{AssistContext, AssistId, Assists, utils};
// Assist: add_missing_match_arms // Assist: add_missing_match_arms
// //
@ -205,7 +205,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
} }
acc.add( acc.add(
AssistId("add_missing_match_arms", AssistKind::QuickFix), AssistId::quick_fix("add_missing_match_arms"),
"Fill match arms", "Fill match arms",
ctx.sema.original_range(match_expr.syntax()).range, ctx.sema.original_range(match_expr.syntax()).range,
|builder| { |builder| {

View File

@ -1,7 +1,7 @@
use hir::HirDisplay; use hir::HirDisplay;
use syntax::{AstNode, SyntaxKind, SyntaxToken, TextRange, TextSize, ast, match_ast}; use syntax::{AstNode, SyntaxKind, SyntaxToken, TextRange, TextSize, ast, match_ast};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: add_return_type // Assist: add_return_type
// //
@ -25,7 +25,7 @@ pub(crate) fn add_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
let ty = ty.display_source_code(ctx.db(), module.into(), true).ok()?; let ty = ty.display_source_code(ctx.db(), module.into(), true).ok()?;
acc.add( acc.add(
AssistId("add_return_type", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("add_return_type"),
match fn_type { match fn_type {
FnType::Function => "Add this function's return type", FnType::Function => "Add this function's return type",
FnType::Closure { .. } => "Add this closure's return type", FnType::Closure { .. } => "Add this closure's return type",

View File

@ -7,7 +7,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -89,7 +89,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
let_stmt.pat()?; let_stmt.pat()?;
acc.add( acc.add(
AssistId("add_type_ascription", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("add_type_ascription"),
"Add `: _` before assignment operator", "Add `: _` before assignment operator",
ident.text_range(), ident.text_range(),
|builder| { |builder| {
@ -135,7 +135,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
.count(); .count();
acc.add( acc.add(
AssistId("add_turbo_fish", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("add_turbo_fish"),
"Add `::<>`", "Add `::<>`",
ident.text_range(), ident.text_range(),
|builder| { |builder| {

View File

@ -17,7 +17,7 @@ use syntax::{
syntax_editor::{Position, SyntaxEditor}, syntax_editor::{Position, SyntaxEditor},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, utils::invert_boolean_expression}; use crate::{AssistContext, AssistId, Assists, utils::invert_boolean_expression};
// Assist: apply_demorgan // Assist: apply_demorgan
// //
@ -107,7 +107,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
acc.add_group( acc.add_group(
&GroupLabel("Apply De Morgan's law".to_owned()), &GroupLabel("Apply De Morgan's law".to_owned()),
AssistId("apply_demorgan", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("apply_demorgan"),
"Apply De Morgan's law", "Apply De Morgan's law",
op_range, op_range,
|builder| { |builder| {
@ -190,7 +190,7 @@ pub(crate) fn apply_demorgan_iterator(acc: &mut Assists, ctx: &AssistContext<'_>
let label = format!("Apply De Morgan's law to `Iterator::{}`", name.text().as_str()); let label = format!("Apply De Morgan's law to `Iterator::{}`", name.text().as_str());
acc.add_group( acc.add_group(
&GroupLabel("Apply De Morgan's law".to_owned()), &GroupLabel("Apply De Morgan's law".to_owned()),
AssistId("apply_demorgan_iterator", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("apply_demorgan_iterator"),
label, label,
op_range, op_range,
|builder| { |builder| {

View File

@ -10,7 +10,7 @@ use ide_db::{
}; };
use syntax::{AstNode, Edition, NodeOrToken, SyntaxElement, ast}; use syntax::{AstNode, Edition, NodeOrToken, SyntaxElement, ast};
use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; use crate::{AssistContext, AssistId, Assists, GroupLabel};
// Feature: Auto Import // Feature: Auto Import
// //
@ -127,7 +127,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
let import_path = import.import_path; let import_path = import.import_path;
let (assist_id, import_name) = let (assist_id, import_name) =
(AssistId("auto_import", AssistKind::QuickFix), import_path.display(ctx.db(), edition)); (AssistId::quick_fix("auto_import"), import_path.display(ctx.db(), edition));
acc.add_group( acc.add_group(
&group_label, &group_label,
assist_id, assist_id,

View File

@ -1,9 +1,5 @@
use crate::assist_context::{AssistContext, Assists}; use crate::assist_context::{AssistContext, Assists};
use ide_db::{ use ide_db::{LineIndexDatabase, assists::AssistId, defs::Definition};
LineIndexDatabase,
assists::{AssistId, AssistKind},
defs::Definition,
};
use syntax::{ use syntax::{
AstNode, AstNode,
ast::{self, edit_in_place::Indent}, ast::{self, edit_in_place::Indent},
@ -42,7 +38,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
let r_curly_range = stmt_list.r_curly_token()?.text_range(); let r_curly_range = stmt_list.r_curly_token()?.text_range();
acc.add( acc.add(
AssistId("bind_unused_param", AssistKind::QuickFix), AssistId::quick_fix("bind_unused_param"),
format!("Bind as `let _ = {ident_pat};`"), format!("Bind as `let _ = {ident_pat};`"),
param.syntax().text_range(), param.syntax().text_range(),
|builder| { |builder| {

View File

@ -8,7 +8,7 @@ use syntax::{
ast::{self, HasName, HasVisibility}, ast::{self, HasName, HasVisibility},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, utils::vis_offset}; use crate::{AssistContext, AssistId, Assists, utils::vis_offset};
// Assist: change_visibility // Assist: change_visibility
// //
@ -76,7 +76,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
}; };
acc.add( acc.add(
AssistId("change_visibility", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("change_visibility"),
"Change visibility to pub(crate)", "Change visibility to pub(crate)",
target, target,
|edit| { |edit| {
@ -112,7 +112,7 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
if vis.syntax().text() == "pub" { if vis.syntax().text() == "pub" {
let target = vis.syntax().text_range(); let target = vis.syntax().text_range();
return acc.add( return acc.add(
AssistId("change_visibility", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("change_visibility"),
"Change Visibility to pub(crate)", "Change Visibility to pub(crate)",
target, target,
|edit| { |edit| {
@ -123,7 +123,7 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
if vis.syntax().text() == "pub(crate)" { if vis.syntax().text() == "pub(crate)" {
let target = vis.syntax().text_range(); let target = vis.syntax().text_range();
return acc.add( return acc.add(
AssistId("change_visibility", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("change_visibility"),
"Change visibility to pub", "Change visibility to pub",
target, target,
|edit| { |edit| {

View File

@ -14,7 +14,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistContext, AssistId, AssistKind, Assists, AssistContext, AssistId, Assists,
utils::{invert_boolean_expression, unwrap_trivial_block}, utils::{invert_boolean_expression, unwrap_trivial_block},
}; };
@ -73,7 +73,7 @@ pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext<'_>
let target = expr.syntax().text_range(); let target = expr.syntax().text_range();
acc.add( acc.add(
AssistId("convert_if_to_bool_then", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_if_to_bool_then"),
"Convert `if` expression to `bool::then` call", "Convert `if` expression to `bool::then` call",
target, target,
|builder| { |builder| {
@ -181,7 +181,7 @@ pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext<'_>
let target = mcall.syntax().text_range(); let target = mcall.syntax().text_range();
acc.add( acc.add(
AssistId("convert_bool_then_to_if", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_bool_then_to_if"),
"Convert `bool::then` call to `if`", "Convert `bool::then` call to `if`",
target, target,
|builder| { |builder| {

View File

@ -3,7 +3,7 @@ use hir::ModuleDef;
use ide_db::text_edit::TextRange; use ide_db::text_edit::TextRange;
use ide_db::{ use ide_db::{
FxHashSet, FxHashSet,
assists::{AssistId, AssistKind}, assists::AssistId,
defs::Definition, defs::Definition,
helpers::mod_path_to_ast, helpers::mod_path_to_ast,
imports::insert_use::{ImportScope, insert_use}, imports::insert_use::{ImportScope, insert_use},
@ -62,7 +62,7 @@ pub(crate) fn convert_bool_to_enum(acc: &mut Assists, ctx: &AssistContext<'_>) -
let target = name.syntax().text_range(); let target = name.syntax().text_range();
acc.add( acc.add(
AssistId("convert_bool_to_enum", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_bool_to_enum"),
"Convert boolean to enum", "Convert boolean to enum",
target, target,
|edit| { |edit| {

View File

@ -1,12 +1,8 @@
use either::Either; use either::Either;
use hir::{CaptureKind, ClosureCapture, FileRangeWrapper, HirDisplay}; use hir::{CaptureKind, ClosureCapture, FileRangeWrapper, HirDisplay};
use ide_db::{ use ide_db::{
FxHashSet, FxHashSet, assists::AssistId, base_db::SourceDatabase, defs::Definition,
assists::{AssistId, AssistKind}, search::FileReferenceNode, source_change::SourceChangeBuilder,
base_db::SourceDatabase,
defs::Definition,
search::FileReferenceNode,
source_change::SourceChangeBuilder,
}; };
use stdx::format_to; use stdx::format_to;
use syntax::{ use syntax::{
@ -147,7 +143,7 @@ pub(crate) fn convert_closure_to_fn(acc: &mut Assists, ctx: &AssistContext<'_>)
}; };
acc.add( acc.add(
AssistId("convert_closure_to_fn", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_closure_to_fn"),
"Convert closure to fn", "Convert closure to fn",
closure.param_list()?.syntax().text_range(), closure.param_list()?.syntax().text_range(),
|builder| { |builder| {

View File

@ -4,7 +4,7 @@ use syntax::{
ast::{self, Comment, CommentKind, CommentShape, Whitespace, edit::IndentLevel}, ast::{self, Comment, CommentKind, CommentShape, Whitespace, edit::IndentLevel},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: line_to_block // Assist: line_to_block
// //
@ -38,7 +38,7 @@ fn block_to_line(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
let target = comment.syntax().text_range(); let target = comment.syntax().text_range();
acc.add( acc.add(
AssistId("block_to_line", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("block_to_line"),
"Replace block comment with line comments", "Replace block comment with line comments",
target, target,
|edit| { |edit| {
@ -80,7 +80,7 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
); );
acc.add( acc.add(
AssistId("line_to_block", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("line_to_block"),
"Replace line comments with a single block comment", "Replace line comments with a single block comment",
target, target,
|edit| { |edit| {

View File

@ -4,7 +4,7 @@ use syntax::{
ast::{self, Comment, CommentPlacement, Whitespace, edit::IndentLevel}, ast::{self, Comment, CommentPlacement, Whitespace, edit::IndentLevel},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: comment_to_doc // Assist: comment_to_doc
// //
@ -39,7 +39,7 @@ fn doc_to_comment(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
}; };
acc.add( acc.add(
AssistId("doc_to_comment", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("doc_to_comment"),
"Replace doc comment with comment", "Replace doc comment with comment",
target, target,
|edit| { |edit| {
@ -86,7 +86,7 @@ fn comment_to_doc(acc: &mut Assists, comment: ast::Comment, style: CommentPlacem
}; };
acc.add( acc.add(
AssistId("comment_to_doc", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("comment_to_doc"),
"Replace comment with doc comment", "Replace comment with doc comment",
target, target,
|edit| { |edit| {

View File

@ -9,7 +9,7 @@ use syntax::{
syntax_editor::Position, syntax_editor::Position,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: convert_for_loop_to_while_let // Assist: convert_for_loop_to_while_let
// //
@ -47,7 +47,7 @@ pub(crate) fn convert_for_loop_to_while_let(
} }
acc.add( acc.add(
AssistId("convert_for_loop_to_while_let", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_for_loop_to_while_let"),
"Replace this for loop with `while let`", "Replace this for loop with `while let`",
for_loop.syntax().text_range(), for_loop.syntax().text_range(),
|builder| { |builder| {

View File

@ -5,7 +5,7 @@ use syntax::{
ted, ted,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: convert_from_to_tryfrom // Assist: convert_from_to_tryfrom
// //
@ -71,7 +71,7 @@ pub(crate) fn convert_from_to_tryfrom(acc: &mut Assists, ctx: &AssistContext<'_>
} }
acc.add( acc.add(
AssistId("convert_from_to_tryfrom", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_from_to_tryfrom"),
"Convert From to TryFrom", "Convert From to TryFrom",
impl_.syntax().text_range(), impl_.syntax().text_range(),
|builder| { |builder| {

View File

@ -1,6 +1,6 @@
use syntax::{AstToken, ast, ast::Radix}; use syntax::{AstToken, ast, ast::Radix};
use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; use crate::{AssistContext, AssistId, Assists, GroupLabel};
// Assist: convert_integer_literal // Assist: convert_integer_literal
// //
@ -47,7 +47,7 @@ pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext<'_>
acc.add_group( acc.add_group(
&group_id, &group_id,
AssistId("convert_integer_literal", AssistKind::RefactorInline), AssistId::refactor_rewrite("convert_integer_literal"),
label, label,
range, range,
|builder| builder.replace(range, converted), |builder| builder.replace(range, converted),

View File

@ -1,7 +1,7 @@
use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast, traits::resolve_target_trait}; use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast, traits::resolve_target_trait};
use syntax::ast::{self, AstNode, HasGenericArgs, HasName}; use syntax::ast::{self, AstNode, HasGenericArgs, HasName};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// FIXME: this should be a diagnostic // FIXME: this should be a diagnostic
@ -85,7 +85,7 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -
.filter(|name| name.text() == "self" || name.text() == "Self"); .filter(|name| name.text() == "self" || name.text() == "Self");
acc.add( acc.add(
AssistId("convert_into_to_from", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_into_to_from"),
"Convert Into to From", "Convert Into to From",
impl_.syntax().text_range(), impl_.syntax().text_range(),
|builder| { |builder| {

View File

@ -6,7 +6,7 @@ use syntax::{
ast::{self, HasArgList, HasLoopBody, edit_in_place::Indent, make}, ast::{self, HasArgList, HasLoopBody, edit_in_place::Indent, make},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: convert_iter_for_each_to_for // Assist: convert_iter_for_each_to_for
// //
@ -53,7 +53,7 @@ pub(crate) fn convert_iter_for_each_to_for(
let range = stmt.as_ref().map_or(method.syntax(), AstNode::syntax).text_range(); let range = stmt.as_ref().map_or(method.syntax(), AstNode::syntax).text_range();
acc.add( acc.add(
AssistId("convert_iter_for_each_to_for", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_iter_for_each_to_for"),
"Replace this `Iterator::for_each` with a for loop", "Replace this `Iterator::for_each` with a for loop",
range, range,
|builder| { |builder| {
@ -108,7 +108,7 @@ pub(crate) fn convert_for_loop_with_for_each(
} }
acc.add( acc.add(
AssistId("convert_for_loop_with_for_each", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_for_loop_with_for_each"),
"Replace this for loop with `Iterator::for_each`", "Replace this for loop with `Iterator::for_each`",
for_loop.syntax().text_range(), for_loop.syntax().text_range(),
|builder| { |builder| {

View File

@ -4,7 +4,7 @@ use syntax::T;
use syntax::ast::RangeItem; use syntax::ast::RangeItem;
use syntax::ast::{AstNode, HasName, LetStmt, Name, Pat, edit::AstNodeEdit}; use syntax::ast::{AstNode, HasName, LetStmt, Name, Pat, edit::AstNodeEdit};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: convert_let_else_to_match // Assist: convert_let_else_to_match
// //
@ -43,7 +43,7 @@ pub(crate) fn convert_let_else_to_match(acc: &mut Assists, ctx: &AssistContext<'
let target = let_stmt.syntax().text_range(); let target = let_stmt.syntax().text_range();
acc.add( acc.add(
AssistId("convert_let_else_to_match", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_let_else_to_match"),
"Convert let-else to let and match", "Convert let-else to let and match",
target, target,
|edit| { |edit| {

View File

@ -6,7 +6,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -55,7 +55,7 @@ pub(crate) fn convert_match_to_let_else(acc: &mut Assists, ctx: &AssistContext<'
let extracted_variable_positions = find_extracted_variable(ctx, &extracting_arm)?; let extracted_variable_positions = find_extracted_variable(ctx, &extracting_arm)?;
acc.add( acc.add(
AssistId("convert_match_to_let_else", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_match_to_let_else"),
"Convert match to let-else", "Convert match to let-else",
let_stmt.syntax().text_range(), let_stmt.syntax().text_range(),
|builder| { |builder| {

View File

@ -7,7 +7,7 @@ use syntax::{
match_ast, ted, match_ast, ted,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder}; use crate::{AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder};
// Assist: convert_named_struct_to_tuple_struct // Assist: convert_named_struct_to_tuple_struct
// //
@ -69,7 +69,7 @@ pub(crate) fn convert_named_struct_to_tuple_struct(
}; };
acc.add( acc.add(
AssistId("convert_named_struct_to_tuple_struct", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_named_struct_to_tuple_struct"),
"Convert to tuple struct", "Convert to tuple struct",
strukt.syntax().text_range(), strukt.syntax().text_range(),
|edit| { |edit| {

View File

@ -1,4 +1,4 @@
use ide_db::assists::{AssistId, AssistKind}; use ide_db::assists::AssistId;
use syntax::ast::{self, HasGenericParams, HasName}; use syntax::ast::{self, HasGenericParams, HasName};
use syntax::{AstNode, SyntaxKind}; use syntax::{AstNode, SyntaxKind};
@ -44,7 +44,7 @@ pub(crate) fn convert_nested_function_to_closure(
let param_list = function.param_list()?; let param_list = function.param_list()?;
acc.add( acc.add(
AssistId("convert_nested_function_to_closure", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_nested_function_to_closure"),
"Convert nested function to closure", "Convert nested function to closure",
target, target,
|edit| { |edit| {

View File

@ -17,7 +17,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
utils::invert_boolean_expression_legacy, utils::invert_boolean_expression_legacy,
}; };
@ -128,7 +128,7 @@ fn if_expr_to_guarded_return(
let target = if_expr.syntax().text_range(); let target = if_expr.syntax().text_range();
acc.add( acc.add(
AssistId("convert_to_guarded_return", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_to_guarded_return"),
"Convert to guarded return", "Convert to guarded return",
target, target,
|edit| { |edit| {
@ -210,7 +210,7 @@ fn let_stmt_to_guarded_return(
}; };
acc.add( acc.add(
AssistId("convert_to_guarded_return", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_to_guarded_return"),
"Convert to guarded return", "Convert to guarded return",
target, target,
|edit| { |edit| {

View File

@ -2,7 +2,7 @@ use either::Either;
use hir::ModuleDef; use hir::ModuleDef;
use ide_db::{ use ide_db::{
FxHashSet, FxHashSet,
assists::{AssistId, AssistKind}, assists::AssistId,
defs::Definition, defs::Definition,
helpers::mod_path_to_ast, helpers::mod_path_to_ast,
imports::insert_use::{ImportScope, insert_use}, imports::insert_use::{ImportScope, insert_use},
@ -63,7 +63,7 @@ pub(crate) fn convert_tuple_return_type_to_struct(
let target = type_ref.syntax().text_range(); let target = type_ref.syntax().text_range();
acc.add( acc.add(
AssistId("convert_tuple_return_type_to_struct", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_tuple_return_type_to_struct"),
"Convert tuple return type to tuple struct", "Convert tuple return type to tuple struct",
target, target,
move |edit| { move |edit| {

View File

@ -6,7 +6,7 @@ use syntax::{
match_ast, ted, match_ast, ted,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder}; use crate::{AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder};
// Assist: convert_tuple_struct_to_named_struct // Assist: convert_tuple_struct_to_named_struct
// //
@ -65,7 +65,7 @@ pub(crate) fn convert_tuple_struct_to_named_struct(
let target = strukt.as_ref().either(|s| s.syntax(), |v| v.syntax()).text_range(); let target = strukt.as_ref().either(|s| s.syntax(), |v| v.syntax()).text_range();
acc.add( acc.add(
AssistId("convert_tuple_struct_to_named_struct", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_tuple_struct_to_named_struct"),
"Convert to named struct", "Convert to named struct",
target, target,
|edit| { |edit| {

View File

@ -3,7 +3,7 @@ use ide_db::RootDatabase;
use stdx::format_to; use stdx::format_to;
use syntax::ast::{self, AstNode}; use syntax::ast::{self, AstNode};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: convert_two_arm_bool_match_to_matches_macro // Assist: convert_two_arm_bool_match_to_matches_macro
// //
@ -56,7 +56,7 @@ pub(crate) fn convert_two_arm_bool_match_to_matches_macro(
let expr = match_expr.expr()?; let expr = match_expr.expr()?;
acc.add( acc.add(
AssistId("convert_two_arm_bool_match_to_matches_macro", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_two_arm_bool_match_to_matches_macro"),
"Convert to matches!", "Convert to matches!",
target_range, target_range,
|builder| { |builder| {

View File

@ -12,7 +12,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
utils::invert_boolean_expression_legacy, utils::invert_boolean_expression_legacy,
}; };
@ -47,7 +47,7 @@ pub(crate) fn convert_while_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>)
let target = while_expr.syntax().text_range(); let target = while_expr.syntax().text_range();
acc.add( acc.add(
AssistId("convert_while_to_loop", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("convert_while_to_loop"),
"Convert while to loop", "Convert while to loop",
target, target,
|edit| { |edit| {

View File

@ -2,7 +2,7 @@ use hir::{HasVisibility, sym};
use ide_db::text_edit::TextRange; use ide_db::text_edit::TextRange;
use ide_db::{ use ide_db::{
FxHashMap, FxHashSet, FxHashMap, FxHashSet,
assists::{AssistId, AssistKind}, assists::AssistId,
defs::Definition, defs::Definition,
helpers::mod_path_to_ast, helpers::mod_path_to_ast,
search::{FileReference, SearchScope}, search::{FileReference, SearchScope},
@ -47,7 +47,7 @@ pub(crate) fn destructure_struct_binding(acc: &mut Assists, ctx: &AssistContext<
let data = collect_data(ident_pat, ctx)?; let data = collect_data(ident_pat, ctx)?;
acc.add( acc.add(
AssistId("destructure_struct_binding", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("destructure_struct_binding"),
"Destructure struct binding", "Destructure struct binding",
data.ident_pat.syntax().text_range(), data.ident_pat.syntax().text_range(),
|edit| destructure_struct_binding_impl(ctx, edit, &data), |edit| destructure_struct_binding_impl(ctx, edit, &data),

View File

@ -1,5 +1,5 @@
use ide_db::{ use ide_db::{
assists::{AssistId, AssistKind}, assists::AssistId,
defs::Definition, defs::Definition,
search::{FileReference, SearchScope}, search::{FileReference, SearchScope},
syntax_helpers::suggest_name, syntax_helpers::suggest_name,
@ -65,7 +65,7 @@ pub(crate) fn destructure_tuple_binding_impl(
if with_sub_pattern { if with_sub_pattern {
acc.add( acc.add(
AssistId("destructure_tuple_binding_in_sub_pattern", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("destructure_tuple_binding_in_sub_pattern"),
"Destructure tuple in sub-pattern", "Destructure tuple in sub-pattern",
data.ident_pat.syntax().text_range(), data.ident_pat.syntax().text_range(),
|edit| destructure_tuple_edit_impl(ctx, edit, &data, true), |edit| destructure_tuple_edit_impl(ctx, edit, &data, true),
@ -73,7 +73,7 @@ pub(crate) fn destructure_tuple_binding_impl(
} }
acc.add( acc.add(
AssistId("destructure_tuple_binding", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("destructure_tuple_binding"),
if with_sub_pattern { "Destructure tuple in place" } else { "Destructure tuple" }, if with_sub_pattern { "Destructure tuple in place" } else { "Destructure tuple" },
data.ident_pat.syntax().text_range(), data.ident_pat.syntax().text_range(),
|edit| destructure_tuple_edit_impl(ctx, edit, &data, false), |edit| destructure_tuple_edit_impl(ctx, edit, &data, false),

View File

@ -6,7 +6,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistContext, AssistId, AssistKind, Assists, AssistContext, AssistId, Assists,
handlers::convert_comment_block::{line_comment_text, relevant_line_comments}, handlers::convert_comment_block::{line_comment_text, relevant_line_comments},
utils::required_hashes, utils::required_hashes,
}; };
@ -54,7 +54,7 @@ pub(crate) fn desugar_doc_comment(acc: &mut Assists, ctx: &AssistContext<'_>) ->
}; };
acc.add( acc.add(
AssistId("desugar_doc_comment", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("desugar_doc_comment"),
"Desugar doc-comment to attribute macro", "Desugar doc-comment to attribute macro",
target, target,
|edit| { |edit| {

View File

@ -13,7 +13,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -62,7 +62,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let target = parent.either(|n| n.syntax().clone(), |n| n.syntax().clone()); let target = parent.either(|n| n.syntax().clone(), |n| n.syntax().clone());
acc.add( acc.add(
AssistId("expand_glob_import", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("expand_glob_import"),
"Expand glob import", "Expand glob import",
target.text_range(), target.text_range(),
|builder| { |builder| {
@ -123,7 +123,7 @@ pub(crate) fn expand_glob_reexport(acc: &mut Assists, ctx: &AssistContext<'_>) -
let target = parent.either(|n| n.syntax().clone(), |n| n.syntax().clone()); let target = parent.either(|n| n.syntax().clone(), |n| n.syntax().clone());
acc.add( acc.add(
AssistId("expand_glob_reexport", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("expand_glob_reexport"),
"Expand glob reexport", "Expand glob reexport",
target.text_range(), target.text_range(),
|builder| { |builder| {

View File

@ -74,7 +74,7 @@ fn expand_record_rest_pattern(
let target_range = rest_pat.syntax().text_range(); let target_range = rest_pat.syntax().text_range();
acc.add( acc.add(
AssistId("expand_record_rest_pattern", crate::AssistKind::RefactorRewrite), AssistId::refactor_rewrite("expand_record_rest_pattern"),
"Fill struct fields", "Fill struct fields",
target_range, target_range,
move |builder| builder.replace_ast(old_field_list, new_field_list), move |builder| builder.replace_ast(old_field_list, new_field_list),
@ -155,7 +155,7 @@ fn expand_tuple_struct_rest_pattern(
let target_range = rest_pat.syntax().text_range(); let target_range = rest_pat.syntax().text_range();
acc.add( acc.add(
AssistId("expand_tuple_struct_rest_pattern", crate::AssistKind::RefactorRewrite), AssistId::refactor_rewrite("expand_tuple_struct_rest_pattern"),
"Fill tuple struct fields", "Fill tuple struct fields",
target_range, target_range,
move |builder| builder.replace_ast(pat, new_pat), move |builder| builder.replace_ast(pat, new_pat),

View File

@ -53,6 +53,7 @@ pub(crate) fn extract_expressions_from_format_string(
} else { } else {
AssistKind::QuickFix AssistKind::QuickFix
}, },
None,
), ),
"Extract format expressions", "Extract format expressions",
tt.syntax().text_range(), tt.syntax().text_range(),

View File

@ -108,7 +108,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
acc.add_group( acc.add_group(
&GroupLabel("Extract into...".to_owned()), &GroupLabel("Extract into...".to_owned()),
AssistId("extract_function", crate::AssistKind::RefactorExtract), AssistId::refactor_extract("extract_function"),
"Extract into function", "Extract into function",
target_range, target_range,
move |builder| { move |builder| {

View File

@ -5,7 +5,7 @@ use hir::{HasSource, HirFileIdExt, ModuleSource};
use ide_db::base_db::salsa::AsDynDatabase; use ide_db::base_db::salsa::AsDynDatabase;
use ide_db::{ use ide_db::{
FileId, FxHashMap, FxHashSet, FileId, FxHashMap, FxHashSet,
assists::{AssistId, AssistKind}, assists::AssistId,
defs::{Definition, NameClass, NameRefClass}, defs::{Definition, NameClass, NameRefClass},
search::{FileReference, SearchScope}, search::{FileReference, SearchScope},
}; };
@ -92,7 +92,7 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
let old_item_indent = module.body_items[0].indent_level(); let old_item_indent = module.body_items[0].indent_level();
acc.add( acc.add(
AssistId("extract_module", AssistKind::RefactorExtract), AssistId::refactor_extract("extract_module"),
"Extract Module", "Extract Module",
module.text_range, module.text_range,
|builder| { |builder| {

View File

@ -22,7 +22,7 @@ use syntax::{
match_ast, ted, match_ast, ted,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder}; use crate::{AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder};
// Assist: extract_struct_from_enum_variant // Assist: extract_struct_from_enum_variant
// //
@ -55,7 +55,7 @@ pub(crate) fn extract_struct_from_enum_variant(
let enum_hir = ctx.sema.to_def(&enum_ast)?; let enum_hir = ctx.sema.to_def(&enum_ast)?;
let target = variant.syntax().text_range(); let target = variant.syntax().text_range();
acc.add( acc.add(
AssistId("extract_struct_from_enum_variant", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("extract_struct_from_enum_variant"),
"Extract struct from enum variant", "Extract struct from enum variant",
target, target,
|builder| { |builder| {

View File

@ -5,7 +5,7 @@ use syntax::{
syntax_editor, syntax_editor,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: extract_type_alias // Assist: extract_type_alias
// //
@ -40,7 +40,7 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let target = ty.syntax().text_range(); let target = ty.syntax().text_range();
acc.add( acc.add(
AssistId("extract_type_alias", AssistKind::RefactorExtract), AssistId::refactor_extract("extract_type_alias"),
"Extract type as type alias", "Extract type as type alias",
target, target,
|builder| { |builder| {

View File

@ -13,7 +13,7 @@ use syntax::{
syntax_editor::Position, syntax_editor::Position,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, utils::is_body_const}; use crate::{AssistContext, AssistId, Assists, utils::is_body_const};
// Assist: extract_variable // Assist: extract_variable
// //
@ -311,7 +311,7 @@ impl ExtractionKind {
ExtractionKind::Static => "extract_static", ExtractionKind::Static => "extract_static",
}; };
AssistId(s, AssistKind::RefactorExtract) AssistId::refactor_extract(s)
} }
fn label(&self) -> &'static str { fn label(&self) -> &'static str {

View File

@ -7,7 +7,7 @@ use syntax::{
ast::{self, HasVisibility as _, edit_in_place::HasVisibilityEdit, make}, ast::{self, HasVisibility as _, edit_in_place::HasVisibilityEdit, make},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// FIXME: this really should be a fix for diagnostic, rather than an assist. // FIXME: this really should be a fix for diagnostic, rather than an assist.
@ -78,7 +78,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext<'_>)
} }
}; };
acc.add(AssistId("fix_visibility", AssistKind::QuickFix), assist_label, target, |edit| { acc.add(AssistId::quick_fix("fix_visibility"), assist_label, target, |edit| {
edit.edit_file(target_file); edit.edit_file(target_file);
let vis_owner = edit.make_mut(vis_owner); let vis_owner = edit.make_mut(vis_owner);
@ -131,7 +131,7 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext<'_>
target_name.display(ctx.db(), current_edition) target_name.display(ctx.db(), current_edition)
); );
acc.add(AssistId("fix_visibility", AssistKind::QuickFix), assist_label, target, |edit| { acc.add(AssistId::quick_fix("fix_visibility"), assist_label, target, |edit| {
edit.edit_file(target_file.file_id()); edit.edit_file(target_file.file_id());
let vis_owner = edit.make_mut(vis_owner); let vis_owner = edit.make_mut(vis_owner);

View File

@ -3,7 +3,7 @@ use syntax::{
ast::{self, AstNode, BinExpr, syntax_factory::SyntaxFactory}, ast::{self, AstNode, BinExpr, syntax_factory::SyntaxFactory},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: flip_binexpr // Assist: flip_binexpr
// //
@ -43,7 +43,7 @@ pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
} }
acc.add( acc.add(
AssistId("flip_binexpr", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("flip_binexpr"),
"Flip binary expression", "Flip binary expression",
op_token.text_range(), op_token.text_range(),
|builder| { |builder| {

View File

@ -5,7 +5,7 @@ use syntax::{
syntax_editor::SyntaxMapping, syntax_editor::SyntaxMapping,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: flip_comma // Assist: flip_comma
// //
@ -40,7 +40,7 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
} }
let target = comma.text_range(); let target = comma.text_range();
acc.add(AssistId("flip_comma", AssistKind::RefactorRewrite), "Flip comma", target, |builder| { acc.add(AssistId::refactor_rewrite("flip_comma"), "Flip comma", target, |builder| {
let parent = comma.parent().unwrap(); let parent = comma.parent().unwrap();
let mut editor = builder.make_editor(&parent); let mut editor = builder.make_editor(&parent);

View File

@ -4,7 +4,7 @@ use syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: flip_or_pattern // Assist: flip_or_pattern
// //
@ -31,17 +31,12 @@ pub(crate) fn flip_or_pattern(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
let after = non_trivia_sibling(pipe.clone().into(), Direction::Next)?.into_node()?; let after = non_trivia_sibling(pipe.clone().into(), Direction::Next)?.into_node()?;
let target = pipe.text_range(); let target = pipe.text_range();
acc.add( acc.add(AssistId::refactor_rewrite("flip_or_pattern"), "Flip patterns", target, |builder| {
AssistId("flip_or_pattern", AssistKind::RefactorRewrite), let mut editor = builder.make_editor(parent.syntax());
"Flip patterns", editor.replace(before.clone(), after.clone());
target, editor.replace(after, before);
|builder| { builder.add_file_edits(ctx.file_id(), editor);
let mut editor = builder.make_editor(parent.syntax()); })
editor.replace(before.clone(), after.clone());
editor.replace(after, before);
builder.add_file_edits(ctx.file_id(), editor);
},
)
} }
#[cfg(test)] #[cfg(test)]

View File

@ -4,7 +4,7 @@ use syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: flip_trait_bound // Assist: flip_trait_bound
// //
@ -29,7 +29,7 @@ pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let target = plus.text_range(); let target = plus.text_range();
acc.add( acc.add(
AssistId("flip_trait_bound", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("flip_trait_bound"),
"Flip trait bounds", "Flip trait bounds",
target, target,
|builder| { |builder| {

View File

@ -2,7 +2,7 @@ use crate::assist_context::{AssistContext, Assists};
use hir::{HasVisibility, HirDisplay, HirFileIdExt, Module}; use hir::{HasVisibility, HirDisplay, HirFileIdExt, Module};
use ide_db::{ use ide_db::{
FileId, FileId,
assists::{AssistId, AssistKind}, assists::AssistId,
base_db::Upcast, base_db::Upcast,
defs::{Definition, NameRefClass}, defs::{Definition, NameRefClass},
}; };
@ -88,17 +88,12 @@ pub(crate) fn generate_constant(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
); );
let text = get_text_for_generate_constant(not_exist_name_ref, indent, outer_exists, type_name)?; let text = get_text_for_generate_constant(not_exist_name_ref, indent, outer_exists, type_name)?;
acc.add( acc.add(AssistId::quick_fix("generate_constant"), "Generate constant", target, |builder| {
AssistId("generate_constant", AssistKind::QuickFix), if let Some(file_id) = file_id {
"Generate constant", builder.edit_file(file_id);
target, }
|builder| { builder.insert(offset, format!("{text}{post_string}"));
if let Some(file_id) = file_id { })
builder.edit_file(file_id);
}
builder.insert(offset, format!("{text}{post_string}"));
},
)
} }
fn get_text_for_generate_constant( fn get_text_for_generate_constant(

View File

@ -1,7 +1,7 @@
use ide_db::{RootDatabase, famous_defs::FamousDefs}; use ide_db::{RootDatabase, famous_defs::FamousDefs};
use syntax::ast::{self, AstNode, HasName}; use syntax::ast::{self, AstNode, HasName};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: generate_default_from_enum_variant // Assist: generate_default_from_enum_variant
// //
@ -47,7 +47,7 @@ pub(crate) fn generate_default_from_enum_variant(
let target = variant.syntax().text_range(); let target = variant.syntax().text_range();
acc.add( acc.add(
AssistId("generate_default_from_enum_variant", AssistKind::Generate), AssistId::generate("generate_default_from_enum_variant"),
"Generate `Default` impl from this enum variant", "Generate `Default` impl from this enum variant",
target, target,
|edit| { |edit| {

View File

@ -65,7 +65,7 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext<'
let insert_location = impl_.syntax().text_range(); let insert_location = impl_.syntax().text_range();
acc.add( acc.add(
AssistId("generate_default_from_new", crate::AssistKind::Generate), AssistId::generate("generate_default_from_new"),
"Generate a Default impl from a new fn", "Generate a Default impl from a new fn",
insert_location, insert_location,
move |builder| { move |builder| {

View File

@ -8,7 +8,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists, SourceChangeBuilder}, assist_context::{AssistContext, Assists, SourceChangeBuilder},
utils::generate_trait_impl_text, utils::generate_trait_impl_text,
}; };
@ -65,7 +65,7 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
let field_name = field.name()?; let field_name = field.name()?;
let target = field.syntax().text_range(); let target = field.syntax().text_range();
acc.add( acc.add(
AssistId("generate_deref", AssistKind::Generate), AssistId::generate("generate_deref"),
format!("Generate `{deref_type_to_generate:?}` impl using `{field_name}`"), format!("Generate `{deref_type_to_generate:?}` impl using `{field_name}`"),
target, target,
|edit| { |edit| {
@ -106,7 +106,7 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
let field_type = field.ty()?; let field_type = field.ty()?;
let target = field.syntax().text_range(); let target = field.syntax().text_range();
acc.add( acc.add(
AssistId("generate_deref", AssistKind::Generate), AssistId::generate("generate_deref"),
format!("Generate `{deref_type_to_generate:?}` impl using `{field}`"), format!("Generate `{deref_type_to_generate:?}` impl using `{field}`"),
target, target,
|edit| { |edit| {

View File

@ -3,7 +3,7 @@ use syntax::{
ast::{self, AstNode, HasAttrs, edit_in_place::AttrsOwnerEdit, make}, ast::{self, AstNode, HasAttrs, edit_in_place::AttrsOwnerEdit, make},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: generate_derive // Assist: generate_derive
// //
@ -39,7 +39,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
Some(tt) => Some(tt.right_delimiter_token()?), Some(tt) => Some(tt.right_delimiter_token()?),
}; };
acc.add(AssistId("generate_derive", AssistKind::Generate), "Add `#[derive]`", target, |edit| { acc.add(AssistId::generate("generate_derive"), "Add `#[derive]`", target, |edit| {
match derive_attr { match derive_attr {
None => { None => {
let derive = make::attr_outer(make::meta_token_tree( let derive = make::attr_outer(make::meta_token_tree(

View File

@ -1,5 +1,5 @@
use hir::{AsAssocItem, HasVisibility, ModuleDef, Visibility}; use hir::{AsAssocItem, HasVisibility, ModuleDef, Visibility};
use ide_db::assists::{AssistId, AssistKind}; use ide_db::assists::AssistId;
use itertools::Itertools; use itertools::Itertools;
use stdx::{format_to, to_lower_snake_case}; use stdx::{format_to, to_lower_snake_case};
use syntax::{ use syntax::{
@ -56,7 +56,7 @@ pub(crate) fn generate_documentation_template(
let indent_level = IndentLevel::from_node(parent_syntax); let indent_level = IndentLevel::from_node(parent_syntax);
acc.add( acc.add(
AssistId("generate_documentation_template", AssistKind::Generate), AssistId::generate("generate_documentation_template"),
"Generate a documentation template", "Generate a documentation template",
text_range, text_range,
|builder| { |builder| {
@ -115,7 +115,7 @@ pub(crate) fn generate_doc_example(acc: &mut Assists, ctx: &AssistContext<'_>) -
let indent_level = IndentLevel::from_node(&node); let indent_level = IndentLevel::from_node(&node);
acc.add( acc.add(
AssistId("generate_doc_example", AssistKind::Generate), AssistId::generate("generate_doc_example"),
"Generate a documentation example", "Generate a documentation example",
node.text_range(), node.text_range(),
|builder| { |builder| {

View File

@ -4,7 +4,7 @@ use syntax::ast::HasVisibility;
use syntax::ast::{self, AstNode, HasName}; use syntax::ast::{self, AstNode, HasName};
use crate::{ use crate::{
AssistContext, AssistId, AssistKind, Assists, AssistContext, AssistId, Assists,
utils::{add_method_to_adt, find_struct_impl}, utils::{add_method_to_adt, find_struct_impl},
}; };
@ -57,7 +57,7 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext<'_>
let target = variant.syntax().text_range(); let target = variant.syntax().text_range();
acc.add_group( acc.add_group(
&GroupLabel("Generate an `is_`,`as_`, or `try_into_` for this enum variant".to_owned()), &GroupLabel("Generate an `is_`,`as_`, or `try_into_` for this enum variant".to_owned()),
AssistId("generate_enum_is_method", AssistKind::Generate), AssistId::generate("generate_enum_is_method"),
"Generate an `is_` method for this enum variant", "Generate an `is_` method for this enum variant",
target, target,
|builder| { |builder| {

View File

@ -5,7 +5,7 @@ use syntax::ast::HasVisibility;
use syntax::ast::{self, AstNode, HasName}; use syntax::ast::{self, AstNode, HasName};
use crate::{ use crate::{
AssistContext, AssistId, AssistKind, Assists, AssistContext, AssistId, Assists,
utils::{add_method_to_adt, find_struct_impl}, utils::{add_method_to_adt, find_struct_impl},
}; };
@ -153,7 +153,7 @@ fn generate_enum_projection_method(
let target = variant.syntax().text_range(); let target = variant.syntax().text_range();
acc.add_group( acc.add_group(
&GroupLabel("Generate an `is_`,`as_`, or `try_into_` for this enum variant".to_owned()), &GroupLabel("Generate an `is_`,`as_`, or `try_into_` for this enum variant".to_owned()),
AssistId(assist_id, AssistKind::Generate), AssistId::generate(assist_id),
assist_description, assist_description,
target, target,
|builder| { |builder| {

View File

@ -1,5 +1,5 @@
use hir::{HasSource, HirDisplay, InRealFile}; use hir::{HasSource, HirDisplay, InRealFile};
use ide_db::assists::{AssistId, AssistKind}; use ide_db::assists::AssistId;
use syntax::{ use syntax::{
AstNode, SyntaxNode, AstNode, SyntaxNode,
ast::{self, HasArgList, syntax_factory::SyntaxFactory}, ast::{self, HasArgList, syntax_factory::SyntaxFactory},
@ -58,21 +58,16 @@ pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext<'_>)
let db = ctx.db(); let db = ctx.db();
let InRealFile { file_id, value: enum_node } = e.source(db)?.original_ast_node_rooted(db)?; let InRealFile { file_id, value: enum_node } = e.source(db)?.original_ast_node_rooted(db)?;
acc.add( acc.add(AssistId::generate("generate_enum_variant"), "Generate variant", target, |builder| {
AssistId("generate_enum_variant", AssistKind::Generate), let mut editor = builder.make_editor(enum_node.syntax());
"Generate variant", let make = SyntaxFactory::new();
target, let field_list = parent.make_field_list(ctx, &make);
|builder| { let variant = make.variant(None, make.name(&name_ref.text()), field_list, None);
let mut editor = builder.make_editor(enum_node.syntax()); if let Some(it) = enum_node.variant_list() {
let make = SyntaxFactory::new(); it.add_variant(&mut editor, &variant);
let field_list = parent.make_field_list(ctx, &make); }
let variant = make.variant(None, make.name(&name_ref.text()), field_list, None); builder.add_file_edits(file_id, editor);
if let Some(it) = enum_node.variant_list() { })
it.add_variant(&mut editor, &variant);
}
builder.add_file_edits(file_id, editor);
},
)
} }
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,5 +1,5 @@
use either::Either; use either::Either;
use ide_db::assists::{AssistId, AssistKind, GroupLabel}; use ide_db::assists::{AssistId, GroupLabel};
use syntax::{ use syntax::{
AstNode, AstNode,
ast::{self, HasGenericParams, HasName, edit::IndentLevel, make}, ast::{self, HasGenericParams, HasName, edit::IndentLevel, make},
@ -139,7 +139,7 @@ impl ParamStyle {
ParamStyle::Unnamed => "generate_fn_type_alias_unnamed", ParamStyle::Unnamed => "generate_fn_type_alias_unnamed",
}; };
AssistId(s, AssistKind::Generate) AssistId::generate(s)
} }
fn label(&self) -> &'static str { fn label(&self) -> &'static str {

View File

@ -1,9 +1,7 @@
use ide_db::{RootDatabase, famous_defs::FamousDefs}; use ide_db::{RootDatabase, famous_defs::FamousDefs};
use syntax::ast::{self, AstNode, HasName}; use syntax::ast::{self, AstNode, HasName};
use crate::{ use crate::{AssistContext, AssistId, Assists, utils::generate_trait_impl_text_intransitive};
AssistContext, AssistId, AssistKind, Assists, utils::generate_trait_impl_text_intransitive,
};
// Assist: generate_from_impl_for_enum // Assist: generate_from_impl_for_enum
// //
@ -53,7 +51,7 @@ pub(crate) fn generate_from_impl_for_enum(
let target = variant.syntax().text_range(); let target = variant.syntax().text_range();
acc.add( acc.add(
AssistId("generate_from_impl_for_enum", AssistKind::Generate), AssistId::generate("generate_from_impl_for_enum"),
"Generate `From` impl for this enum variant", "Generate `From` impl for this enum variant",
target, target,
|edit| { |edit| {

View File

@ -23,7 +23,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistContext, AssistId, AssistKind, Assists, AssistContext, AssistId, Assists,
utils::{convert_reference_type, find_struct_impl}, utils::{convert_reference_type, find_struct_impl},
}; };
@ -173,7 +173,7 @@ fn add_func_to_accumulator(
adt_info: Option<AdtInfo>, adt_info: Option<AdtInfo>,
label: String, label: String,
) -> Option<()> { ) -> Option<()> {
acc.add(AssistId("generate_function", AssistKind::Generate), label, text_range, |edit| { acc.add(AssistId::generate("generate_function"), label, text_range, |edit| {
edit.edit_file(file); edit.edit_file(file);
let target = function_builder.target.clone(); let target = function_builder.target.clone();

View File

@ -7,7 +7,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistContext, AssistId, AssistKind, Assists, GroupLabel, AssistContext, AssistId, Assists, GroupLabel,
utils::{convert_reference_type, find_struct_impl, generate_impl}, utils::{convert_reference_type, find_struct_impl, generate_impl},
}; };
@ -63,7 +63,7 @@ pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
acc.add_group( acc.add_group(
&GroupLabel("Generate getter/setter".to_owned()), &GroupLabel("Generate getter/setter".to_owned()),
AssistId("generate_setter", AssistKind::Generate), AssistId::generate("generate_setter"),
"Generate a setter method", "Generate a setter method",
target, target,
|builder| build_source_change(builder, ctx, info_of_record_fields, setter_info), |builder| build_source_change(builder, ctx, info_of_record_fields, setter_info),
@ -204,7 +204,7 @@ pub(crate) fn generate_getter_impl(
acc.add_group( acc.add_group(
&GroupLabel("Generate getter/setter".to_owned()), &GroupLabel("Generate getter/setter".to_owned()),
AssistId(id, AssistKind::Generate), AssistId::generate(id),
label, label,
target, target,
|builder| build_source_change(builder, ctx, info_of_record_fields, getter_info), |builder| build_source_change(builder, ctx, info_of_record_fields, getter_info),

View File

@ -3,7 +3,7 @@ use syntax::{
ted, ted,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, utils}; use crate::{AssistContext, AssistId, Assists, utils};
fn insert_impl(impl_: ast::Impl, nominal: &ast::Adt) { fn insert_impl(impl_: ast::Impl, nominal: &ast::Adt) {
let indent = nominal.indent_level(); let indent = nominal.indent_level();
@ -44,7 +44,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
} }
acc.add( acc.add(
AssistId("generate_impl", AssistKind::Generate), AssistId::generate("generate_impl"),
format!("Generate impl for `{name}`"), format!("Generate impl for `{name}`"),
target, target,
|edit| { |edit| {
@ -90,7 +90,7 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
} }
acc.add( acc.add(
AssistId("generate_trait_impl", AssistKind::Generate), AssistId::generate("generate_trait_impl"),
format!("Generate trait impl for `{name}`"), format!("Generate trait impl for `{name}`"),
target, target,
|edit| { |edit| {

View File

@ -5,7 +5,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -69,7 +69,7 @@ pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext<
let range = node.syntax().value.text_range(); let range = node.syntax().value.text_range();
acc.add( acc.add(
AssistId("generate_is_empty_from_len", AssistKind::Generate), AssistId::generate("generate_is_empty_from_len"),
"Generate a is_empty impl from a len function", "Generate a is_empty impl from a len function",
range, range,
|builder| { |builder| {

View File

@ -5,7 +5,7 @@ use syntax::{
ted, ted,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// FIXME: Generate proper `index_mut` method body refer to `index` method body may impossible due to the unpredictable case [#15581]. // FIXME: Generate proper `index_mut` method body refer to `index` method body may impossible due to the unpredictable case [#15581].
// Here just leave the `index_mut` method body be same as `index` method body, user can modify it manually to meet their need. // Here just leave the `index_mut` method body be same as `index` method body, user can modify it manually to meet their need.
@ -102,7 +102,7 @@ pub(crate) fn generate_mut_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>
let target = impl_def.syntax().text_range(); let target = impl_def.syntax().text_range();
acc.add( acc.add(
AssistId("generate_mut_trait_impl", AssistKind::Generate), AssistId::generate("generate_mut_trait_impl"),
"Generate `IndexMut` impl from this `Index` trait", "Generate `IndexMut` impl from this `Index` trait",
target, target,
|edit| { |edit| {

View File

@ -7,7 +7,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistContext, AssistId, AssistKind, Assists, AssistContext, AssistId, Assists,
utils::{find_struct_impl, generate_impl}, utils::{find_struct_impl, generate_impl},
}; };
@ -48,7 +48,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
let current_module = ctx.sema.scope(strukt.syntax())?.module(); let current_module = ctx.sema.scope(strukt.syntax())?.module();
let target = strukt.syntax().text_range(); let target = strukt.syntax().text_range();
acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| { acc.add(AssistId::generate("generate_new"), "Generate `new`", target, |builder| {
let trivial_constructors = field_list let trivial_constructors = field_list
.fields() .fields()
.map(|f| { .map(|f| {

View File

@ -95,7 +95,7 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
let impl_name = impl_ast.self_ty()?; let impl_name = impl_ast.self_ty()?;
acc.add( acc.add(
AssistId("generate_trait_from_impl", ide_db::assists::AssistKind::Generate), AssistId::generate("generate_trait_from_impl"),
"Generate trait from impl", "Generate trait from impl",
impl_ast.syntax().text_range(), impl_ast.syntax().text_range(),
|builder| { |builder| {

View File

@ -27,7 +27,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -98,7 +98,7 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) ->
} }
acc.add( acc.add(
AssistId("inline_into_callers", AssistKind::RefactorInline), AssistId::refactor_inline("inline_into_callers"),
"Inline into all callers", "Inline into all callers",
name.syntax().text_range(), name.syntax().text_range(),
|builder| { |builder| {
@ -232,21 +232,16 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
} }
let syntax = call_info.node.syntax().clone(); let syntax = call_info.node.syntax().clone();
acc.add( acc.add(AssistId::refactor_inline("inline_call"), label, syntax.text_range(), |builder| {
AssistId("inline_call", AssistKind::RefactorInline), let replacement = inline(&ctx.sema, file_id, function, &fn_body, &params, &call_info);
label, builder.replace_ast(
syntax.text_range(), match call_info.node {
|builder| { ast::CallableExpr::Call(it) => ast::Expr::CallExpr(it),
let replacement = inline(&ctx.sema, file_id, function, &fn_body, &params, &call_info); ast::CallableExpr::MethodCall(it) => ast::Expr::MethodCallExpr(it),
builder.replace_ast( },
match call_info.node { replacement,
ast::CallableExpr::Call(it) => ast::Expr::CallExpr(it), );
ast::CallableExpr::MethodCall(it) => ast::Expr::MethodCallExpr(it), })
},
replacement,
);
},
)
} }
struct CallInfo { struct CallInfo {

View File

@ -1,7 +1,7 @@
use hir::HasCrate; use hir::HasCrate;
use syntax::{AstNode, ast}; use syntax::{AstNode, ast};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: inline_const_as_literal // Assist: inline_const_as_literal
// //
@ -44,7 +44,7 @@ pub(crate) fn inline_const_as_literal(acc: &mut Assists, ctx: &AssistContext<'_>
.ok()? .ok()?
.render(ctx.sema.db, konst.krate(ctx.sema.db).to_display_target(ctx.sema.db)); .render(ctx.sema.db, konst.krate(ctx.sema.db).to_display_target(ctx.sema.db));
let id = AssistId("inline_const_as_literal", AssistKind::RefactorInline); let id = AssistId::refactor_inline("inline_const_as_literal");
let label = "Inline const as literal".to_owned(); let label = "Inline const as literal".to_owned();
let target = variable.syntax().text_range(); let target = variable.syntax().text_range();

View File

@ -10,7 +10,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -74,7 +74,7 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext<'_>)
}; };
acc.add( acc.add(
AssistId("inline_local_variable", AssistKind::RefactorInline), AssistId::refactor_inline("inline_local_variable"),
"Inline variable", "Inline variable",
target.text_range(), target.text_range(),
move |builder| { move |builder| {

View File

@ -2,7 +2,7 @@ use hir::db::ExpandDatabase;
use ide_db::syntax_helpers::prettify_macro_expansion; use ide_db::syntax_helpers::prettify_macro_expansion;
use syntax::ast::{self, AstNode}; use syntax::ast::{self, AstNode};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: inline_macro // Assist: inline_macro
// //
@ -42,7 +42,7 @@ pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
let text_range = unexpanded.syntax().text_range(); let text_range = unexpanded.syntax().text_range();
acc.add( acc.add(
AssistId("inline_macro", AssistKind::RefactorInline), AssistId::refactor_inline("inline_macro"),
"Inline macro".to_owned(), "Inline macro".to_owned(),
text_range, text_range,
|builder| { |builder| {

View File

@ -16,7 +16,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -60,7 +60,7 @@ pub(crate) fn inline_type_alias_uses(acc: &mut Assists, ctx: &AssistContext<'_>)
// until this is ok // until this is ok
acc.add( acc.add(
AssistId("inline_type_alias_uses", AssistKind::RefactorInline), AssistId::refactor_inline("inline_type_alias_uses"),
"Inline type alias into all uses", "Inline type alias into all uses",
name.syntax().text_range(), name.syntax().text_range(),
|builder| { |builder| {
@ -149,7 +149,7 @@ pub(crate) fn inline_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
let target = alias_instance.syntax().text_range(); let target = alias_instance.syntax().text_range();
acc.add( acc.add(
AssistId("inline_type_alias", AssistKind::RefactorInline), AssistId::refactor_inline("inline_type_alias"),
"Inline type alias", "Inline type alias",
target, target,
|builder| builder.replace(target, replacement.to_text(&concrete_type)), |builder| builder.replace(target, replacement.to_text(&concrete_type)),

View File

@ -1,8 +1,5 @@
use hir::{AsAssocItem, HirDisplay}; use hir::{AsAssocItem, HirDisplay};
use ide_db::{ use ide_db::{assists::AssistId, famous_defs::FamousDefs};
assists::{AssistId, AssistKind},
famous_defs::FamousDefs,
};
use syntax::{AstNode, ast}; use syntax::{AstNode, ast};
use crate::assist_context::{AssistContext, Assists}; use crate::assist_context::{AssistContext, Assists};
@ -60,7 +57,7 @@ pub(crate) fn into_to_qualified_from(acc: &mut Assists, ctx: &AssistContext<'_>)
let sc = adjusted_tc.display_source_code(db, scope.module().into(), true).ok()?; let sc = adjusted_tc.display_source_code(db, scope.module().into(), true).ok()?;
acc.add( acc.add(
AssistId("into_to_qualified_from", AssistKind::Generate), AssistId::generate("into_to_qualified_from"),
"Convert `into` to fully qualified `from`", "Convert `into` to fully qualified `from`",
nameref.syntax().text_range(), nameref.syntax().text_range(),
|edit| { |edit| {

View File

@ -5,7 +5,7 @@ use syntax::{
ted::{self, Position}, ted::{self, Position},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder}; use crate::{AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder};
static ASSIST_NAME: &str = "introduce_named_lifetime"; static ASSIST_NAME: &str = "introduce_named_lifetime";
static ASSIST_LABEL: &str = "Introduce named lifetime"; static ASSIST_LABEL: &str = "Introduce named lifetime";
@ -83,7 +83,7 @@ fn generate_fn_def_assist(
_ => return None, _ => return None,
} }
}; };
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| { acc.add(AssistId::refactor(ASSIST_NAME), ASSIST_LABEL, lifetime_loc, |builder| {
let fn_def = builder.make_mut(fn_def); let fn_def = builder.make_mut(fn_def);
let lifetime = builder.make_mut(lifetime); let lifetime = builder.make_mut(lifetime);
let loc_needing_lifetime = let loc_needing_lifetime =
@ -107,7 +107,7 @@ fn generate_impl_def_assist(
lifetime: ast::Lifetime, lifetime: ast::Lifetime,
) -> Option<()> { ) -> Option<()> {
let new_lifetime_param = generate_unique_lifetime_param_name(impl_def.generic_param_list())?; let new_lifetime_param = generate_unique_lifetime_param_name(impl_def.generic_param_list())?;
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| { acc.add(AssistId::refactor(ASSIST_NAME), ASSIST_LABEL, lifetime_loc, |builder| {
let impl_def = builder.make_mut(impl_def); let impl_def = builder.make_mut(impl_def);
let lifetime = builder.make_mut(lifetime); let lifetime = builder.make_mut(lifetime);

View File

@ -2,7 +2,7 @@ use ide_db::syntax_helpers::suggest_name;
use itertools::Itertools; use itertools::Itertools;
use syntax::ast::{self, AstNode, HasGenericParams, HasName, syntax_factory::SyntaxFactory}; use syntax::ast::{self, AstNode, HasGenericParams, HasName, syntax_factory::SyntaxFactory};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: introduce_named_type_parameter // Assist: introduce_named_type_parameter
// //
@ -27,7 +27,7 @@ pub(crate) fn introduce_named_type_parameter(
let make = SyntaxFactory::new(); let make = SyntaxFactory::new();
let target = fn_.syntax().text_range(); let target = fn_.syntax().text_range();
acc.add( acc.add(
AssistId("introduce_named_type_parameter", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("introduce_named_type_parameter"),
"Replace impl trait with type parameter", "Replace impl trait with type parameter",
target, target,
|builder| { |builder| {

View File

@ -5,7 +5,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
utils::invert_boolean_expression_legacy, utils::invert_boolean_expression_legacy,
}; };
@ -47,7 +47,7 @@ pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
ast::ElseBranch::IfExpr(_) => return None, ast::ElseBranch::IfExpr(_) => return None,
}; };
acc.add(AssistId("invert_if", AssistKind::RefactorRewrite), "Invert if", if_range, |edit| { acc.add(AssistId::refactor_rewrite("invert_if"), "Invert if", if_range, |edit| {
let flip_cond = invert_boolean_expression_legacy(cond.clone()); let flip_cond = invert_boolean_expression_legacy(cond.clone());
edit.replace_ast(cond, flip_cond); edit.replace_ast(cond, flip_cond);

View File

@ -12,7 +12,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
utils::next_prev, utils::next_prev,
}; };
@ -69,55 +69,50 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
(selection_range, edits?) (selection_range, edits?)
}; };
acc.add( acc.add(AssistId::refactor_rewrite("merge_imports"), "Merge imports", target, |builder| {
AssistId("merge_imports", AssistKind::RefactorRewrite), let edits_mut: Vec<Edit> = edits
"Merge imports", .into_iter()
target, .map(|it| match it {
|builder| { Remove(Either::Left(it)) => Remove(Either::Left(builder.make_mut(it))),
let edits_mut: Vec<Edit> = edits Remove(Either::Right(it)) => Remove(Either::Right(builder.make_mut(it))),
.into_iter() Replace(old, new) => Replace(builder.make_syntax_mut(old), new),
.map(|it| match it { })
Remove(Either::Left(it)) => Remove(Either::Left(builder.make_mut(it))), .collect();
Remove(Either::Right(it)) => Remove(Either::Right(builder.make_mut(it))), for edit in edits_mut {
Replace(old, new) => Replace(builder.make_syntax_mut(old), new), match edit {
}) Remove(it) => it.as_ref().either(Removable::remove, Removable::remove),
.collect(); Replace(old, new) => {
for edit in edits_mut { ted::replace(old, &new);
match edit {
Remove(it) => it.as_ref().either(Removable::remove, Removable::remove),
Replace(old, new) => {
ted::replace(old, &new);
// If there's a selection and we're replacing a use tree in a tree list, // If there's a selection and we're replacing a use tree in a tree list,
// normalize the parent use tree if it only contains the merged subtree. // normalize the parent use tree if it only contains the merged subtree.
if !ctx.has_empty_selection() { if !ctx.has_empty_selection() {
let normalized_use_tree = ast::UseTree::cast(new) let normalized_use_tree = ast::UseTree::cast(new)
.as_ref() .as_ref()
.and_then(ast::UseTree::parent_use_tree_list) .and_then(ast::UseTree::parent_use_tree_list)
.and_then(|use_tree_list| { .and_then(|use_tree_list| {
if use_tree_list.use_trees().collect_tuple::<(_,)>().is_some() { if use_tree_list.use_trees().collect_tuple::<(_,)>().is_some() {
Some(use_tree_list.parent_use_tree()) Some(use_tree_list.parent_use_tree())
} else { } else {
None None
} }
}) })
.and_then(|target_tree| { .and_then(|target_tree| {
try_normalize_use_tree( try_normalize_use_tree(
&target_tree, &target_tree,
ctx.config.insert_use.granularity.into(), ctx.config.insert_use.granularity.into(),
) )
.map(|top_use_tree_flat| (target_tree, top_use_tree_flat)) .map(|top_use_tree_flat| (target_tree, top_use_tree_flat))
}); });
if let Some((old_tree, new_tree)) = normalized_use_tree { if let Some((old_tree, new_tree)) = normalized_use_tree {
cov_mark::hit!(replace_parent_with_normalized_use_tree); cov_mark::hit!(replace_parent_with_normalized_use_tree);
ted::replace(old_tree.syntax(), new_tree.syntax()); ted::replace(old_tree.syntax(), new_tree.syntax());
}
} }
} }
} }
} }
}, }
) })
} }
trait Merge: AstNode + Clone { trait Merge: AstNode + Clone {

View File

@ -7,7 +7,7 @@ use syntax::{
ast::{self, AstNode, HasName}, ast::{self, AstNode, HasName},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists, TextRange}; use crate::{AssistContext, AssistId, Assists, TextRange};
// Assist: merge_match_arms // Assist: merge_match_arms
// //
@ -73,7 +73,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
} }
acc.add( acc.add(
AssistId("merge_match_arms", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("merge_match_arms"),
"Merge match arms", "Merge match arms",
current_text_range, current_text_range,
|edit| { |edit| {

View File

@ -5,7 +5,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
// Assist: merge_nested_if // Assist: merge_nested_if
@ -69,29 +69,24 @@ pub(crate) fn merge_nested_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
let nested_if_then_branch = nested_if_to_merge.then_branch()?; let nested_if_then_branch = nested_if_to_merge.then_branch()?;
let then_branch_range = then_branch.syntax().text_range(); let then_branch_range = then_branch.syntax().text_range();
acc.add( acc.add(AssistId::refactor_rewrite("merge_nested_if"), "Merge nested if", if_range, |edit| {
AssistId("merge_nested_if", AssistKind::RefactorRewrite), let cond_text = if has_logic_op_or(&cond) {
"Merge nested if", format!("({})", cond.syntax().text())
if_range, } else {
|edit| { cond.syntax().text().to_string()
let cond_text = if has_logic_op_or(&cond) { };
format!("({})", cond.syntax().text())
} else {
cond.syntax().text().to_string()
};
let nested_if_cond_text = if has_logic_op_or(&nested_if_cond) { let nested_if_cond_text = if has_logic_op_or(&nested_if_cond) {
format!("({})", nested_if_cond.syntax().text()) format!("({})", nested_if_cond.syntax().text())
} else { } else {
nested_if_cond.syntax().text().to_string() nested_if_cond.syntax().text().to_string()
}; };
let replace_cond = format!("{cond_text} && {nested_if_cond_text}"); let replace_cond = format!("{cond_text} && {nested_if_cond_text}");
edit.replace(cond_range, replace_cond); edit.replace(cond_range, replace_cond);
edit.replace(then_branch_range, nested_if_then_branch.syntax().text()); edit.replace(then_branch_range, nested_if_then_branch.syntax().text());
}, })
)
} }
/// Returns whether the given if condition has logical operators. /// Returns whether the given if condition has logical operators.

View File

@ -7,7 +7,7 @@ use syntax::{
match_ast, match_ast,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: move_bounds_to_where_clause // Assist: move_bounds_to_where_clause
// //
@ -42,7 +42,7 @@ pub(crate) fn move_bounds_to_where_clause(
let target = type_param_list.syntax().text_range(); let target = type_param_list.syntax().text_range();
acc.add( acc.add(
AssistId("move_bounds_to_where_clause", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("move_bounds_to_where_clause"),
"Move to where clause", "Move to where clause",
target, target,
|edit| { |edit| {

View File

@ -83,7 +83,7 @@ pub(crate) fn move_const_to_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
} }
acc.add( acc.add(
AssistId("move_const_to_impl", crate::AssistKind::RefactorRewrite), AssistId::refactor_rewrite("move_const_to_impl"),
"Move const to impl block", "Move const to impl block",
const_.syntax().text_range(), const_.syntax().text_range(),
|builder| { |builder| {

View File

@ -1,7 +1,4 @@
use ide_db::{ use ide_db::{assists::AssistId, base_db::AnchoredPathBuf};
assists::{AssistId, AssistKind},
base_db::AnchoredPathBuf,
};
use syntax::{AstNode, ToSmolStr, ast}; use syntax::{AstNode, ToSmolStr, ast};
use crate::{ use crate::{
@ -43,7 +40,7 @@ pub(crate) fn move_from_mod_rs(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let path = format!("../{module_name}.rs"); let path = format!("../{module_name}.rs");
let dst = AnchoredPathBuf { anchor: ctx.file_id().into(), path }; let dst = AnchoredPathBuf { anchor: ctx.file_id().into(), path };
acc.add( acc.add(
AssistId("move_from_mod_rs", AssistKind::Refactor), AssistId::refactor("move_from_mod_rs"),
format!("Convert {module_name}/mod.rs to {module_name}.rs"), format!("Convert {module_name}/mod.rs to {module_name}.rs"),
target, target,
|builder| { |builder| {

View File

@ -3,7 +3,7 @@ use syntax::{
ast::{AstNode, BlockExpr, ElseBranch, Expr, IfExpr, MatchArm, Pat, edit::AstNodeEdit, make}, ast::{AstNode, BlockExpr, ElseBranch, Expr, IfExpr, MatchArm, Pat, edit::AstNodeEdit, make},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: move_guard_to_arm_body // Assist: move_guard_to_arm_body
// //
@ -49,7 +49,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext<'_>)
let target = guard.syntax().text_range(); let target = guard.syntax().text_range();
acc.add( acc.add(
AssistId("move_guard_to_arm_body", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("move_guard_to_arm_body"),
"Move guard to arm body", "Move guard to arm body",
target, target,
|edit| { |edit| {
@ -118,7 +118,7 @@ pub(crate) fn move_arm_cond_to_match_guard(
let (conds_blocks, tail) = parse_if_chain(if_expr)?; let (conds_blocks, tail) = parse_if_chain(if_expr)?;
acc.add( acc.add(
AssistId("move_arm_cond_to_match_guard", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("move_arm_cond_to_match_guard"),
"Move condition to match guard", "Move condition to match guard",
replace_node.text_range(), replace_node.text_range(),
|edit| { |edit| {

View File

@ -10,7 +10,7 @@ use syntax::{
ast::{self, HasName, edit::AstNodeEdit}, ast::{self, HasName, edit::AstNodeEdit},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: move_module_to_file // Assist: move_module_to_file
// //
@ -45,7 +45,7 @@ pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let parent_module = module_def.parent(ctx.db())?; let parent_module = module_def.parent(ctx.db())?;
acc.add( acc.add(
AssistId("move_module_to_file", AssistKind::RefactorExtract), AssistId::refactor_extract("move_module_to_file"),
"Extract module to file", "Extract module to file",
target, target,
|builder| { |builder| {

View File

@ -1,7 +1,4 @@
use ide_db::{ use ide_db::{assists::AssistId, base_db::AnchoredPathBuf};
assists::{AssistId, AssistKind},
base_db::AnchoredPathBuf,
};
use syntax::{AstNode, ToSmolStr, ast}; use syntax::{AstNode, ToSmolStr, ast};
use crate::{ use crate::{
@ -43,7 +40,7 @@ pub(crate) fn move_to_mod_rs(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
let path = format!("./{module_name}/mod.rs"); let path = format!("./{module_name}/mod.rs");
let dst = AnchoredPathBuf { anchor: ctx.file_id().into(), path }; let dst = AnchoredPathBuf { anchor: ctx.file_id().into(), path };
acc.add( acc.add(
AssistId("move_to_mod_rs", AssistKind::Refactor), AssistId::refactor("move_to_mod_rs"),
format!("Convert {module_name}.rs to {module_name}/mod.rs"), format!("Convert {module_name}.rs to {module_name}/mod.rs"),
target, target,
|builder| { |builder| {

View File

@ -2,7 +2,7 @@ use ide_db::imports::merge_imports::try_normalize_import;
use syntax::{AstNode, ast}; use syntax::{AstNode, ast};
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -28,14 +28,9 @@ pub(crate) fn normalize_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let normalized_use_item = let normalized_use_item =
try_normalize_import(&use_item, ctx.config.insert_use.granularity.into())?; try_normalize_import(&use_item, ctx.config.insert_use.granularity.into())?;
acc.add( acc.add(AssistId::refactor_rewrite("normalize_import"), "Normalize import", target, |builder| {
AssistId("normalize_import", AssistKind::RefactorRewrite), builder.replace_ast(use_item, normalized_use_item);
"Normalize import", })
target,
|builder| {
builder.replace_ast(use_item, normalized_use_item);
},
)
} }
#[cfg(test)] #[cfg(test)]

View File

@ -1,6 +1,6 @@
use syntax::{AstToken, ast, ast::Radix}; use syntax::{AstToken, ast, ast::Radix};
use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; use crate::{AssistContext, AssistId, Assists, GroupLabel};
const MIN_NUMBER_OF_DIGITS_TO_FORMAT: usize = 5; const MIN_NUMBER_OF_DIGITS_TO_FORMAT: usize = 5;
@ -42,7 +42,7 @@ pub(crate) fn reformat_number_literal(acc: &mut Assists, ctx: &AssistContext<'_>
let range = literal.syntax().text_range(); let range = literal.syntax().text_range();
acc.add_group( acc.add_group(
&group_id, &group_id,
AssistId("reformat_number_literal", AssistKind::RefactorInline), AssistId::refactor_inline("reformat_number_literal"),
label, label,
range, range,
|builder| builder.replace(range, converted), |builder| builder.replace(range, converted),
@ -54,7 +54,7 @@ fn remove_separators(acc: &mut Assists, literal: ast::IntNumber) -> Option<()> {
let range = literal.syntax().text_range(); let range = literal.syntax().text_range();
acc.add_group( acc.add_group(
&group_id, &group_id,
AssistId("reformat_number_literal", AssistKind::RefactorInline), AssistId::refactor_inline("reformat_number_literal"),
"Remove digit separators", "Remove digit separators",
range, range,
|builder| builder.replace(range, literal.text().replace('_', "")), |builder| builder.replace(range, literal.text().replace('_', "")),

View File

@ -1,8 +1,5 @@
use hir::HirDisplay; use hir::HirDisplay;
use ide_db::{ use ide_db::{assists::AssistId, defs::Definition};
assists::{AssistId, AssistKind},
defs::Definition,
};
use stdx::to_upper_snake_case; use stdx::to_upper_snake_case;
use syntax::{ use syntax::{
AstNode, AstNode,
@ -68,7 +65,7 @@ pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext<'_>)
} }
acc.add( acc.add(
AssistId("promote_local_to_const", AssistKind::Refactor), AssistId::refactor("promote_local_to_const"),
"Promote local to constant", "Promote local to constant",
let_stmt.syntax().text_range(), let_stmt.syntax().text_range(),
|edit| { |edit| {

View File

@ -5,7 +5,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
}; };
@ -68,7 +68,7 @@ pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext<'_>) ->
} }
acc.add( acc.add(
AssistId("pull_assignment_up", AssistKind::RefactorExtract), AssistId::refactor_extract("pull_assignment_up"),
"Pull assignment up", "Pull assignment up",
tgt.syntax().text_range(), tgt.syntax().text_range(),
move |edit| { move |edit| {

View File

@ -1,5 +1,5 @@
use hir::{AsAssocItem, AssocItem, AssocItemContainer, ItemInNs, ModuleDef, db::HirDatabase}; use hir::{AsAssocItem, AssocItem, AssocItemContainer, ItemInNs, ModuleDef, db::HirDatabase};
use ide_db::assists::{AssistId, AssistKind}; use ide_db::assists::AssistId;
use syntax::{AstNode, ast}; use syntax::{AstNode, ast};
use crate::{ use crate::{
@ -54,7 +54,7 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call); let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
acc.add( acc.add(
AssistId("qualify_method_call", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("qualify_method_call"),
format!("Qualify `{ident}` method call"), format!("Qualify `{ident}` method call"),
range, range,
|builder| { |builder| {

View File

@ -15,7 +15,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, GroupLabel, AssistId, GroupLabel,
assist_context::{AssistContext, Assists}, assist_context::{AssistContext, Assists},
handlers::auto_import::find_importable_node, handlers::auto_import::find_importable_node,
}; };
@ -104,7 +104,7 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
for import in proposed_imports { for import in proposed_imports {
acc.add_group( acc.add_group(
&group_label, &group_label,
AssistId("qualify_path", AssistKind::QuickFix), AssistId::quick_fix("qualify_path"),
label(ctx.db(), candidate, &import, current_edition), label(ctx.db(), candidate, &import, current_edition),
range, range,
|builder| { |builder| {

View File

@ -2,7 +2,7 @@ use std::borrow::Cow;
use syntax::{AstToken, TextRange, TextSize, ast, ast::IsString}; use syntax::{AstToken, TextRange, TextSize, ast, ast::IsString};
use crate::{AssistContext, AssistId, AssistKind, Assists, utils::required_hashes}; use crate::{AssistContext, AssistId, Assists, utils::required_hashes};
// Assist: make_raw_string // Assist: make_raw_string
// //
@ -28,7 +28,7 @@ pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
let value = token.value().ok()?; let value = token.value().ok()?;
let target = token.syntax().text_range(); let target = token.syntax().text_range();
acc.add( acc.add(
AssistId("make_raw_string", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("make_raw_string"),
"Rewrite as raw string", "Rewrite as raw string",
target, target,
|edit| { |edit| {
@ -67,7 +67,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
let value = token.value().ok()?; let value = token.value().ok()?;
let target = token.syntax().text_range(); let target = token.syntax().text_range();
acc.add( acc.add(
AssistId("make_usual_string", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("make_usual_string"),
"Rewrite as regular string", "Rewrite as regular string",
target, target,
|edit| { |edit| {
@ -108,7 +108,7 @@ pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()>
} }
let text_range = token.syntax().text_range(); let text_range = token.syntax().text_range();
let target = text_range; let target = text_range;
acc.add(AssistId("add_hash", AssistKind::Refactor), "Add #", target, |edit| { acc.add(AssistId::refactor("add_hash"), "Add #", target, |edit| {
edit.insert(text_range.start() + TextSize::of('r'), "#"); edit.insert(text_range.start() + TextSize::of('r'), "#");
edit.insert(text_range.end(), "#"); edit.insert(text_range.end(), "#");
}) })
@ -150,7 +150,7 @@ pub(crate) fn remove_hash(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
return None; return None;
} }
acc.add(AssistId("remove_hash", AssistKind::RefactorRewrite), "Remove #", text_range, |edit| { acc.add(AssistId::refactor_rewrite("remove_hash"), "Remove #", text_range, |edit| {
edit.delete(TextRange::at(text_range.start() + TextSize::of('r'), TextSize::of('#'))); edit.delete(TextRange::at(text_range.start() + TextSize::of('r'), TextSize::of('#')));
edit.delete(TextRange::new(text_range.end() - TextSize::of('#'), text_range.end())); edit.delete(TextRange::new(text_range.end() - TextSize::of('#'), text_range.end()));
}) })

View File

@ -5,7 +5,7 @@ use syntax::{
match_ast, ted, match_ast, ted,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: remove_dbg // Assist: remove_dbg
// //
@ -42,7 +42,7 @@ pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
macro_calls.into_iter().filter_map(compute_dbg_replacement).collect::<Vec<_>>(); macro_calls.into_iter().filter_map(compute_dbg_replacement).collect::<Vec<_>>();
acc.add( acc.add(
AssistId("remove_dbg", AssistKind::QuickFix), AssistId::quick_fix("remove_dbg"),
"Remove dbg!()", "Remove dbg!()",
replacements.iter().map(|&(range, _)| range).reduce(|acc, range| acc.cover(range))?, replacements.iter().map(|&(range, _)| range).reduce(|acc, range| acc.cover(range))?,
|builder| { |builder| {

View File

@ -1,6 +1,6 @@
use syntax::{SyntaxKind, T}; use syntax::{SyntaxKind, T};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: remove_mut // Assist: remove_mut
// //
@ -21,18 +21,13 @@ pub(crate) fn remove_mut(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
let mut_token = ctx.find_token_syntax_at_offset(T![mut])?; let mut_token = ctx.find_token_syntax_at_offset(T![mut])?;
let target = mut_token.text_range(); let target = mut_token.text_range();
acc.add( acc.add(AssistId::refactor("remove_mut"), "Remove `mut` keyword", target, |builder| {
AssistId("remove_mut", AssistKind::Refactor), let mut editor = builder.make_editor(&mut_token.parent().unwrap());
"Remove `mut` keyword", match mut_token.next_token() {
target, Some(it) if it.kind() == SyntaxKind::WHITESPACE => editor.delete(it),
|builder| { _ => (),
let mut editor = builder.make_editor(&mut_token.parent().unwrap()); }
match mut_token.next_token() { editor.delete(mut_token);
Some(it) if it.kind() == SyntaxKind::WHITESPACE => editor.delete(it), builder.add_file_edits(ctx.file_id(), editor);
_ => (), })
}
editor.delete(mut_token);
builder.add_file_edits(ctx.file_id(), editor);
},
)
} }

View File

@ -4,7 +4,7 @@ use syntax::{
syntax_editor::Position, syntax_editor::Position,
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: remove_parentheses // Assist: remove_parentheses
// //
@ -40,7 +40,7 @@ pub(crate) fn remove_parentheses(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let target = parens.syntax().text_range(); let target = parens.syntax().text_range();
acc.add( acc.add(
AssistId("remove_parentheses", AssistKind::Refactor), AssistId::refactor("remove_parentheses"),
"Remove redundant parentheses", "Remove redundant parentheses",
target, target,
|builder| { |builder| {

View File

@ -12,7 +12,7 @@ use syntax::{
ast::{self, Rename}, ast::{self, Rename},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: remove_unused_imports // Assist: remove_unused_imports
// //
@ -126,7 +126,7 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)
// Peek so we terminate early if an unused use is found. Only do the rest of the work if the user selects the assist. // Peek so we terminate early if an unused use is found. Only do the rest of the work if the user selects the assist.
if unused.peek().is_some() { if unused.peek().is_some() {
acc.add( acc.add(
AssistId("remove_unused_imports", AssistKind::QuickFix), AssistId::quick_fix("remove_unused_imports"),
"Remove all the unused imports", "Remove all the unused imports",
selected_el.text_range(), selected_el.text_range(),
|builder| { |builder| {

View File

@ -11,8 +11,7 @@ use syntax::{
use SyntaxKind::WHITESPACE; use SyntaxKind::WHITESPACE;
use crate::{ use crate::{
AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder, AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder, utils::next_prev,
utils::next_prev,
}; };
// Assist: remove_unused_param // Assist: remove_unused_param
@ -79,7 +78,7 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) ->
} }
let parent = param.syntax().parent()?; let parent = param.syntax().parent()?;
acc.add( acc.add(
AssistId("remove_unused_param", AssistKind::Refactor), AssistId::refactor("remove_unused_param"),
"Remove unused parameter", "Remove unused parameter",
param.syntax().text_range(), param.syntax().text_range(),
|builder| { |builder| {

View File

@ -3,7 +3,7 @@ use ide_db::FxHashMap;
use itertools::Itertools; use itertools::Itertools;
use syntax::{AstNode, SmolStr, SyntaxElement, ToSmolStr, ast, syntax_editor::SyntaxEditor}; use syntax::{AstNode, SmolStr, SyntaxElement, ToSmolStr, ast, syntax_editor::SyntaxEditor};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: reorder_fields // Assist: reorder_fields
// //
@ -67,7 +67,7 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
} }
let target = record.as_ref().either(AstNode::syntax, AstNode::syntax).text_range(); let target = record.as_ref().either(AstNode::syntax, AstNode::syntax).text_range();
acc.add( acc.add(
AssistId("reorder_fields", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("reorder_fields"),
"Reorder record fields", "Reorder record fields",
target, target,
|builder| { |builder| {

View File

@ -6,7 +6,7 @@ use syntax::{
ast::{self, HasName}, ast::{self, HasName},
}; };
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, Assists};
// Assist: reorder_impl_items // Assist: reorder_impl_items
// //
@ -95,7 +95,7 @@ pub(crate) fn reorder_impl_items(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let target = items.syntax().text_range(); let target = items.syntax().text_range();
acc.add( acc.add(
AssistId("reorder_impl_items", AssistKind::RefactorRewrite), AssistId::refactor_rewrite("reorder_impl_items"),
"Sort items by trait definition", "Sort items by trait definition",
target, target,
|builder| { |builder| {

View File

@ -1,4 +1,4 @@
use ide_db::assists::{AssistId, AssistKind, GroupLabel}; use ide_db::assists::{AssistId, GroupLabel};
use syntax::{ use syntax::{
AstNode, TextRange, AstNode, TextRange,
ast::{self, ArithOp, BinaryOp}, ast::{self, ArithOp, BinaryOp},
@ -132,7 +132,7 @@ impl ArithKind {
ArithKind::Wrapping => "replace_arith_with_wrapping", ArithKind::Wrapping => "replace_arith_with_wrapping",
}; };
AssistId(s, AssistKind::RefactorRewrite) AssistId::refactor_rewrite(s)
} }
fn label(&self) -> &'static str { fn label(&self) -> &'static str {

View File

@ -9,7 +9,7 @@ use syntax::{
}; };
use crate::{ use crate::{
AssistId, AssistKind, AssistId,
assist_context::{AssistContext, Assists, SourceChangeBuilder}, assist_context::{AssistContext, Assists, SourceChangeBuilder},
utils::{ utils::{
DefaultMethods, IgnoreAssocItems, add_trait_assoc_items_to_impl, filter_assoc_items, DefaultMethods, IgnoreAssocItems, add_trait_assoc_items_to_impl, filter_assoc_items,
@ -125,101 +125,94 @@ fn add_assist(
let annotated_name = adt.name()?; let annotated_name = adt.name()?;
let label = format!("Convert to manual `impl {replace_trait_path} for {annotated_name}`"); let label = format!("Convert to manual `impl {replace_trait_path} for {annotated_name}`");
acc.add( acc.add(AssistId::refactor("replace_derive_with_manual_impl"), label, target, |builder| {
AssistId("replace_derive_with_manual_impl", AssistKind::Refactor), let insert_after = ted::Position::after(builder.make_mut(adt.clone()).syntax());
label, let impl_is_unsafe = trait_.map(|s| s.is_unsafe(ctx.db())).unwrap_or(false);
target, let impl_def_with_items =
|builder| { impl_def_from_trait(&ctx.sema, adt, &annotated_name, trait_, replace_trait_path);
let insert_after = ted::Position::after(builder.make_mut(adt.clone()).syntax()); update_attribute(builder, old_derives, old_tree, old_trait_path, attr);
let impl_is_unsafe = trait_.map(|s| s.is_unsafe(ctx.db())).unwrap_or(false);
let impl_def_with_items =
impl_def_from_trait(&ctx.sema, adt, &annotated_name, trait_, replace_trait_path);
update_attribute(builder, old_derives, old_tree, old_trait_path, attr);
let trait_path = make::ty_path(replace_trait_path.clone()); let trait_path = make::ty_path(replace_trait_path.clone());
match (ctx.config.snippet_cap, impl_def_with_items) { match (ctx.config.snippet_cap, impl_def_with_items) {
(None, None) => { (None, None) => {
let impl_def = generate_trait_impl(adt, trait_path); let impl_def = generate_trait_impl(adt, trait_path);
if impl_is_unsafe { if impl_is_unsafe {
ted::insert( ted::insert(
Position::first_child_of(impl_def.syntax()), Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]), make::token(T![unsafe]),
);
}
ted::insert_all(
insert_after,
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
); );
} }
(None, Some((impl_def, _))) => {
if impl_is_unsafe { ted::insert_all(
ted::insert( insert_after,
Position::first_child_of(impl_def.syntax()), vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
make::token(T![unsafe]), );
); }
} (None, Some((impl_def, _))) => {
ted::insert_all( if impl_is_unsafe {
insert_after, ted::insert(
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()], Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]),
); );
} }
(Some(cap), None) => { ted::insert_all(
let impl_def = generate_trait_impl(adt, trait_path); insert_after,
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
);
}
(Some(cap), None) => {
let impl_def = generate_trait_impl(adt, trait_path);
if impl_is_unsafe { if impl_is_unsafe {
ted::insert( ted::insert(
Position::first_child_of(impl_def.syntax()), Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]), make::token(T![unsafe]),
);
}
if let Some(l_curly) =
impl_def.assoc_item_list().and_then(|it| it.l_curly_token())
{
builder.add_tabstop_after_token(cap, l_curly);
}
ted::insert_all(
insert_after,
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
); );
} }
(Some(cap), Some((impl_def, first_assoc_item))) => {
let mut added_snippet = false;
if impl_is_unsafe { if let Some(l_curly) = impl_def.assoc_item_list().and_then(|it| it.l_curly_token())
ted::insert( {
Position::first_child_of(impl_def.syntax()), builder.add_tabstop_after_token(cap, l_curly);
make::token(T![unsafe]), }
);
}
if let ast::AssocItem::Fn(ref func) = first_assoc_item { ted::insert_all(
if let Some(m) = func.syntax().descendants().find_map(ast::MacroCall::cast) insert_after,
{ vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
if m.syntax().text() == "todo!()" { );
// Make the `todo!()` a placeholder }
builder.add_placeholder_snippet(cap, m); (Some(cap), Some((impl_def, first_assoc_item))) => {
added_snippet = true; let mut added_snippet = false;
}
if impl_is_unsafe {
ted::insert(
Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]),
);
}
if let ast::AssocItem::Fn(ref func) = first_assoc_item {
if let Some(m) = func.syntax().descendants().find_map(ast::MacroCall::cast) {
if m.syntax().text() == "todo!()" {
// Make the `todo!()` a placeholder
builder.add_placeholder_snippet(cap, m);
added_snippet = true;
} }
} }
if !added_snippet {
// If we haven't already added a snippet, add a tabstop before the generated function
builder.add_tabstop_before(cap, first_assoc_item);
}
ted::insert_all(
insert_after,
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
);
} }
};
}, if !added_snippet {
) // If we haven't already added a snippet, add a tabstop before the generated function
builder.add_tabstop_before(cap, first_assoc_item);
}
ted::insert_all(
insert_after,
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
);
}
};
})
} }
fn impl_def_from_trait( fn impl_def_from_trait(

Some files were not shown because too many files have changed in this diff Show More