@@ -260,14 +260,27 @@ interface CreateParamsSignature<E, P> {
260260 ( data : E ) : RequestParam < P > ;
261261}
262262
263- export interface NotificationSendEvent < P extends { textDocument : TextDocumentIdentifier } > {
263+ interface NotificationEvent < P extends { textDocument : TextDocumentIdentifier } > {
264264 textDocument : TextDocument ;
265265 type : ProtocolNotificationType < P , TextDocumentRegistrationOptions > ;
266266 params : RequestParam < P > ;
267267}
268268
269+ export interface AboutToSendNotificationEvent < P extends { textDocument : TextDocumentIdentifier } > extends NotificationEvent < P > {
270+ }
271+
272+ export interface NotificationSentEvent < P extends { textDocument : TextDocumentIdentifier } > extends NotificationEvent < P > {
273+ }
274+
275+ /**
276+ * @deprecated Use `NotificationSentEvent` instead.
277+ */
278+ export interface NotificationSendEvent < P extends { textDocument : TextDocumentIdentifier } > extends NotificationSentEvent < P > {
279+ }
280+
269281export interface NotifyingFeature < P extends { textDocument : TextDocumentIdentifier } > {
270- onNotificationSent : VEvent < NotificationSendEvent < P > > ;
282+ onAboutToSendNotification : VEvent < AboutToSendNotificationEvent < P > > ;
283+ onNotificationSent : VEvent < NotificationSentEvent < P > > ;
271284}
272285
273286/**
@@ -340,7 +353,8 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc
340353
341354 private _listener : Disposable | undefined ;
342355 protected readonly _selectors : Map < string , VDocumentSelector > ;
343- private _onNotificationSent : EventEmitter < NotificationSendEvent < P > > ;
356+ private _onAboutToSendNotification : EventEmitter < AboutToSendNotificationEvent < P > > ;
357+ private _onNotificationSent : EventEmitter < NotificationSentEvent < P > > ;
344358
345359 public static textDocumentFilter ( selectors : IterableIterator < VDocumentSelector > , textDocument : TextDocument ) : boolean {
346360 for ( const selector of selectors ) {
@@ -365,7 +379,8 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc
365379 this . _selectorFilter = selectorFilter ;
366380
367381 this . _selectors = new Map < string , VDocumentSelector > ( ) ;
368- this . _onNotificationSent = new EventEmitter < NotificationSendEvent < P > > ( ) ;
382+ this . _onAboutToSendNotification = new EventEmitter < AboutToSendNotificationEvent < P > > ( ) ;
383+ this . _onNotificationSent = new EventEmitter < NotificationSentEvent < P > > ( ) ;
369384 }
370385
371386 protected getStateInfo ( ) : [ IterableIterator < VDocumentSelector > , boolean ] {
@@ -392,9 +407,11 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc
392407
393408 protected async callback ( data : E ) : Promise < void > {
394409 const doSend = async ( data : E ) : Promise < void > => {
410+ const textDocument = this . getTextDocument ( data ) ;
395411 const params = this . _createParams ( data ) ;
412+ this . aboutToSendNotification ( textDocument , this . _type , params ) ;
396413 await this . _client . sendNotification ( this . _type , params ) ;
397- this . notificationSent ( this . getTextDocument ( data ) , this . _type , params ) ;
414+ this . notificationSent ( textDocument , this . _type , params ) ;
398415 } ;
399416 if ( this . matches ( data ) ) {
400417 const middleware = this . _middleware ( ) ;
@@ -409,7 +426,15 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc
409426 return ! this . _selectorFilter || this . _selectorFilter ( this . _selectors . values ( ) , data ) ;
410427 }
411428
412- public get onNotificationSent ( ) : VEvent < NotificationSendEvent < P > > {
429+ public get onAboutToSendNotification ( ) : VEvent < AboutToSendNotificationEvent < P > > {
430+ return this . _onAboutToSendNotification . event ;
431+ }
432+
433+ protected aboutToSendNotification ( textDocument : TextDocument , type : ProtocolNotificationType < P , TextDocumentRegistrationOptions > , params : RequestParam < P > ) : void {
434+ this . _onAboutToSendNotification . fire ( { textDocument, type, params } ) ;
435+ }
436+
437+ public get onNotificationSent ( ) : VEvent < NotificationSentEvent < P > > {
413438 return this . _onNotificationSent . event ;
414439 }
415440
@@ -430,7 +455,7 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc
430455 public clear ( ) : void {
431456 this . _selectors . clear ( ) ;
432457 this . _onNotificationSent . dispose ( ) ;
433- this . _onNotificationSent = new EventEmitter < NotificationSendEvent < P > > ( ) ;
458+ this . _onNotificationSent = new EventEmitter < NotificationSentEvent < P > > ( ) ;
434459 if ( this . _listener ) {
435460 this . _listener . dispose ( ) ;
436461 this . _listener = undefined ;
0 commit comments