Add AssistKind::Generate

This commit is contained in:
Aleksey Kladov 2020-07-03 19:14:42 +02:00
parent 66b6a433c6
commit d09f692300
7 changed files with 32 additions and 26 deletions

View File

@ -29,7 +29,11 @@ pub(crate) fn generate_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("generate_derive", AssistKind::None), "Add `#[derive]`", target, |builder| {
acc.add(
AssistId("generate_derive", AssistKind::Generate),
"Add `#[derive]`",
target,
|builder| {
let derive_attr = nominal
.attrs()
.filter_map(|x| x.as_simple_call())
@ -49,7 +53,8 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<
)
}
};
})
},
)
}
// Insert `derive` after doc comments.

View File

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

View File

@ -63,7 +63,7 @@ pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext) -> Optio
let target = call.syntax().text_range();
acc.add(
AssistId("generate_function", AssistKind::None),
AssistId("generate_function", AssistKind::Generate),
format!("Generate `{}` function", function_builder.fn_name),
target,
|builder| {

View File

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

View File

@ -42,7 +42,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
let impl_def = find_struct_impl(&ctx, &strukt)?;
let target = strukt.syntax().text_range();
acc.add(AssistId("generate_new", AssistKind::None), "Generate `new`", target, |builder| {
acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| {
let mut buf = String::with_capacity(512);
if impl_def.is_some() {

View File

@ -30,6 +30,7 @@ pub use assist_config::AssistConfig;
pub enum AssistKind {
None,
QuickFix,
Generate,
Refactor,
RefactorExtract,
RefactorInline,

View File

@ -629,7 +629,7 @@ pub(crate) fn call_hierarchy_item(
pub(crate) fn code_action_kind(kind: AssistKind) -> String {
match kind {
AssistKind::None => lsp_types::code_action_kind::EMPTY,
AssistKind::None | AssistKind::Generate => lsp_types::code_action_kind::EMPTY,
AssistKind::QuickFix => lsp_types::code_action_kind::QUICKFIX,
AssistKind::Refactor => lsp_types::code_action_kind::REFACTOR,
AssistKind::RefactorExtract => lsp_types::code_action_kind::REFACTOR_EXTRACT,