aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers/add_derive.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-07 15:28:47 +0100
committerGitHub <[email protected]>2020-05-07 15:28:47 +0100
commitc7e305731c922a2d32eda89ff22cb636059bc4e7 (patch)
tree4f3ab3a70fbbb901ccec3cd162da00eaa9cbad09 /crates/ra_assists/src/handlers/add_derive.rs
parentf4cd75ac06dff7f5a95065a6c3868669e5c2ab27 (diff)
parent4867968d22899395e6551f22641b3617e995140c (diff)
Merge #4350
4350: Refactor assists API to be more convenient for adding new assists r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers/add_derive.rs')
-rw-r--r--crates/ra_assists/src/handlers/add_derive.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/crates/ra_assists/src/handlers/add_derive.rs b/crates/ra_assists/src/handlers/add_derive.rs
index 2a6bb1cae..fb08c19e9 100644
--- a/crates/ra_assists/src/handlers/add_derive.rs
+++ b/crates/ra_assists/src/handlers/add_derive.rs
@@ -4,7 +4,7 @@ use ra_syntax::{
4 TextSize, 4 TextSize,
5}; 5};
6 6
7use crate::{Assist, AssistCtx, AssistId}; 7use crate::{AssistContext, AssistId, Assists};
8 8
9// Assist: add_derive 9// Assist: add_derive
10// 10//
@@ -24,11 +24,11 @@ use crate::{Assist, AssistCtx, AssistId};
24// y: u32, 24// y: u32,
25// } 25// }
26// ``` 26// ```
27pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> { 27pub(crate) fn add_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
28 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; 28 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
29 let node_start = derive_insertion_offset(&nominal)?; 29 let node_start = derive_insertion_offset(&nominal)?;
30 let target = nominal.syntax().text_range(); 30 let target = nominal.syntax().text_range();
31 ctx.add_assist(AssistId("add_derive"), "Add `#[derive]`", target, |edit| { 31 acc.add(AssistId("add_derive"), "Add `#[derive]`", target, |edit| {
32 let derive_attr = nominal 32 let derive_attr = nominal
33 .attrs() 33 .attrs()
34 .filter_map(|x| x.as_simple_call()) 34 .filter_map(|x| x.as_simple_call())
@@ -57,9 +57,10 @@ fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> {
57 57
58#[cfg(test)] 58#[cfg(test)]
59mod tests { 59mod tests {
60 use super::*;
61 use crate::tests::{check_assist, check_assist_target}; 60 use crate::tests::{check_assist, check_assist_target};
62 61
62 use super::*;
63
63 #[test] 64 #[test]
64 fn add_derive_new() { 65 fn add_derive_new() {
65 check_assist( 66 check_assist(