@@ -62,8 +62,17 @@ export function getRawPackageJson(): any {
6262 return rawPackageJson ;
6363}
6464
65+ export async function getRawLaunchJson ( ) : Promise < any > {
66+ const path : string | undefined = getLaunchJsonPath ( ) ;
67+ return getRawJson ( path ) ;
68+ }
69+
6570export async function getRawTasksJson ( ) : Promise < any > {
6671 const path : string | undefined = getTasksJsonPath ( ) ;
72+ return getRawJson ( path ) ;
73+ }
74+
75+ async function getRawJson ( path : string | undefined ) : Promise < any > {
6776 if ( ! path ) {
6877 return { } ;
6978 }
@@ -82,6 +91,24 @@ export async function getRawTasksJson(): Promise<any> {
8291 return rawTasks ;
8392}
8493
94+ export async function ensureDebugConfigExists ( configName : string ) : Promise < void > {
95+ const launchJsonPath : string | undefined = getLaunchJsonPath ( ) ;
96+ if ( ! launchJsonPath ) {
97+ throw new Error ( "Failed to get launchJsonPath in ensureDebugConfigExists()" ) ;
98+ }
99+
100+ const rawLaunchJson : any = await getRawLaunchJson ( ) ;
101+ // Ensure that the debug configurations exists in the user's launch.json. Config will not be found otherwise.
102+ if ( ! rawLaunchJson || ! rawLaunchJson . configurations ) {
103+ throw new Error ( `Configuration '${ configName } ' is missing in 'launch.json'.` ) ;
104+ }
105+ const selectedConfig : vscode . Task | undefined = rawLaunchJson . configurations . find ( ( config : any ) => config . name && config . name === configName ) ;
106+ if ( ! selectedConfig ) {
107+ throw new Error ( `Configuration '${ configName } ' is missing in 'launch.json'.` ) ;
108+ }
109+ return ;
110+ }
111+
85112export async function ensureBuildTaskExists ( taskLabel : string ) : Promise < void > {
86113 const rawTasksJson : any = await getRawTasksJson ( ) ;
87114
@@ -159,7 +186,15 @@ export function getPackageJsonPath(): string {
159186 return getExtensionFilePath ( "package.json" ) ;
160187}
161188
189+ export function getLaunchJsonPath ( ) : string | undefined {
190+ return getJsonPath ( "launch.json" ) ;
191+ }
192+
162193export function getTasksJsonPath ( ) : string | undefined {
194+ return getJsonPath ( "tasks.json" ) ;
195+ }
196+
197+ function getJsonPath ( jsonFilaName : string ) : string | undefined {
163198 const editor : vscode . TextEditor | undefined = vscode . window . activeTextEditor ;
164199 if ( ! editor ) {
165200 return undefined ;
@@ -168,7 +203,7 @@ export function getTasksJsonPath(): string | undefined {
168203 if ( ! folder ) {
169204 return undefined ;
170205 }
171- return path . join ( folder . uri . fsPath , ".vscode" , "tasks.json" ) ;
206+ return path . join ( folder . uri . fsPath , ".vscode" , jsonFilaName ) ;
172207}
173208
174209export function getVcpkgPathDescriptorFile ( ) : string {
0 commit comments