@@ -381,22 +381,17 @@ export default class AutoLanguageClient {
381
381
}
382
382
383
383
private captureServerErrors ( lsProcess : LanguageServerProcess , projectPath : string ) : void {
384
- lsProcess . on ( 'error' , ( err ) => this . handleSpawnFailure ( err ) ) ;
385
- lsProcess . on ( "close" , ( ... args ) => this . handleCloseFailure ( ... args ) ) ;
386
- lsProcess . on ( 'exit' , ( code , signal ) => this . logger . debug ( `exit: code ${ code } signal ${ signal } ` ) ) ;
384
+ lsProcess . on ( 'error' , ( err ) => this . onSpawnError ( err ) ) ;
385
+ lsProcess . on ( "close" , ( code , signal ) => this . onSpawnClose ( code , signal ) ) ;
386
+ lsProcess . on ( 'exit' , ( code , signal ) => this . onSpawnExit ( code , signal ) ) ;
387
387
lsProcess . stderr ?. setEncoding ( 'utf8' ) ;
388
- lsProcess . stderr ?. on ( 'data' , ( chunk : Buffer ) => {
389
- const errorString = chunk . toString ( ) ;
390
- this . handleServerStderr ( errorString , projectPath ) ;
391
- // Keep the last 5 lines for packages to use in messages
392
- this . processStdErr = ( this . processStdErr + errorString )
393
- . split ( '\n' )
394
- . slice ( - 5 )
395
- . join ( '\n' ) ;
396
- } ) ;
388
+ lsProcess . stderr ?. on ( 'data' , ( chunk : Buffer ) => this . onSpawnStdErrData ( chunk , projectPath ) ) ;
397
389
}
398
390
399
- private handleSpawnFailure ( err : any ) : void {
391
+ /** The function called whenever the spawned server `error`s.
392
+ * Extend (call super.onSpawnError) or override this if you need custom error handling
393
+ */
394
+ protected onSpawnError ( err : Error ) : void {
400
395
atom . notifications . addError (
401
396
`${ this . getServerName ( ) } language server for ${ this . getLanguageName ( ) } unable to start` ,
402
397
{
@@ -406,14 +401,38 @@ export default class AutoLanguageClient {
406
401
) ;
407
402
}
408
403
409
- private handleCloseFailure ( code : number | null , signal : NodeJS . Signals | null ) : void {
404
+ /** The function called whenever the spawned server `close`s.
405
+ * Extend (call super.onSpawnClose) or override this if you need custom close handling
406
+ */
407
+ protected onSpawnClose ( code : number | null , signal : NodeJS . Signals | null ) : void {
410
408
if ( code !== 0 && signal === null ) {
411
409
atom . notifications . addError (
412
410
`${ this . getServerName ( ) } language server for ${ this . getLanguageName ( ) } was closed with code: ${ code } .`
413
411
) ;
414
412
}
415
413
}
416
414
415
+
416
+ /** The function called whenever the spawned server `exit`s.
417
+ * Extend (call super.onSpawnExit) or override this if you need custom exit handling
418
+ */
419
+ protected onSpawnExit ( code : number | null , signal : NodeJS . Signals | null ) : void {
420
+ this . logger . debug ( `exit: code ${ code } signal ${ signal } ` ) ;
421
+ }
422
+
423
+ /** The function called whenever the spawned server returns `data` in `stderr`
424
+ * Extend (call super.onSpawnStdErrData) or override this if you need custom stderr data handling
425
+ */
426
+ protected onSpawnStdErrData ( chunk : Buffer , projectPath : string ) : void {
427
+ const errorString = chunk . toString ( ) ;
428
+ this . handleServerStderr ( errorString , projectPath ) ;
429
+ // Keep the last 5 lines for packages to use in messages
430
+ this . processStdErr = ( this . processStdErr + errorString )
431
+ . split ( '\n' )
432
+ . slice ( - 5 )
433
+ . join ( '\n' ) ;
434
+ }
435
+
417
436
/** Creates the RPC connection which can be ipc, socket or stdio */
418
437
private createRpcConnection ( lsProcess : LanguageServerProcess ) : rpc . MessageConnection {
419
438
let reader : rpc . MessageReader ;
0 commit comments