@@ -45,6 +45,9 @@ pub fn run_server(analysis: Arc<AnalysisHost>, vfs: Arc<Vfs>) {
45
45
#[ derive( Debug , Serialize ) ]
46
46
pub struct Ack ;
47
47
48
+ #[ derive( Debug ) ]
49
+ pub struct NoResponse ;
50
+
48
51
#[ derive( Debug , Serialize , PartialEq ) ]
49
52
pub struct NoParams ;
50
53
@@ -56,6 +59,21 @@ impl<'de> Deserialize<'de> for NoParams {
56
59
}
57
60
}
58
61
62
+ pub trait Response {
63
+ fn send < O : Output > ( & self , id : usize , out : O ) ;
64
+ }
65
+
66
+ impl Response for NoResponse {
67
+ fn send < O : Output > ( & self , _id : usize , _out : O ) {
68
+ }
69
+ }
70
+
71
+ impl < R : :: serde:: Serialize + fmt:: Debug > Response for R {
72
+ fn send < O : Output > ( & self , id : usize , out : O ) {
73
+ out. success ( id, & self ) ;
74
+ }
75
+ }
76
+
59
77
pub trait Action < ' a > {
60
78
type Params : serde:: Serialize + for < ' de > :: serde:: Deserialize < ' de > ;
61
79
const METHOD : & ' static str ;
@@ -68,7 +86,7 @@ pub trait NotificationAction<'a>: Action<'a> {
68
86
}
69
87
70
88
pub trait RequestAction < ' a > : Action < ' a > {
71
- type Response : :: serde :: Serialize + fmt:: Debug ;
89
+ type Response : Response + fmt:: Debug ;
72
90
73
91
fn handle < O : Output > ( & mut self , id : usize , params : Self :: Params , ctx : & mut ActionContext , out : O ) -> Result < Self :: Response , ( ) > ;
74
92
}
@@ -90,9 +108,7 @@ impl<'a, A: RequestAction<'a>> Request<'a, A> {
90
108
fn dispatch < O : Output > ( self , state : & ' a mut LsState , ctx : & mut ActionContext , out : O ) -> Result < A :: Response , ( ) > {
91
109
let mut action = A :: new ( state) ;
92
110
let result = action. handle ( self . id , self . params , ctx, out. clone ( ) ) ?;
93
- if :: std:: mem:: size_of :: < A :: Response > ( ) > 0 {
94
- out. success ( self . id , & result) ;
95
- }
111
+ result. send ( self . id , out) ;
96
112
Ok ( result)
97
113
}
98
114
}
@@ -196,8 +212,8 @@ impl<'a> Action<'a> for InitializeRequest {
196
212
}
197
213
198
214
impl < ' a > RequestAction < ' a > for InitializeRequest {
199
- type Response = ( ) ;
200
- fn handle < O : Output > ( & mut self , id : usize , params : Self :: Params , ctx : & mut ActionContext , out : O ) -> Result < ( ) , ( ) > {
215
+ type Response = NoResponse ;
216
+ fn handle < O : Output > ( & mut self , id : usize , params : Self :: Params , ctx : & mut ActionContext , out : O ) -> Result < NoResponse , ( ) > {
201
217
let init_options: InitializationOptions = params
202
218
. initialization_options
203
219
. as_ref ( )
@@ -240,7 +256,7 @@ impl<'a> RequestAction<'a> for InitializeRequest {
240
256
let root_path = params. root_path . as_ref ( ) . map ( PathBuf :: from) . expect ( "No root path" ) ;
241
257
ctx. init ( root_path, & init_options, out) ;
242
258
243
- Ok ( ( ) )
259
+ Ok ( NoResponse )
244
260
}
245
261
}
246
262
0 commit comments