Move AssistKind into AssistId

This commit is contained in:
kjeremy 2020-07-02 17:48:35 -04:00
parent 1d58e16824
commit 36cc81ac71
41 changed files with 89 additions and 139 deletions

View File

@ -19,7 +19,7 @@
use crate::{
assist_config::{AssistConfig, SnippetCap},
Assist, AssistId, AssistKind, GroupLabel, ResolvedAssist,
Assist, AssistId, GroupLabel, ResolvedAssist,
};
/// `AssistContext` allows to apply an assist or check if it could be applied.
@ -135,24 +135,22 @@ pub(crate) fn finish_resolved(self) -> Vec<ResolvedAssist> {
pub(crate) fn add(
&mut self,
id: AssistId,
kind: AssistKind,
label: impl Into<String>,
target: TextRange,
f: impl FnOnce(&mut AssistBuilder),
) -> Option<()> {
let label = Assist::new(id, kind, label.into(), None, target);
let label = Assist::new(id, label.into(), None, target);
self.add_impl(label, f)
}
pub(crate) fn add_group(
&mut self,
group: &GroupLabel,
id: AssistId,
kind: AssistKind,
label: impl Into<String>,
target: TextRange,
f: impl FnOnce(&mut AssistBuilder),
) -> Option<()> {
let label = Assist::new(id, kind, label.into(), Some(group.clone()), target);
let label = Assist::new(id, label.into(), Some(group.clone()), target);
self.add_impl(label, f)
}
fn add_impl(&mut self, label: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> {

View File

@ -52,7 +52,7 @@ pub(crate) fn add_custom_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<
format!("Add custom impl `{}` for `{}`", trait_token.text().as_str(), annotated_name);
let target = attr.syntax().text_range();
acc.add(AssistId("add_custom_impl"), AssistKind::Refactor, label, target, |builder| {
acc.add(AssistId("add_custom_impl", AssistKind::Refactor), label, target, |builder| {
let new_attr_input = input
.syntax()
.descendants_with_tokens()

View File

@ -29,7 +29,7 @@ pub(crate) fn add_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
let node_start = derive_insertion_offset(&nominal)?;
let target = nominal.syntax().text_range();
acc.add(AssistId("add_derive"), AssistKind::Refactor, "Add `#[derive]`", target, |builder| {
acc.add(AssistId("add_derive", AssistKind::Refactor), "Add `#[derive]`", target, |builder| {
let derive_attr = nominal
.attrs()
.filter_map(|x| x.as_simple_call())

View File

@ -59,8 +59,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
let inferred_type = ty.display_source_code(ctx.db(), module.into()).ok()?;
acc.add(
AssistId("add_explicit_type"),
AssistKind::RefactorRewrite,
AssistId("add_explicit_type", AssistKind::RefactorRewrite),
format!("Insert explicit type `{}`", inferred_type),
pat_range,
|builder| match ascribed_ty {

View File

@ -45,8 +45,7 @@ pub(crate) fn add_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) ->
let target = variant.syntax().text_range();
acc.add(
AssistId("add_from_impl_for_enum"),
AssistKind::Refactor,
AssistId("add_from_impl_for_enum", AssistKind::Refactor),
"Add From impl for this enum variant",
target,
|edit| {

View File

@ -63,8 +63,7 @@ pub(crate) fn add_function(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
let target = call.syntax().text_range();
acc.add(
AssistId("add_function"),
AssistKind::RefactorExtract,
AssistId("add_function", AssistKind::RefactorExtract),
"Add function",
target,
|builder| {

View File

@ -27,8 +27,7 @@ pub(crate) fn add_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let name = nominal.name()?;
let target = nominal.syntax().text_range();
acc.add(
AssistId("add_impl"),
AssistKind::Refactor,
AssistId("add_impl", AssistKind::Refactor),
format!("Implement {}", name.text().as_str()),
target,
|edit| {

View File

@ -147,7 +147,7 @@ fn add_missing_impl_members_inner(
}
let target = impl_def.syntax().text_range();
acc.add(AssistId(assist_id), AssistKind::QuickFix, label, target, |builder| {
acc.add(AssistId(assist_id, AssistKind::QuickFix), label, target, |builder| {
let n_existing_items = impl_item_list.assoc_items().count();
let source_scope = ctx.sema.scope_for_def(trait_);
let target_scope = ctx.sema.scope(impl_item_list.syntax());

View File

@ -43,8 +43,7 @@ pub(crate) fn add_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let target = strukt.syntax().text_range();
acc.add(
AssistId("add_new"),
AssistKind::Refactor,
AssistId("add_new", AssistKind::Refactor),
"Add default constructor",
target,
|builder| {

View File

@ -46,8 +46,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
return None;
}
acc.add(
AssistId("add_turbo_fish"),
AssistKind::RefactorRewrite,
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
"Add `::<>`",
ident.text_range(),
|builder| match ctx.config.snippet_cap {

View File

@ -40,8 +40,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<(
let not_rhs = invert_boolean_expression(rhs);
acc.add(
AssistId("apply_demorgan"),
AssistKind::RefactorRewrite,
AssistId("apply_demorgan", AssistKind::RefactorRewrite),
"Apply De Morgan's law",
op_range,
|edit| {

View File

@ -48,8 +48,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
for import in proposed_imports {
acc.add_group(
&group,
AssistId("auto_import"),
AssistKind::QuickFix,
AssistId("auto_import", AssistKind::QuickFix),
format!("Import `{}`", &import),
range,
|builder| {

View File

@ -35,8 +35,7 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex
let block_expr = &fn_def.body()?;
acc.add(
AssistId("change_return_type_to_result"),
AssistKind::RefactorRewrite,
AssistId("change_return_type_to_result", AssistKind::RefactorRewrite),
"Change return type to Result",
type_ref.syntax().text_range(),
|builder| {

View File

@ -63,8 +63,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
};
acc.add(
AssistId("change_visibility"),
AssistKind::RefactorRewrite,
AssistId("change_visibility", AssistKind::RefactorRewrite),
"Change visibility to pub(crate)",
target,
|edit| {
@ -77,8 +76,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("change_visibility", AssistKind::RefactorRewrite),
"Change Visibility to pub(crate)",
target,
|edit| {
@ -89,8 +87,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("change_visibility", AssistKind::RefactorRewrite),
"Change visibility to pub",
target,
|edit| {

View File

@ -100,8 +100,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
let target = if_expr.syntax().text_range();
acc.add(
AssistId("convert_to_guarded_return"),
AssistKind::RefactorRewrite,
AssistId("convert_to_guarded_return", AssistKind::RefactorRewrite),
"Convert to guarded return",
target,
|edit| {

View File

@ -49,8 +49,7 @@ pub(crate) fn extract_struct_from_enum_variant(
let current_module = enum_hir.module(ctx.db());
let target = variant.syntax().text_range();
acc.add(
AssistId("extract_struct_from_enum_variant"),
AssistKind::RefactorRewrite,
AssistId("extract_struct_from_enum_variant", AssistKind::RefactorRewrite),
"Extract struct from enum variant",
target,
|builder| {

View File

@ -44,8 +44,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
}
let target = expr.syntax().text_range();
acc.add(
AssistId("extract_variable"),
AssistKind::RefactorExtract,
AssistId("extract_variable", AssistKind::RefactorExtract),
"Extract into variable",
target,
move |edit| {

View File

@ -104,8 +104,7 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<
let target = match_expr.syntax().text_range();
acc.add(
AssistId("fill_match_arms"),
AssistKind::QuickFix,
AssistId("fill_match_arms", AssistKind::QuickFix),
"Fill match arms",
target,
|builder| {

View File

@ -58,7 +58,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O
Some(name) => format!("Change visibility of {} to {}", name, missing_visibility),
};
acc.add(AssistId("fix_visibility"), AssistKind::QuickFix, assist_label, target, |builder| {
acc.add(AssistId("fix_visibility", AssistKind::QuickFix), assist_label, target, |builder| {
builder.edit_file(target_file);
match ctx.config.snippet_cap {
Some(cap) => builder.insert_snippet(cap, offset, format!("$0{} ", missing_visibility)),
@ -101,7 +101,7 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) ->
let assist_label =
format!("Change visibility of {}.{} to {}", parent_name, target_name, missing_visibility);
acc.add(AssistId("fix_visibility"), AssistKind::QuickFix, assist_label, target, |builder| {
acc.add(AssistId("fix_visibility", AssistKind::QuickFix), assist_label, target, |builder| {
builder.edit_file(target_file);
match ctx.config.snippet_cap {
Some(cap) => builder.insert_snippet(cap, offset, format!("$0{} ", missing_visibility)),

View File

@ -34,8 +34,7 @@ pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
}
acc.add(
AssistId("flip_binexpr"),
AssistKind::RefactorRewrite,
AssistId("flip_binexpr", AssistKind::RefactorRewrite),
"Flip binary expression",
op_range,
|edit| {

View File

@ -29,8 +29,7 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
}
acc.add(
AssistId("flip_comma"),
AssistKind::RefactorRewrite,
AssistId("flip_comma", AssistKind::RefactorRewrite),
"Flip comma",
comma.text_range(),
|edit| {

View File

@ -34,8 +34,7 @@ pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext) -> Option
let target = plus.text_range();
acc.add(
AssistId("flip_trait_bound"),
AssistKind::RefactorRewrite,
AssistId("flip_trait_bound", AssistKind::RefactorRewrite),
"Flip trait bounds",
target,
|edit| {

View File

@ -111,8 +111,7 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
let target = bind_pat.syntax().text_range();
acc.add(
AssistId("inline_local_variable"),
AssistKind::RefactorInline,
AssistId("inline_local_variable", AssistKind::RefactorInline),
"Inline variable",
target,
move |builder| {

View File

@ -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(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
add_lifetime_param(fn_def, builder, end_of_fn_ident, new_lifetime_param);
builder.replace(lifetime_loc, format!("'{}", new_lifetime_param));
loc_needing_lifetime.map(|loc| builder.insert(loc, format!("'{} ", new_lifetime_param)));
@ -98,7 +98,7 @@ fn generate_impl_def_assist(
) -> Option<()> {
let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.type_param_list())?;
let end_of_impl_kw = impl_def.impl_token()?.text_range().end();
acc.add(AssistId(ASSIST_NAME), AssistKind::Refactor, ASSIST_LABEL, lifetime_loc, |builder| {
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
add_lifetime_param(impl_def, builder, end_of_impl_kw, new_lifetime_param);
builder.replace(lifetime_loc, format!("'{}", new_lifetime_param));
})

View File

@ -54,7 +54,7 @@ pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let else_node = else_block.syntax();
let else_range = else_node.text_range();
let then_range = then_node.text_range();
acc.add(AssistId("invert_if"), AssistKind::RefactorRewrite, "Invert if", if_range, |edit| {
acc.add(AssistId("invert_if", AssistKind::RefactorRewrite), "Invert if", if_range, |edit| {
edit.replace(cond_range, flip_cond.syntax().text());
edit.replace(else_range, then_node.text());
edit.replace(then_range, else_node.text());

View File

@ -57,8 +57,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
let target = tree.syntax().text_range();
acc.add(
AssistId("merge_imports"),
AssistKind::RefactorRewrite,
AssistId("merge_imports", AssistKind::RefactorRewrite),
"Merge imports",
target,
|builder| {

View File

@ -60,8 +60,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
}
acc.add(
AssistId("merge_match_arms"),
AssistKind::RefactorRewrite,
AssistId("merge_match_arms", AssistKind::RefactorRewrite),
"Merge match arms",
current_text_range,
|edit| {

View File

@ -51,8 +51,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
let target = type_param_list.syntax().text_range();
acc.add(
AssistId("move_bounds_to_where_clause"),
AssistKind::RefactorRewrite,
AssistId("move_bounds_to_where_clause", AssistKind::RefactorRewrite),
"Move to where clause",
target,
|edit| {

View File

@ -41,8 +41,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("move_guard_to_arm_body", AssistKind::RefactorRewrite),
"Move guard to arm body",
target,
|edit| {
@ -106,8 +105,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
let target = if_expr.syntax().text_range();
acc.add(
AssistId("move_arm_cond_to_match_guard"),
AssistKind::RefactorRewrite,
AssistId("move_arm_cond_to_match_guard", AssistKind::RefactorRewrite),
"Move condition to match guard",
target,
|edit| {

View File

@ -27,8 +27,7 @@ pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext) -> Option<
let value = token.value()?;
let target = token.syntax().text_range();
acc.add(
AssistId("make_raw_string"),
AssistKind::RefactorRewrite,
AssistId("make_raw_string", AssistKind::RefactorRewrite),
"Rewrite as raw string",
target,
|edit| {
@ -65,8 +64,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext) -> Optio
let value = token.value()?;
let target = token.syntax().text_range();
acc.add(
AssistId("make_usual_string"),
AssistKind::RefactorRewrite,
AssistId("make_usual_string", AssistKind::RefactorRewrite),
"Rewrite as regular string",
target,
|edit| {
@ -95,7 +93,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext) -> Optio
pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let token = ctx.find_token_at_offset(RAW_STRING)?;
let target = token.text_range();
acc.add(AssistId("add_hash"), AssistKind::Refactor, "Add # to raw string", target, |edit| {
acc.add(AssistId("add_hash", AssistKind::Refactor), "Add # to raw string", target, |edit| {
edit.insert(token.text_range().start() + TextSize::of('r'), "#");
edit.insert(token.text_range().end(), "#");
})
@ -125,8 +123,7 @@ pub(crate) fn remove_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
}
let target = token.text_range();
acc.add(
AssistId("remove_hash"),
AssistKind::RefactorRewrite,
AssistId("remove_hash", AssistKind::RefactorRewrite),
"Remove hash from raw string",
target,
|edit| {

View File

@ -38,7 +38,7 @@ pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
};
let target = macro_call.syntax().text_range();
acc.add(AssistId("remove_dbg"), AssistKind::Refactor, "Remove dbg!()", target, |builder| {
acc.add(AssistId("remove_dbg", AssistKind::Refactor), "Remove dbg!()", target, |builder| {
builder.replace(macro_range, macro_content);
})
}

View File

@ -27,8 +27,7 @@ pub(crate) fn remove_mut(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let target = mut_token.text_range();
acc.add(
AssistId("remove_mut"),
AssistKind::Refactor,
AssistId("remove_mut", AssistKind::Refactor),
"Remove `mut` keyword",
target,
|builder| {

View File

@ -43,8 +43,7 @@ fn reorder<R: AstNode>(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let target = record.syntax().text_range();
acc.add(
AssistId("reorder_fields"),
AssistKind::RefactorRewrite,
AssistId("reorder_fields", AssistKind::RefactorRewrite),
"Reorder record fields",
target,
|edit| {

View File

@ -49,8 +49,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
let target = if_expr.syntax().text_range();
acc.add(
AssistId("replace_if_let_with_match"),
AssistKind::RefactorRewrite,
AssistId("replace_if_let_with_match", AssistKind::RefactorRewrite),
"Replace with match",
target,
move |edit| {

View File

@ -45,8 +45,7 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) ->
let target = let_kw.text_range();
acc.add(
AssistId("replace_let_with_if_let"),
AssistKind::RefactorRewrite,
AssistId("replace_let_with_if_let", AssistKind::RefactorRewrite),
"Replace with if-let",
target,
|edit| {

View File

@ -37,8 +37,7 @@ pub(crate) fn replace_qualified_name_with_use(
let target = path.syntax().text_range();
acc.add(
AssistId("replace_qualified_name_with_use"),
AssistKind::RefactorRewrite,
AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite),
"Replace qualified path with use",
target,
|builder| {

View File

@ -47,8 +47,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
let happy_variant = TryEnum::from_ty(&ctx.sema, &ty)?.happy_case();
let target = method_call.syntax().text_range();
acc.add(
AssistId("replace_unwrap_with_match"),
AssistKind::RefactorRewrite,
AssistId("replace_unwrap_with_match", AssistKind::RefactorRewrite),
"Replace unwrap with match",
target,
|builder| {

View File

@ -28,7 +28,7 @@ pub(crate) fn split_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
}
let target = colon_colon.text_range();
acc.add(AssistId("split_import"), AssistKind::RefactorRewrite, "Split import", target, |edit| {
acc.add(AssistId("split_import", AssistKind::RefactorRewrite), "Split import", target, |edit| {
edit.replace_ast(use_tree, new_tree);
})
}

View File

@ -27,7 +27,7 @@
// }
// ```
pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let assist_id = AssistId("unwrap_block");
let assist_id = AssistId("unwrap_block", AssistKind::RefactorRewrite);
let assist_label = "Unwrap block";
let l_curly_token = ctx.find_token_at_offset(T!['{'])?;
@ -50,47 +50,35 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
let ancestor_then_branch = ancestor.then_branch()?;
let target = then_branch.syntax().text_range();
return acc.add(
assist_id,
AssistKind::Refactor,
assist_label,
target,
|edit| {
let range_to_del_else_if = TextRange::new(
ancestor_then_branch.syntax().text_range().end(),
l_curly_token.text_range().start(),
);
let range_to_del_rest = TextRange::new(
then_branch.syntax().text_range().end(),
if_expr.syntax().text_range().end(),
);
return acc.add(assist_id, assist_label, target, |edit| {
let range_to_del_else_if = TextRange::new(
ancestor_then_branch.syntax().text_range().end(),
l_curly_token.text_range().start(),
);
let range_to_del_rest = TextRange::new(
then_branch.syntax().text_range().end(),
if_expr.syntax().text_range().end(),
);
edit.delete(range_to_del_rest);
edit.delete(range_to_del_else_if);
edit.replace(
target,
update_expr_string(then_branch.to_string(), &[' ', '{']),
);
},
);
edit.delete(range_to_del_rest);
edit.delete(range_to_del_else_if);
edit.replace(
target,
update_expr_string(then_branch.to_string(), &[' ', '{']),
);
});
}
} else {
let target = block.syntax().text_range();
return acc.add(
assist_id,
AssistKind::RefactorRewrite,
assist_label,
target,
|edit| {
let range_to_del = TextRange::new(
then_branch.syntax().text_range().end(),
l_curly_token.text_range().start(),
);
return acc.add(assist_id, assist_label, target, |edit| {
let range_to_del = TextRange::new(
then_branch.syntax().text_range().end(),
l_curly_token.text_range().start(),
);
edit.delete(range_to_del);
edit.replace(target, update_expr_string(block.to_string(), &[' ', '{']));
},
);
edit.delete(range_to_del);
edit.replace(target, update_expr_string(block.to_string(), &[' ', '{']));
});
}
}
_ => return None,
@ -98,7 +86,7 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
let unwrapped = unwrap_trivial_block(block);
let target = unwrapped.syntax().text_range();
acc.add(assist_id, AssistKind::RefactorRewrite, assist_label, target, |builder| {
acc.add(assist_id, assist_label, target, |builder| {
builder.replace(
parent.syntax().text_range(),
update_expr_string(unwrapped.to_string(), &[' ', '{', '\n']),

View File

@ -26,10 +26,22 @@ macro_rules! eprintln {
pub use assist_config::AssistConfig;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AssistKind {
None,
QuickFix,
Refactor,
RefactorExtract,
RefactorInline,
RefactorRewrite,
Source,
OrganizeImports,
}
/// Unique identifier of the assist, should not be shown to the user
/// directly.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AssistId(pub &'static str);
pub struct AssistId(pub &'static str, pub AssistKind);
#[derive(Clone, Debug)]
pub struct GroupLabel(pub String);
@ -37,7 +49,6 @@ macro_rules! eprintln {
#[derive(Debug, Clone)]
pub struct Assist {
pub id: AssistId,
pub kind: AssistKind,
/// Short description of the assist, as shown in the UI.
pub label: String,
pub group: Option<GroupLabel>,
@ -52,18 +63,6 @@ pub struct ResolvedAssist {
pub source_change: SourceChange,
}
#[derive(Debug, Copy, Clone)]
pub enum AssistKind {
None,
QuickFix,
Refactor,
RefactorExtract,
RefactorInline,
RefactorRewrite,
Source,
OrganizeImports,
}
impl Assist {
/// Return all the assists applicable at the given position.
///
@ -99,14 +98,13 @@ pub fn resolved(
pub(crate) fn new(
id: AssistId,
kind: AssistKind,
label: String,
group: Option<GroupLabel>,
target: TextRange,
) -> Assist {
// FIXME: make fields private, so that this invariant can't be broken
assert!(label.starts_with(|c: char| c.is_uppercase()));
Assist { id, kind, label, group, target }
Assist { id, label, group, target }
}
}

View File

@ -650,7 +650,7 @@ pub(crate) fn unresolved_code_action(
title: assist.label,
id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())),
group: assist.group.filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0),
kind: Some(code_action_kind(assist.kind)),
kind: Some(code_action_kind(assist.id.1)),
edit: None,
command: None,
};