@@ -549,24 +549,15 @@ export class FileSystemState {
549549 } )
550550 }
551551 public async getAllExts ( ) : Promise < ExtInstanceHeartbeat [ ] > {
552- const res = await withFailCtx ( 'getAllExts' , async ( ) => {
552+ return withFailCtx ( 'getAllExts' , async ( ) => {
553553 // Read all the exts from the filesystem, deserializing as needed
554554 const allExtIds : ExtInstanceId [ ] = await withFailCtx ( 'readdir' , async ( ) => {
555555 const filesInDir = await fs . readdir ( this . stateDirPath )
556- const relevantFiles = filesInDir . filter ( ( file : [ string , vscode . FileType ] ) => {
557- const name = file [ 0 ]
558- const type = file [ 1 ]
559- if ( type !== vscode . FileType . File ) {
560- return false
561- }
562- if ( path . extname ( name ) !== `.${ this . fileSuffix } ` ) {
563- return false
564- }
565- return true
556+ const relevantFiles = filesInDir . filter ( ( file : [ name : string , type : vscode . FileType ] ) => {
557+ return file [ 1 ] === vscode . FileType . File && path . extname ( file [ 0 ] ) === `.${ this . fileSuffix } `
566558 } )
567- const idsFromFileNames = relevantFiles . map ( ( file : [ string , vscode . FileType ] ) => {
568- const name = file [ 0 ]
569- return name . split ( '.' ) [ 0 ]
559+ const idsFromFileNames = relevantFiles . map ( ( file : [ name : string , type : vscode . FileType ] ) => {
560+ return file [ 0 ] . split ( '.' ) [ 0 ]
570561 } )
571562 return idsFromFileNames
572563 } )
@@ -575,22 +566,21 @@ export class FileSystemState {
575566 // Due to a race condition, a separate extension instance may have removed this file by this point. It is okay since
576567 // we will assume that other instance handled its termination appropriately.
577568 // NOTE: On Windows we were failing on EBUSY, so we retry on failure.
578- const ext : ExtInstanceHeartbeat | undefined = await withRetries (
579- ( ) =>
580- withFailCtx ( 'parseRunningExtFile' , async ( ) =>
581- ignoreBadFileError ( async ( ) => {
582- const text = await fs . readFileText ( this . makeStateFilePath ( extId ) )
583-
584- if ( ! text ) {
585- return undefined
586- }
587-
588- // This was sometimes throwing SyntaxError
589- return JSON . parse ( text ) as ExtInstanceHeartbeat
590- } )
591- ) ,
592- { maxRetries : 6 , delay : 100 , backoff : 2 }
593- )
569+ const loadExtFromDisk = async ( ) => {
570+ const text = await fs . readFileText ( this . makeStateFilePath ( extId ) )
571+
572+ if ( ! text ) {
573+ return undefined
574+ }
575+
576+ // This was sometimes throwing SyntaxError
577+ return JSON . parse ( text ) as ExtInstanceHeartbeat
578+ }
579+ const funcWithIgnoreBadFile = ( ) => ignoreBadFileError ( loadExtFromDisk )
580+ const funcWithRetries = ( ) =>
581+ withRetries ( funcWithIgnoreBadFile , { maxRetries : 6 , delay : 100 , backoff : 2 } )
582+ const funcWithCtx = ( ) => withFailCtx ( 'parseRunningExtFile' , funcWithRetries )
583+ const ext : ExtInstanceHeartbeat | undefined = await funcWithCtx ( )
594584
595585 if ( ext === undefined ) {
596586 return
@@ -602,10 +592,8 @@ export class FileSystemState {
602592 return ext
603593 } )
604594 // filter out undefined before returning
605- const result = ( await Promise . all ( allExts ) ) . filter < ExtInstanceHeartbeat > ( isExtHeartbeat )
606- return result
595+ return ( await Promise . all ( allExts ) ) . filter < ExtInstanceHeartbeat > ( isExtHeartbeat )
607596 } )
608- return res
609597 }
610598}
611599
0 commit comments