From 4c9347ecc3356748c52847a29d5e53a65778dc13 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Thu, 2 Jul 2020 18:01:22 -0400 Subject: Don't categorize things we don't care about --- crates/ra_assists/src/handlers/add_derive.rs | 2 +- crates/ra_assists/src/handlers/add_function.rs | 23 +++---- crates/ra_assists/src/handlers/add_new.rs | 89 ++++++++++++-------------- crates/ra_assists/src/lib.rs | 2 - crates/rust-analyzer/src/caps.rs | 2 - crates/rust-analyzer/src/to_proto.rs | 2 - 6 files changed, 52 insertions(+), 68 deletions(-) diff --git a/crates/ra_assists/src/handlers/add_derive.rs b/crates/ra_assists/src/handlers/add_derive.rs index 12acfbbe4..e2b94e7f8 100644 --- a/crates/ra_assists/src/handlers/add_derive.rs +++ b/crates/ra_assists/src/handlers/add_derive.rs @@ -29,7 +29,7 @@ pub(crate) fn add_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let nominal = ctx.find_node_at_offset::()?; 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::None), "Add `#[derive]`", target, |builder| { let derive_attr = nominal .attrs() .filter_map(|x| x.as_simple_call()) diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs index 6f2950daf..7150eb53a 100644 --- a/crates/ra_assists/src/handlers/add_function.rs +++ b/crates/ra_assists/src/handlers/add_function.rs @@ -62,20 +62,15 @@ pub(crate) fn add_function(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let function_builder = FunctionBuilder::from_call(&ctx, &call, &path, target_module)?; let target = call.syntax().text_range(); - acc.add( - AssistId("add_function", AssistKind::RefactorExtract), - "Add function", - target, - |builder| { - let function_template = function_builder.render(); - builder.edit_file(function_template.file); - let new_fn = function_template.to_string(ctx.config.snippet_cap); - match ctx.config.snippet_cap { - Some(cap) => builder.insert_snippet(cap, function_template.insert_offset, new_fn), - None => builder.insert(function_template.insert_offset, new_fn), - } - }, - ) + acc.add(AssistId("add_function", AssistKind::None), "Add function", target, |builder| { + let function_template = function_builder.render(); + builder.edit_file(function_template.file); + let new_fn = function_template.to_string(ctx.config.snippet_cap); + match ctx.config.snippet_cap { + Some(cap) => builder.insert_snippet(cap, function_template.insert_offset, new_fn), + None => builder.insert(function_template.insert_offset, new_fn), + } + }) } struct FunctionTemplate { diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 84eda5486..0b3d29c7c 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -42,55 +42,50 @@ pub(crate) fn add_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let impl_def = find_struct_impl(&ctx, &strukt)?; let target = strukt.syntax().text_range(); - acc.add( - AssistId("add_new", AssistKind::Refactor), - "Add default constructor", - target, - |builder| { - let mut buf = String::with_capacity(512); - - if impl_def.is_some() { - buf.push('\n'); - } + acc.add(AssistId("add_new", AssistKind::None), "Add default constructor", target, |builder| { + let mut buf = String::with_capacity(512); - let vis = strukt.visibility().map_or(String::new(), |v| format!("{} ", v)); - - let params = field_list - .fields() - .filter_map(|f| { - Some(format!("{}: {}", f.name()?.syntax(), f.ascribed_type()?.syntax())) - }) - .sep_by(", "); - let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); - - format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields); - - let start_offset = impl_def - .and_then(|impl_def| { - buf.push('\n'); - let start = impl_def - .syntax() - .descendants_with_tokens() - .find(|t| t.kind() == T!['{'])? - .text_range() - .end(); - - Some(start) - }) - .unwrap_or_else(|| { - buf = generate_impl_text(&strukt, &buf); - strukt.syntax().text_range().end() - }); - - match ctx.config.snippet_cap { - None => builder.insert(start_offset, buf), - Some(cap) => { - buf = buf.replace("fn new", "fn $0new"); - builder.insert_snippet(cap, start_offset, buf); - } + if impl_def.is_some() { + buf.push('\n'); + } + + let vis = strukt.visibility().map_or(String::new(), |v| format!("{} ", v)); + + let params = field_list + .fields() + .filter_map(|f| { + Some(format!("{}: {}", f.name()?.syntax(), f.ascribed_type()?.syntax())) + }) + .sep_by(", "); + let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); + + format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields); + + let start_offset = impl_def + .and_then(|impl_def| { + buf.push('\n'); + let start = impl_def + .syntax() + .descendants_with_tokens() + .find(|t| t.kind() == T!['{'])? + .text_range() + .end(); + + Some(start) + }) + .unwrap_or_else(|| { + buf = generate_impl_text(&strukt, &buf); + strukt.syntax().text_range().end() + }); + + match ctx.config.snippet_cap { + None => builder.insert(start_offset, buf), + Some(cap) => { + buf = buf.replace("fn new", "fn $0new"); + builder.insert_snippet(cap, start_offset, buf); } - }, - ) + } + }) } // Generates the surrounding `impl Type { }` including type and lifetime diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 201213c73..65cda95ee 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -34,8 +34,6 @@ pub enum AssistKind { RefactorExtract, RefactorInline, RefactorRewrite, - Source, - OrganizeImports, } /// Unique identifier of the assist, should not be shown to the user diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs index 673795e78..070ad5e68 100644 --- a/crates/rust-analyzer/src/caps.rs +++ b/crates/rust-analyzer/src/caps.rs @@ -112,8 +112,6 @@ fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProvi lsp_types::code_action_kind::REFACTOR_EXTRACT.to_string(), lsp_types::code_action_kind::REFACTOR_INLINE.to_string(), lsp_types::code_action_kind::REFACTOR_REWRITE.to_string(), - lsp_types::code_action_kind::SOURCE.to_string(), - lsp_types::code_action_kind::SOURCE_ORGANIZE_IMPORTS.to_string(), ]), work_done_progress_options: Default::default(), }) diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index e16d6482a..2312a6e4d 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -635,8 +635,6 @@ pub(crate) fn code_action_kind(kind: AssistKind) -> String { AssistKind::RefactorExtract => lsp_types::code_action_kind::REFACTOR_EXTRACT, AssistKind::RefactorInline => lsp_types::code_action_kind::REFACTOR_INLINE, AssistKind::RefactorRewrite => lsp_types::code_action_kind::REFACTOR_REWRITE, - AssistKind::Source => lsp_types::code_action_kind::SOURCE, - AssistKind::OrganizeImports => lsp_types::code_action_kind::SOURCE_ORGANIZE_IMPORTS, } .to_string() } -- cgit v1.2.3