1
1
import { inject , injectable , named } from 'inversify' ;
2
+ import { parse } from 'jsonc-parser' ;
2
3
import * as path from 'path' ;
3
- import * as stripJsonComments from 'strip-json-comments' ;
4
4
import { DebugConfiguration , Uri , WorkspaceFolder } from 'vscode' ;
5
5
import { IApplicationShell , IDebugService , IWorkspaceService } from '../../common/application/types' ;
6
6
import { EXTENSION_ROOT_DIR } from '../../common/constants' ;
@@ -12,9 +12,7 @@ import { DebuggerTypeName } from '../../debugger/constants';
12
12
import { IDebugConfigurationResolver } from '../../debugger/extension/configuration/types' ;
13
13
import { LaunchRequestArguments } from '../../debugger/types' ;
14
14
import { IServiceContainer } from '../../ioc/types' ;
15
- import {
16
- ITestDebugConfig , ITestDebugLauncher , LaunchOptions , TestProvider
17
- } from './types' ;
15
+ import { ITestDebugConfig , ITestDebugLauncher , LaunchOptions , TestProvider } from './types' ;
18
16
19
17
@injectable ( )
20
18
export class DebugLauncher implements ITestDebugLauncher {
@@ -45,7 +43,26 @@ export class DebugLauncher implements ITestDebugLauncher {
45
43
return debugManager . startDebugging ( workspaceFolder , launchArgs )
46
44
. then ( noop , ex => traceError ( 'Failed to start debugging tests' , ex ) ) ;
47
45
}
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
+ }
49
66
private resolveWorkspaceFolder ( cwd : string ) : WorkspaceFolder {
50
67
if ( ! this . workspaceService . hasWorkspaceFolders ) {
51
68
throw new Error ( 'Please open a workspace' ) ;
@@ -95,30 +112,6 @@ export class DebugLauncher implements ITestDebugLauncher {
95
112
}
96
113
return undefined ;
97
114
}
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
-
122
115
private applyDefaults (
123
116
cfg : ITestDebugConfig ,
124
117
workspaceFolder : WorkspaceFolder ,
0 commit comments