11import { inject , injectable , named } from 'inversify' ;
2+ import { parse } from 'jsonc-parser' ;
23import * as path from 'path' ;
3- import * as stripJsonComments from 'strip-json-comments' ;
44import { DebugConfiguration , Uri , WorkspaceFolder } from 'vscode' ;
55import { IApplicationShell , IDebugService , IWorkspaceService } from '../../common/application/types' ;
66import { EXTENSION_ROOT_DIR } from '../../common/constants' ;
@@ -12,9 +12,7 @@ import { DebuggerTypeName } from '../../debugger/constants';
1212import { IDebugConfigurationResolver } from '../../debugger/extension/configuration/types' ;
1313import { LaunchRequestArguments } from '../../debugger/types' ;
1414import { IServiceContainer } from '../../ioc/types' ;
15- import {
16- ITestDebugConfig , ITestDebugLauncher , LaunchOptions , TestProvider
17- } from './types' ;
15+ import { ITestDebugConfig , ITestDebugLauncher , LaunchOptions , TestProvider } from './types' ;
1816
1917@injectable ( )
2018export class DebugLauncher implements ITestDebugLauncher {
@@ -45,7 +43,26 @@ export class DebugLauncher implements ITestDebugLauncher {
4543 return debugManager . startDebugging ( workspaceFolder , launchArgs )
4644 . then ( noop , ex => traceError ( 'Failed to start debugging tests' , ex ) ) ;
4745 }
48-
46+ public async readAllDebugConfigs ( workspaceFolder : WorkspaceFolder ) : Promise < DebugConfiguration [ ] > {
47+ const filename = path . join ( workspaceFolder . uri . fsPath , '.vscode' , 'launch.json' ) ;
48+ if ( ! ( await this . fs . fileExists ( filename ) ) ) {
49+ return [ ] ;
50+ }
51+ try {
52+ const text = await this . fs . readFile ( filename ) ;
53+ const parsed = parse ( text , [ ] , { allowTrailingComma : true , disallowComments : false } ) ;
54+ if ( ! parsed . version || ! parsed . configurations || ! Array . isArray ( parsed . configurations ) ) {
55+ throw Error ( 'malformed launch.json' ) ;
56+ }
57+ // We do not bother ensuring each item is a DebugConfiguration...
58+ return parsed . configurations ;
59+ } catch ( exc ) {
60+ traceError ( 'could not get debug config' , exc ) ;
61+ const appShell = this . serviceContainer . get < IApplicationShell > ( IApplicationShell ) ;
62+ await appShell . showErrorMessage ( 'Could not load unit test config from launch.json' ) ;
63+ return [ ] ;
64+ }
65+ }
4966 private resolveWorkspaceFolder ( cwd : string ) : WorkspaceFolder {
5067 if ( ! this . workspaceService . hasWorkspaceFolders ) {
5168 throw new Error ( 'Please open a workspace' ) ;
@@ -95,30 +112,6 @@ export class DebugLauncher implements ITestDebugLauncher {
95112 }
96113 return undefined ;
97114 }
98-
99- private async readAllDebugConfigs ( workspaceFolder : WorkspaceFolder ) : Promise < DebugConfiguration [ ] > {
100- const filename = path . join ( workspaceFolder . uri . fsPath , '.vscode' , 'launch.json' ) ;
101- let configs : DebugConfiguration [ ] = [ ] ;
102- if ( ! ( await this . fs . fileExists ( filename ) ) ) {
103- return [ ] ;
104- }
105- try {
106- let text = await this . fs . readFile ( filename ) ;
107- text = stripJsonComments ( text ) ;
108- const parsed = JSON . parse ( text ) ;
109- if ( ! parsed . version || ! parsed . configurations || ! Array . isArray ( parsed . configurations ) ) {
110- throw Error ( 'malformed launch.json' ) ;
111- }
112- // We do not bother ensuring each item is a DebugConfiguration...
113- configs = parsed . configurations ;
114- } catch ( exc ) {
115- traceError ( 'could not get debug config' , exc ) ;
116- const appShell = this . serviceContainer . get < IApplicationShell > ( IApplicationShell ) ;
117- await appShell . showErrorMessage ( 'Could not load unit test config from launch.json' ) ;
118- }
119- return configs ;
120- }
121-
122115 private applyDefaults (
123116 cfg : ITestDebugConfig ,
124117 workspaceFolder : WorkspaceFolder ,
0 commit comments