@@ -151,7 +151,10 @@ export interface IServerRequestHandler<
151
151
T extends keyof IServerRequestParams = keyof IServerRequestParams
152
152
> {
153
153
setHandler (
154
- handler : ( params : IServerRequestParams [ T ] ) => Promise < IServerResult [ T ] >
154
+ handler : (
155
+ params : IServerRequestParams [ T ] ,
156
+ connection ?: LSPConnection
157
+ ) => Promise < IServerResult [ T ] >
155
158
) : void ;
156
159
clearHandler ( ) : void ;
157
160
}
@@ -183,10 +186,15 @@ class ServerRequestHandler<
183
186
T extends keyof IServerRequestParams = keyof IServerRequestParams
184
187
> implements IServerRequestHandler {
185
188
private _handler : (
186
- params : IServerRequestParams [ T ]
189
+ params : IServerRequestParams [ T ] ,
190
+ connection ?: LSPConnection
187
191
) => Promise < IServerResult [ T ] > ;
188
192
189
- constructor ( protected connection : MessageConnection , protected method : T ) {
193
+ constructor (
194
+ protected connection : MessageConnection ,
195
+ protected method : T ,
196
+ protected emitter : LSPConnection
197
+ ) {
190
198
// on request accepts "thenable"
191
199
this . connection . onRequest ( method , this . handle ) ;
192
200
this . _handler = null ;
@@ -196,11 +204,14 @@ class ServerRequestHandler<
196
204
if ( ! this . _handler ) {
197
205
return ;
198
206
}
199
- return this . _handler ( request ) ;
207
+ return this . _handler ( request , this . emitter ) ;
200
208
}
201
209
202
210
setHandler (
203
- handler : ( params : IServerRequestParams [ T ] ) => Promise < IServerResult [ T ] >
211
+ handler : (
212
+ params : IServerRequestParams [ T ] ,
213
+ connection ?: LSPConnection
214
+ ) => Promise < IServerResult [ T ] >
204
215
) {
205
216
this . _handler = handler ;
206
217
}
@@ -281,7 +292,8 @@ export class LSPConnection extends LspWsConnection {
281
292
for ( let method of Object . values ( methods ) ) {
282
293
result [ method as U ] = new ServerRequestHandler (
283
294
this . connection ,
284
- ( method as U ) as any
295
+ ( method as U ) as any ,
296
+ this
285
297
) ;
286
298
}
287
299
return result as T ;
0 commit comments