@@ -9,9 +9,10 @@ use ra_fmt::{leading_indent, reindent};
9
9
10
10
use crate :: { AssistLabel , AssistAction } ;
11
11
12
+ #[ derive( Clone , Debug ) ]
12
13
pub ( crate ) enum Assist {
13
- Unresolved ( AssistLabel ) ,
14
- Resolved ( AssistLabel , AssistAction ) ,
14
+ Unresolved ( Vec < AssistLabel > ) ,
15
+ Resolved ( Vec < ( AssistLabel , AssistAction ) > ) ,
15
16
}
16
17
17
18
/// `AssistCtx` allows to apply an assist or check if it could be applied.
@@ -50,6 +51,7 @@ pub(crate) struct AssistCtx<'a, DB> {
50
51
pub ( crate ) frange : FileRange ,
51
52
source_file : & ' a SourceFile ,
52
53
should_compute_edit : bool ,
54
+ assist : Assist ,
53
55
}
54
56
55
57
impl < ' a , DB > Clone for AssistCtx < ' a , DB > {
@@ -59,6 +61,7 @@ impl<'a, DB> Clone for AssistCtx<'a, DB> {
59
61
frange : self . frange ,
60
62
source_file : self . source_file ,
61
63
should_compute_edit : self . should_compute_edit ,
64
+ assist : self . assist . clone ( ) ,
62
65
}
63
66
}
64
67
}
@@ -69,25 +72,35 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
69
72
F : FnOnce ( AssistCtx < DB > ) -> T ,
70
73
{
71
74
let source_file = & db. parse ( frange. file_id ) ;
72
- let ctx = AssistCtx { db, frange, source_file, should_compute_edit } ;
75
+ let assist =
76
+ if should_compute_edit { Assist :: Resolved ( vec ! [ ] ) } else { Assist :: Unresolved ( vec ! [ ] ) } ;
77
+
78
+ let ctx = AssistCtx { db, frange, source_file, should_compute_edit, assist } ;
73
79
f ( ctx)
74
80
}
75
81
76
- pub ( crate ) fn build (
77
- self ,
82
+ pub ( crate ) fn add_action (
83
+ & mut self ,
78
84
label : impl Into < String > ,
79
85
f : impl FnOnce ( & mut AssistBuilder ) ,
80
- ) -> Option < Assist > {
86
+ ) -> & mut Self {
81
87
let label = AssistLabel { label : label. into ( ) } ;
82
- if !self . should_compute_edit {
83
- return Some ( Assist :: Unresolved ( label) ) ;
88
+ match & mut self . assist {
89
+ Assist :: Unresolved ( labels) => labels. push ( label) ,
90
+ Assist :: Resolved ( labels_actions) => {
91
+ let action = {
92
+ let mut edit = AssistBuilder :: default ( ) ;
93
+ f ( & mut edit) ;
94
+ edit. build ( )
95
+ } ;
96
+ labels_actions. push ( ( label, action) ) ;
97
+ }
84
98
}
85
- let action = {
86
- let mut edit = AssistBuilder :: default ( ) ;
87
- f ( & mut edit) ;
88
- edit. build ( )
89
- } ;
90
- Some ( Assist :: Resolved ( label, action) )
99
+ self
100
+ }
101
+
102
+ pub ( crate ) fn build ( self ) -> Option < Assist > {
103
+ Some ( self . assist )
91
104
}
92
105
93
106
pub ( crate ) fn leaf_at_offset ( & self ) -> LeafAtOffset < & ' a SyntaxNode > {
0 commit comments