@@ -440,6 +440,7 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
440440 private readonly _ignoredRegistrations : Set < string > ;
441441 // private _idleStart: number | undefined;
442442 private readonly _listeners : Disposable [ ] ;
443+ private _disposed : 'disposing' | 'disposed' | undefined ;
443444
444445 private readonly _notificationHandlers : Map < string , GenericNotificationHandler > ;
445446 private readonly _notificationDisposables : Map < string , Disposable > ;
@@ -769,6 +770,9 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
769770 }
770771
771772 public async sendProgress < P > ( type : ProgressType < P > , token : string | number , value : P ) : Promise < void > {
773+ if ( this . $state === ClientState . StartFailed || this . $state === ClientState . Stopping || this . $state === ClientState . Stopped ) {
774+ return Promise . reject ( new ResponseError ( ErrorCodes . ConnectionInactive , `Client is not running` ) ) ;
775+ }
772776 try {
773777 // Ensure we have a connection before we force the document sync.
774778 const connection = await this . $start ( ) ;
@@ -935,6 +939,9 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
935939 }
936940
937941 public async start ( ) : Promise < void > {
942+ if ( this . _disposed === 'disposing' || this . _disposed === 'disposed' ) {
943+ throw new Error ( `Client got disposed and can't be restarted.` ) ;
944+ }
938945 if ( this . $state === ClientState . Stopping ) {
939946 throw new Error ( `Client is currently stopping. Can only restart a full stopped client` ) ;
940947 }
@@ -1226,6 +1233,15 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
12261233 return this . shutdown ( 'stop' , timeout ) ;
12271234 }
12281235
1236+ public dispose ( timeout : number = 2000 ) : Promise < void > {
1237+ try {
1238+ this . _disposed = 'disposing' ;
1239+ return this . stop ( timeout ) ;
1240+ } finally {
1241+ this . _disposed = 'disposed' ;
1242+ }
1243+ }
1244+
12291245 private async shutdown ( mode : 'suspend' | 'stop' , timeout : number ) : Promise < void > {
12301246 // If the client is stopped or in its initial state return.
12311247 if ( this . $state === ClientState . Stopped || this . $state === ClientState . Initial ) {
0 commit comments