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},
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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)?;
acc.add(
AssistId("add_braces", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("add_braces"),
match expr_type {
ParentType::ClosureExpr => "Add braces to closure body",
ParentType::MatchArmExpr => "Add braces to arm expression",

View File

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

View File

@ -2,7 +2,7 @@ use hir::HirDisplay;
use ide_db::syntax_helpers::node_ext::walk_ty;
use syntax::ast::{self, AstNode, LetStmt, Param};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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()?;
acc.add(
AssistId("add_explicit_type", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("add_explicit_type"),
format!("Insert explicit type `{inferred_type}`"),
pat_range,
|builder| match ascribed_ty {

View File

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

View File

@ -1,6 +1,6 @@
use syntax::ast::{self, AstNode, HasGenericParams, HasName};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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 target = node.syntax().text_range();
acc.add(
AssistId("add_lifetime_to_type", AssistKind::Generate),
"Add lifetime",
target,
|builder| {
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>");
}
acc.add(AssistId::generate("add_lifetime_to_type"), "Add lifetime", target, |builder| {
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>");
}
}
}
for ref_type in ref_types {
if let Some(amp_token) = ref_type.amp_token() {
builder.insert(amp_token.text_range().end(), "'a ");
}
for ref_type in ref_types {
if let Some(amp_token) = ref_type.amp_token() {
builder.insert(amp_token.text_range().end(), "'a ");
}
},
)
}
})
}
fn fetch_borrowed_types(node: &ast::Adt) -> Option<Vec<ast::RefType>> {

View File

@ -5,7 +5,7 @@ use syntax::{
};
use crate::{
AssistId, AssistKind,
AssistId,
assist_context::{AssistContext, Assists},
utils::{
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();
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 first_new_item = add_trait_assoc_items_to_impl(
&ctx.sema,

View File

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

View File

@ -1,7 +1,7 @@
use hir::HirDisplay;
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
//
@ -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()?;
acc.add(
AssistId("add_return_type", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("add_return_type"),
match fn_type {
FnType::Function => "Add this function's return type",
FnType::Closure { .. } => "Add this closure's return type",

View File

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

View File

@ -17,7 +17,7 @@ use syntax::{
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
//
@ -107,7 +107,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
acc.add_group(
&GroupLabel("Apply De Morgan's law".to_owned()),
AssistId("apply_demorgan", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("apply_demorgan"),
"Apply De Morgan's law",
op_range,
|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());
acc.add_group(
&GroupLabel("Apply De Morgan's law".to_owned()),
AssistId("apply_demorgan_iterator", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("apply_demorgan_iterator"),
label,
op_range,
|builder| {

View File

@ -10,7 +10,7 @@ use ide_db::{
};
use syntax::{AstNode, Edition, NodeOrToken, SyntaxElement, ast};
use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
use crate::{AssistContext, AssistId, Assists, GroupLabel};
// 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 (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(
&group_label,
assist_id,

View File

@ -1,9 +1,5 @@
use crate::assist_context::{AssistContext, Assists};
use ide_db::{
LineIndexDatabase,
assists::{AssistId, AssistKind},
defs::Definition,
};
use ide_db::{LineIndexDatabase, assists::AssistId, defs::Definition};
use syntax::{
AstNode,
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();
acc.add(
AssistId("bind_unused_param", AssistKind::QuickFix),
AssistId::quick_fix("bind_unused_param"),
format!("Bind as `let _ = {ident_pat};`"),
param.syntax().text_range(),
|builder| {

View File

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

View File

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

View File

@ -3,7 +3,7 @@ use hir::ModuleDef;
use ide_db::text_edit::TextRange;
use ide_db::{
FxHashSet,
assists::{AssistId, AssistKind},
assists::AssistId,
defs::Definition,
helpers::mod_path_to_ast,
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();
acc.add(
AssistId("convert_bool_to_enum", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("convert_bool_to_enum"),
"Convert boolean to enum",
target,
|edit| {

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@ use syntax::{
syntax_editor::Position,
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// Assist: convert_for_loop_to_while_let
//
@ -47,7 +47,7 @@ pub(crate) fn convert_for_loop_to_while_let(
}
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`",
for_loop.syntax().text_range(),
|builder| {

View File

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

View File

@ -1,6 +1,6 @@
use syntax::{AstToken, ast, ast::Radix};
use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
use crate::{AssistContext, AssistId, Assists, GroupLabel};
// Assist: convert_integer_literal
//
@ -47,7 +47,7 @@ pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext<'_>
acc.add_group(
&group_id,
AssistId("convert_integer_literal", AssistKind::RefactorInline),
AssistId::refactor_rewrite("convert_integer_literal"),
label,
range,
|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 syntax::ast::{self, AstNode, HasGenericArgs, HasName};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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");
acc.add(
AssistId("convert_into_to_from", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("convert_into_to_from"),
"Convert Into to From",
impl_.syntax().text_range(),
|builder| {

View File

@ -6,7 +6,7 @@ use syntax::{
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
//
@ -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();
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",
range,
|builder| {
@ -108,7 +108,7 @@ pub(crate) fn convert_for_loop_with_for_each(
}
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`",
for_loop.syntax().text_range(),
|builder| {

View File

@ -4,7 +4,7 @@ use syntax::T;
use syntax::ast::RangeItem;
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
//
@ -43,7 +43,7 @@ pub(crate) fn convert_let_else_to_match(acc: &mut Assists, ctx: &AssistContext<'
let target = let_stmt.syntax().text_range();
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",
target,
|edit| {

View File

@ -6,7 +6,7 @@ use syntax::{
};
use crate::{
AssistId, AssistKind,
AssistId,
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)?;
acc.add(
AssistId("convert_match_to_let_else", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("convert_match_to_let_else"),
"Convert match to let-else",
let_stmt.syntax().text_range(),
|builder| {

View File

@ -7,7 +7,7 @@ use syntax::{
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
//
@ -69,7 +69,7 @@ pub(crate) fn convert_named_struct_to_tuple_struct(
};
acc.add(
AssistId("convert_named_struct_to_tuple_struct", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("convert_named_struct_to_tuple_struct"),
"Convert to tuple struct",
strukt.syntax().text_range(),
|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::{AstNode, SyntaxKind};
@ -44,7 +44,7 @@ pub(crate) fn convert_nested_function_to_closure(
let param_list = function.param_list()?;
acc.add(
AssistId("convert_nested_function_to_closure", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("convert_nested_function_to_closure"),
"Convert nested function to closure",
target,
|edit| {

View File

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

View File

@ -2,7 +2,7 @@ use either::Either;
use hir::ModuleDef;
use ide_db::{
FxHashSet,
assists::{AssistId, AssistKind},
assists::AssistId,
defs::Definition,
helpers::mod_path_to_ast,
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();
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",
target,
move |edit| {

View File

@ -6,7 +6,7 @@ use syntax::{
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
//
@ -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();
acc.add(
AssistId("convert_tuple_struct_to_named_struct", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("convert_tuple_struct_to_named_struct"),
"Convert to named struct",
target,
|edit| {

View File

@ -3,7 +3,7 @@ use ide_db::RootDatabase;
use stdx::format_to;
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
//
@ -56,7 +56,7 @@ pub(crate) fn convert_two_arm_bool_match_to_matches_macro(
let expr = match_expr.expr()?;
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!",
target_range,
|builder| {

View File

@ -12,7 +12,7 @@ use syntax::{
};
use crate::{
AssistId, AssistKind,
AssistId,
assist_context::{AssistContext, Assists},
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();
acc.add(
AssistId("convert_while_to_loop", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("convert_while_to_loop"),
"Convert while to loop",
target,
|edit| {

View File

@ -2,7 +2,7 @@ use hir::{HasVisibility, sym};
use ide_db::text_edit::TextRange;
use ide_db::{
FxHashMap, FxHashSet,
assists::{AssistId, AssistKind},
assists::AssistId,
defs::Definition,
helpers::mod_path_to_ast,
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)?;
acc.add(
AssistId("destructure_struct_binding", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("destructure_struct_binding"),
"Destructure struct binding",
data.ident_pat.syntax().text_range(),
|edit| destructure_struct_binding_impl(ctx, edit, &data),

View File

@ -1,5 +1,5 @@
use ide_db::{
assists::{AssistId, AssistKind},
assists::AssistId,
defs::Definition,
search::{FileReference, SearchScope},
syntax_helpers::suggest_name,
@ -65,7 +65,7 @@ pub(crate) fn destructure_tuple_binding_impl(
if with_sub_pattern {
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",
data.ident_pat.syntax().text_range(),
|edit| destructure_tuple_edit_impl(ctx, edit, &data, true),
@ -73,7 +73,7 @@ pub(crate) fn destructure_tuple_binding_impl(
}
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" },
data.ident_pat.syntax().text_range(),
|edit| destructure_tuple_edit_impl(ctx, edit, &data, false),

View File

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

View File

@ -13,7 +13,7 @@ use syntax::{
};
use crate::{
AssistId, AssistKind,
AssistId,
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());
acc.add(
AssistId("expand_glob_import", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("expand_glob_import"),
"Expand glob import",
target.text_range(),
|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());
acc.add(
AssistId("expand_glob_reexport", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("expand_glob_reexport"),
"Expand glob reexport",
target.text_range(),
|builder| {

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ use hir::{HasSource, HirFileIdExt, ModuleSource};
use ide_db::base_db::salsa::AsDynDatabase;
use ide_db::{
FileId, FxHashMap, FxHashSet,
assists::{AssistId, AssistKind},
assists::AssistId,
defs::{Definition, NameClass, NameRefClass},
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();
acc.add(
AssistId("extract_module", AssistKind::RefactorExtract),
AssistId::refactor_extract("extract_module"),
"Extract Module",
module.text_range,
|builder| {

View File

@ -22,7 +22,7 @@ use syntax::{
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
//
@ -55,7 +55,7 @@ pub(crate) fn extract_struct_from_enum_variant(
let enum_hir = ctx.sema.to_def(&enum_ast)?;
let target = variant.syntax().text_range();
acc.add(
AssistId("extract_struct_from_enum_variant", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("extract_struct_from_enum_variant"),
"Extract struct from enum variant",
target,
|builder| {

View File

@ -5,7 +5,7 @@ use syntax::{
syntax_editor,
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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();
acc.add(
AssistId("extract_type_alias", AssistKind::RefactorExtract),
AssistId::refactor_extract("extract_type_alias"),
"Extract type as type alias",
target,
|builder| {

View File

@ -13,7 +13,7 @@ use syntax::{
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
//
@ -311,7 +311,7 @@ impl ExtractionKind {
ExtractionKind::Static => "extract_static",
};
AssistId(s, AssistKind::RefactorExtract)
AssistId::refactor_extract(s)
}
fn label(&self) -> &'static str {

View File

@ -7,7 +7,7 @@ use syntax::{
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.
@ -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);
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)
);
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());
let vis_owner = edit.make_mut(vis_owner);

View File

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

View File

@ -5,7 +5,7 @@ use syntax::{
syntax_editor::SyntaxMapping,
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// Assist: flip_comma
//
@ -40,7 +40,7 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
}
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 mut editor = builder.make_editor(&parent);

View File

@ -4,7 +4,7 @@ use syntax::{
ast::{self, AstNode},
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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 target = pipe.text_range();
acc.add(
AssistId("flip_or_pattern", AssistKind::RefactorRewrite),
"Flip patterns",
target,
|builder| {
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);
},
)
acc.add(AssistId::refactor_rewrite("flip_or_pattern"), "Flip patterns", target, |builder| {
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)]

View File

@ -4,7 +4,7 @@ use syntax::{
ast::{self, AstNode},
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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();
acc.add(
AssistId("flip_trait_bound", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("flip_trait_bound"),
"Flip trait bounds",
target,
|builder| {

View File

@ -2,7 +2,7 @@ use crate::assist_context::{AssistContext, Assists};
use hir::{HasVisibility, HirDisplay, HirFileIdExt, Module};
use ide_db::{
FileId,
assists::{AssistId, AssistKind},
assists::AssistId,
base_db::Upcast,
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)?;
acc.add(
AssistId("generate_constant", AssistKind::QuickFix),
"Generate constant",
target,
|builder| {
if let Some(file_id) = file_id {
builder.edit_file(file_id);
}
builder.insert(offset, format!("{text}{post_string}"));
},
)
acc.add(AssistId::quick_fix("generate_constant"), "Generate constant", target, |builder| {
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(

View File

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

View File

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

View File

@ -3,7 +3,7 @@ use syntax::{
ast::{self, AstNode, HasAttrs, edit_in_place::AttrsOwnerEdit, make},
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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()?),
};
acc.add(AssistId("generate_derive", AssistKind::Generate), "Add `#[derive]`", target, |edit| {
acc.add(AssistId::generate("generate_derive"), "Add `#[derive]`", target, |edit| {
match derive_attr {
None => {
let derive = make::attr_outer(make::meta_token_tree(

View File

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

View File

@ -4,7 +4,7 @@ use syntax::ast::HasVisibility;
use syntax::ast::{self, AstNode, HasName};
use crate::{
AssistContext, AssistId, AssistKind, Assists,
AssistContext, AssistId, Assists,
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();
acc.add_group(
&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",
target,
|builder| {

View File

@ -5,7 +5,7 @@ use syntax::ast::HasVisibility;
use syntax::ast::{self, AstNode, HasName};
use crate::{
AssistContext, AssistId, AssistKind, Assists,
AssistContext, AssistId, Assists,
utils::{add_method_to_adt, find_struct_impl},
};
@ -153,7 +153,7 @@ fn generate_enum_projection_method(
let target = variant.syntax().text_range();
acc.add_group(
&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,
target,
|builder| {

View File

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

View File

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

View File

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

View File

@ -23,7 +23,7 @@ use syntax::{
};
use crate::{
AssistContext, AssistId, AssistKind, Assists,
AssistContext, AssistId, Assists,
utils::{convert_reference_type, find_struct_impl},
};
@ -173,7 +173,7 @@ fn add_func_to_accumulator(
adt_info: Option<AdtInfo>,
label: String,
) -> 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);
let target = function_builder.target.clone();

View File

@ -7,7 +7,7 @@ use syntax::{
};
use crate::{
AssistContext, AssistId, AssistKind, Assists, GroupLabel,
AssistContext, AssistId, Assists, GroupLabel,
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(
&GroupLabel("Generate getter/setter".to_owned()),
AssistId("generate_setter", AssistKind::Generate),
AssistId::generate("generate_setter"),
"Generate a setter method",
target,
|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(
&GroupLabel("Generate getter/setter".to_owned()),
AssistId(id, AssistKind::Generate),
AssistId::generate(id),
label,
target,
|builder| build_source_change(builder, ctx, info_of_record_fields, getter_info),

View File

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

View File

@ -5,7 +5,7 @@ use syntax::{
};
use crate::{
AssistId, AssistKind,
AssistId,
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();
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",
range,
|builder| {

View File

@ -5,7 +5,7 @@ use syntax::{
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].
// 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();
acc.add(
AssistId("generate_mut_trait_impl", AssistKind::Generate),
AssistId::generate("generate_mut_trait_impl"),
"Generate `IndexMut` impl from this `Index` trait",
target,
|edit| {

View File

@ -7,7 +7,7 @@ use syntax::{
};
use crate::{
AssistContext, AssistId, AssistKind, Assists,
AssistContext, AssistId, Assists,
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 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
.fields()
.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()?;
acc.add(
AssistId("generate_trait_from_impl", ide_db::assists::AssistKind::Generate),
AssistId::generate("generate_trait_from_impl"),
"Generate trait from impl",
impl_ast.syntax().text_range(),
|builder| {

View File

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

View File

@ -1,7 +1,7 @@
use hir::HasCrate;
use syntax::{AstNode, ast};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// Assist: inline_const_as_literal
//
@ -44,7 +44,7 @@ pub(crate) fn inline_const_as_literal(acc: &mut Assists, ctx: &AssistContext<'_>
.ok()?
.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 target = variable.syntax().text_range();

View File

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

View File

@ -2,7 +2,7 @@ use hir::db::ExpandDatabase;
use ide_db::syntax_helpers::prettify_macro_expansion;
use syntax::ast::{self, AstNode};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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();
acc.add(
AssistId("inline_macro", AssistKind::RefactorInline),
AssistId::refactor_inline("inline_macro"),
"Inline macro".to_owned(),
text_range,
|builder| {

View File

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

View File

@ -1,8 +1,5 @@
use hir::{AsAssocItem, HirDisplay};
use ide_db::{
assists::{AssistId, AssistKind},
famous_defs::FamousDefs,
};
use ide_db::{assists::AssistId, famous_defs::FamousDefs};
use syntax::{AstNode, ast};
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()?;
acc.add(
AssistId("into_to_qualified_from", AssistKind::Generate),
AssistId::generate("into_to_qualified_from"),
"Convert `into` to fully qualified `from`",
nameref.syntax().text_range(),
|edit| {

View File

@ -5,7 +5,7 @@ use syntax::{
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_LABEL: &str = "Introduce named lifetime";
@ -83,7 +83,7 @@ fn generate_fn_def_assist(
_ => 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 lifetime = builder.make_mut(lifetime);
let loc_needing_lifetime =
@ -107,7 +107,7 @@ fn generate_impl_def_assist(
lifetime: ast::Lifetime,
) -> Option<()> {
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 lifetime = builder.make_mut(lifetime);

View File

@ -2,7 +2,7 @@ use ide_db::syntax_helpers::suggest_name;
use itertools::Itertools;
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
//
@ -27,7 +27,7 @@ pub(crate) fn introduce_named_type_parameter(
let make = SyntaxFactory::new();
let target = fn_.syntax().text_range();
acc.add(
AssistId("introduce_named_type_parameter", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("introduce_named_type_parameter"),
"Replace impl trait with type parameter",
target,
|builder| {

View File

@ -5,7 +5,7 @@ use syntax::{
};
use crate::{
AssistId, AssistKind,
AssistId,
assist_context::{AssistContext, Assists},
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,
};
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());
edit.replace_ast(cond, flip_cond);

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ use syntax::{
match_ast,
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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();
acc.add(
AssistId("move_bounds_to_where_clause", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("move_bounds_to_where_clause"),
"Move to where clause",
target,
|edit| {

View File

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

View File

@ -1,7 +1,4 @@
use ide_db::{
assists::{AssistId, AssistKind},
base_db::AnchoredPathBuf,
};
use ide_db::{assists::AssistId, base_db::AnchoredPathBuf};
use syntax::{AstNode, ToSmolStr, ast};
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 dst = AnchoredPathBuf { anchor: ctx.file_id().into(), path };
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"),
target,
|builder| {

View File

@ -3,7 +3,7 @@ use syntax::{
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
//
@ -49,7 +49,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext<'_>)
let target = guard.syntax().text_range();
acc.add(
AssistId("move_guard_to_arm_body", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("move_guard_to_arm_body"),
"Move guard to arm body",
target,
|edit| {
@ -118,7 +118,7 @@ pub(crate) fn move_arm_cond_to_match_guard(
let (conds_blocks, tail) = parse_if_chain(if_expr)?;
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",
replace_node.text_range(),
|edit| {

View File

@ -10,7 +10,7 @@ use syntax::{
ast::{self, HasName, edit::AstNodeEdit},
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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())?;
acc.add(
AssistId("move_module_to_file", AssistKind::RefactorExtract),
AssistId::refactor_extract("move_module_to_file"),
"Extract module to file",
target,
|builder| {

View File

@ -1,7 +1,4 @@
use ide_db::{
assists::{AssistId, AssistKind},
base_db::AnchoredPathBuf,
};
use ide_db::{assists::AssistId, base_db::AnchoredPathBuf};
use syntax::{AstNode, ToSmolStr, ast};
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 dst = AnchoredPathBuf { anchor: ctx.file_id().into(), path };
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"),
target,
|builder| {

View File

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

View File

@ -1,6 +1,6 @@
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;
@ -42,7 +42,7 @@ pub(crate) fn reformat_number_literal(acc: &mut Assists, ctx: &AssistContext<'_>
let range = literal.syntax().text_range();
acc.add_group(
&group_id,
AssistId("reformat_number_literal", AssistKind::RefactorInline),
AssistId::refactor_inline("reformat_number_literal"),
label,
range,
|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();
acc.add_group(
&group_id,
AssistId("reformat_number_literal", AssistKind::RefactorInline),
AssistId::refactor_inline("reformat_number_literal"),
"Remove digit separators",
range,
|builder| builder.replace(range, literal.text().replace('_', "")),

View File

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

View File

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

View File

@ -1,5 +1,5 @@
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 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);
acc.add(
AssistId("qualify_method_call", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("qualify_method_call"),
format!("Qualify `{ident}` method call"),
range,
|builder| {

View File

@ -15,7 +15,7 @@ use syntax::{
};
use crate::{
AssistId, AssistKind, GroupLabel,
AssistId, GroupLabel,
assist_context::{AssistContext, Assists},
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 {
acc.add_group(
&group_label,
AssistId("qualify_path", AssistKind::QuickFix),
AssistId::quick_fix("qualify_path"),
label(ctx.db(), candidate, &import, current_edition),
range,
|builder| {

View File

@ -2,7 +2,7 @@ use std::borrow::Cow;
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
//
@ -28,7 +28,7 @@ pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
let value = token.value().ok()?;
let target = token.syntax().text_range();
acc.add(
AssistId("make_raw_string", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("make_raw_string"),
"Rewrite as raw string",
target,
|edit| {
@ -67,7 +67,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
let value = token.value().ok()?;
let target = token.syntax().text_range();
acc.add(
AssistId("make_usual_string", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("make_usual_string"),
"Rewrite as regular string",
target,
|edit| {
@ -108,7 +108,7 @@ pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()>
}
let text_range = token.syntax().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.end(), "#");
})
@ -150,7 +150,7 @@ pub(crate) fn remove_hash(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
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::new(text_range.end() - TextSize::of('#'), text_range.end()));
})

View File

@ -5,7 +5,7 @@ use syntax::{
match_ast, ted,
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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<_>>();
acc.add(
AssistId("remove_dbg", AssistKind::QuickFix),
AssistId::quick_fix("remove_dbg"),
"Remove dbg!()",
replacements.iter().map(|&(range, _)| range).reduce(|acc, range| acc.cover(range))?,
|builder| {

View File

@ -1,6 +1,6 @@
use syntax::{SyntaxKind, T};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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 target = mut_token.text_range();
acc.add(
AssistId("remove_mut", AssistKind::Refactor),
"Remove `mut` keyword",
target,
|builder| {
let mut editor = builder.make_editor(&mut_token.parent().unwrap());
match mut_token.next_token() {
Some(it) if it.kind() == SyntaxKind::WHITESPACE => editor.delete(it),
_ => (),
}
editor.delete(mut_token);
builder.add_file_edits(ctx.file_id(), editor);
},
)
acc.add(AssistId::refactor("remove_mut"), "Remove `mut` keyword", target, |builder| {
let mut editor = builder.make_editor(&mut_token.parent().unwrap());
match mut_token.next_token() {
Some(it) if it.kind() == SyntaxKind::WHITESPACE => editor.delete(it),
_ => (),
}
editor.delete(mut_token);
builder.add_file_edits(ctx.file_id(), editor);
})
}

View File

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

View File

@ -12,7 +12,7 @@ use syntax::{
ast::{self, Rename},
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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.
if unused.peek().is_some() {
acc.add(
AssistId("remove_unused_imports", AssistKind::QuickFix),
AssistId::quick_fix("remove_unused_imports"),
"Remove all the unused imports",
selected_el.text_range(),
|builder| {

View File

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

View File

@ -3,7 +3,7 @@ use ide_db::FxHashMap;
use itertools::Itertools;
use syntax::{AstNode, SmolStr, SyntaxElement, ToSmolStr, ast, syntax_editor::SyntaxEditor};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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();
acc.add(
AssistId("reorder_fields", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("reorder_fields"),
"Reorder record fields",
target,
|builder| {

View File

@ -6,7 +6,7 @@ use syntax::{
ast::{self, HasName},
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{AssistContext, AssistId, Assists};
// 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();
acc.add(
AssistId("reorder_impl_items", AssistKind::RefactorRewrite),
AssistId::refactor_rewrite("reorder_impl_items"),
"Sort items by trait definition",
target,
|builder| {

View File

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

View File

@ -9,7 +9,7 @@ use syntax::{
};
use crate::{
AssistId, AssistKind,
AssistId,
assist_context::{AssistContext, Assists, SourceChangeBuilder},
utils::{
DefaultMethods, IgnoreAssocItems, add_trait_assoc_items_to_impl, filter_assoc_items,
@ -125,101 +125,94 @@ fn add_assist(
let annotated_name = adt.name()?;
let label = format!("Convert to manual `impl {replace_trait_path} for {annotated_name}`");
acc.add(
AssistId("replace_derive_with_manual_impl", AssistKind::Refactor),
label,
target,
|builder| {
let insert_after = ted::Position::after(builder.make_mut(adt.clone()).syntax());
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);
acc.add(AssistId::refactor("replace_derive_with_manual_impl"), label, target, |builder| {
let insert_after = ted::Position::after(builder.make_mut(adt.clone()).syntax());
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) {
(None, None) => {
let impl_def = generate_trait_impl(adt, trait_path);
if impl_is_unsafe {
ted::insert(
Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]),
);
}
ted::insert_all(
insert_after,
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
match (ctx.config.snippet_cap, impl_def_with_items) {
(None, None) => {
let impl_def = generate_trait_impl(adt, trait_path);
if impl_is_unsafe {
ted::insert(
Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]),
);
}
(None, Some((impl_def, _))) => {
if impl_is_unsafe {
ted::insert(
Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]),
);
}
ted::insert_all(
insert_after,
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
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(
Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]),
);
}
(Some(cap), None) => {
let impl_def = generate_trait_impl(adt, trait_path);
ted::insert_all(
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 {
ted::insert(
Position::first_child_of(impl_def.syntax()),
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()],
if impl_is_unsafe {
ted::insert(
Position::first_child_of(impl_def.syntax()),
make::token(T![unsafe]),
);
}
(Some(cap), Some((impl_def, first_assoc_item))) => {
let mut added_snippet = false;
if impl_is_unsafe {
ted::insert(
Position::first_child_of(impl_def.syntax()),
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);
}
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;
}
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 {
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(

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