@@ -18,7 +18,7 @@ export class RawBuildParser {
18
18
}
19
19
20
20
export class ProblemDiagnosticResolver implements HandleProblemDiagnosticResolver {
21
- private static xcodebuild = "xcodebuild" ;
21
+ static xcodebuild = "xcodebuild" ;
22
22
static isSourcekit : SourcePredicate = source => this . xcodebuild !== source ;
23
23
static isXcodebuild : SourcePredicate = source => this . xcodebuild === source ;
24
24
@@ -205,7 +205,7 @@ export class ProblemDiagnosticResolver implements HandleProblemDiagnosticResolve
205
205
}
206
206
if ( lastErrorIndex !== - 1 ) {
207
207
rawParser . triggerCharacter = "^" ;
208
- const problems = this . parseBuildLog (
208
+ const problems = parseBuildLog (
209
209
rawParser . buildLogFile ,
210
210
rawParser . stdout . substring ( 0 , lastErrorIndex + 1 ) ,
211
211
rawParser . numberOfLines
@@ -238,134 +238,138 @@ export class ProblemDiagnosticResolver implements HandleProblemDiagnosticResolve
238
238
this . buildErrors . clear ( ) ;
239
239
}
240
240
}
241
+ }
241
242
242
- private problemPattern = / ^ ( .* ?) : ( \d + ) (?: : ( \d + ) ) ? : \s + ( w a r n i n g | e r r o r | n o t e ) : \s + ( .* ) $ / gm;
243
- private problemLinkerPattern = / ^ ( c l a n g ) : \s + ( e r r o r ) : \s + ( .* ) $ / gm;
244
- private frameworkErrorPattern = / ^ ( e r r o r : ) ( .* ?) $ / gm;
243
+ const problemPattern = / ^ ( .* ?) : ( \d + ) (?: : ( \d + ) ) ? : \s + ( w a r n i n g | e r r o r | n o t e ) : \s + ( .* ) $ / gm;
244
+ const problemLinkerPattern = / ^ ( c l a n g ) : \s + ( e r r o r ) : \s + ( .* ) $ / gm;
245
+ const frameworkErrorPattern = / ^ ( e r r o r : ) ( .* ?) $ / gm;
245
246
246
- private column ( output : string , messageEnd : number ) {
247
- let newLineCounter = 0 ;
248
- let str = "" ;
249
- let shouldBreak = false ;
250
- for ( let i = messageEnd ; i < output . length ; ++ i ) {
251
- if ( output [ i ] === "\n" ) {
252
- if ( shouldBreak ) {
253
- break ;
254
- }
255
- str = "" ;
256
- newLineCounter += 1 ;
257
- } else {
258
- str += output [ i ] ;
259
- }
260
- if ( output [ i ] === "^" ) {
261
- shouldBreak = true ;
262
- }
263
- if ( newLineCounter >= 3 ) {
247
+ function column ( output : string , messageEnd : number ) {
248
+ let newLineCounter = 0 ;
249
+ let str = "" ;
250
+ let shouldBreak = false ;
251
+ for ( let i = messageEnd ; i < output . length ; ++ i ) {
252
+ if ( output [ i ] === "\n" ) {
253
+ if ( shouldBreak ) {
264
254
break ;
265
255
}
256
+ str = "" ;
257
+ newLineCounter += 1 ;
258
+ } else {
259
+ str += output [ i ] ;
266
260
}
267
- let start = str . length ,
268
- end = 0 ;
269
- for ( let i = 0 ; i < str . length ; ++ i ) {
270
- if ( str [ i ] !== " " ) {
271
- start = Math . min ( i , start ) ;
272
- end = Math . max ( end , i ) ;
273
- }
261
+ if ( output [ i ] === "^" ) {
262
+ shouldBreak = true ;
274
263
}
275
- if ( start > end ) {
276
- return [ 0 , 10000 ] ;
264
+ if ( newLineCounter >= 3 ) {
265
+ break ;
277
266
}
278
- return [ start , end ] ;
279
267
}
268
+ let start = str . length ,
269
+ end = 0 ;
270
+ for ( let i = 0 ; i < str . length ; ++ i ) {
271
+ if ( str [ i ] !== " " ) {
272
+ start = Math . min ( i , start ) ;
273
+ end = Math . max ( end , i ) ;
274
+ }
275
+ }
276
+ if ( start > end ) {
277
+ return [ 0 , 10000 ] ;
278
+ }
279
+ return [ start , end ] ;
280
+ }
280
281
281
- private parseBuildLog ( buildLogFile : string , output : string , numberOfLines : number ) {
282
- const files : { [ key : string ] : vscode . Diagnostic [ ] } = { } ;
283
- try {
284
- let matches = [ ...output . matchAll ( this . problemPattern ) ] ;
285
- for ( const match of matches ) {
286
- const file = match [ 1 ] ;
287
- const line = Number ( match [ 2 ] ) - 1 ;
288
- const column = this . column ( output , ( match ?. index || 0 ) + match [ 0 ] . length ) ;
289
-
290
- const severity = match [ 4 ] ;
291
- const message = match [ 5 ] ;
292
- let errorSeverity = vscode . DiagnosticSeverity . Error ;
282
+ function parseBuildLog ( buildLogFile : string , output : string , numberOfLines : number ) {
283
+ const files : { [ key : string ] : vscode . Diagnostic [ ] } = { } ;
284
+ try {
285
+ let matches = [ ...output . matchAll ( problemPattern ) ] ;
286
+ for ( const match of matches ) {
287
+ const file = match [ 1 ] ;
288
+ const line = Number ( match [ 2 ] ) - 1 ;
289
+ const localColumn = column ( output , ( match ?. index || 0 ) + match [ 0 ] . length ) ;
293
290
294
- switch ( severity ) {
295
- case "warning" :
296
- errorSeverity = vscode . DiagnosticSeverity . Warning ;
297
- break ;
298
- case "note" :
299
- errorSeverity = vscode . DiagnosticSeverity . Information ;
300
- break ;
301
- default :
302
- break ;
303
- }
291
+ const severity = match [ 4 ] ;
292
+ const message = match [ 5 ] ;
293
+ let errorSeverity = vscode . DiagnosticSeverity . Error ;
304
294
305
- const diagnostic = new vscode . Diagnostic (
306
- new vscode . Range (
307
- new vscode . Position ( line , column [ 0 ] ) ,
308
- new vscode . Position ( line , column [ 1 ] )
309
- ) ,
310
- message ,
311
- errorSeverity
312
- ) ;
313
- diagnostic . source = ProblemDiagnosticResolver . xcodebuild ;
314
- const value = files [ file ] || [ ] ;
315
- value . push ( diagnostic ) ;
316
- if ( fs . existsSync ( file ) ) {
317
- files [ file ] = value ;
318
- }
295
+ switch ( severity ) {
296
+ case "warning" :
297
+ errorSeverity = vscode . DiagnosticSeverity . Warning ;
298
+ break ;
299
+ case "note" :
300
+ errorSeverity = vscode . DiagnosticSeverity . Information ;
301
+ break ;
302
+ default :
303
+ break ;
319
304
}
320
- // parsing linker errors
321
- matches = [ ...output . matchAll ( this . problemLinkerPattern ) ] ;
322
- for ( const match of matches ) {
323
- const file = buildLogFile ;
324
-
325
- let line = numberOfLines ;
326
- for ( let i = 0 ; i < ( match . index || 0 ) ; ++ i ) {
327
- line += output [ i ] === "\n" ? 1 : 0 ;
328
- }
329
-
330
- const message = match [ 3 ] ;
331
- const errorSeverity = vscode . DiagnosticSeverity . Error ;
332
305
333
- const diagnostic = new vscode . Diagnostic (
334
- new vscode . Range ( new vscode . Position ( line , 0 ) , new vscode . Position ( line , 0 ) ) ,
335
- message ,
336
- errorSeverity
337
- ) ;
338
- diagnostic . source = ProblemDiagnosticResolver . xcodebuild ;
339
- const value = files [ file ] || [ ] ;
340
- value . push ( diagnostic ) ;
306
+ const diagnostic = new vscode . Diagnostic (
307
+ new vscode . Range (
308
+ new vscode . Position ( line , localColumn [ 0 ] ) ,
309
+ new vscode . Position ( line , localColumn [ 1 ] )
310
+ ) ,
311
+ message ,
312
+ errorSeverity
313
+ ) ;
314
+ diagnostic . source = ProblemDiagnosticResolver . xcodebuild ;
315
+ const value = files [ file ] || [ ] ;
316
+ value . push ( diagnostic ) ;
317
+ if ( fs . existsSync ( file ) ) {
341
318
files [ file ] = value ;
342
319
}
343
- // parsing framework errors
344
- matches = [ ...output . matchAll ( this . frameworkErrorPattern ) ] ;
345
- for ( const match of matches ) {
346
- const file = buildLogFile ;
320
+ }
321
+ // parsing linker errors
322
+ matches = [ ...output . matchAll ( problemLinkerPattern ) ] ;
323
+ for ( const match of matches ) {
324
+ const file = buildLogFile ;
347
325
348
- let line = numberOfLines ;
349
- for ( let i = 0 ; i < ( match . index || 0 ) ; ++ i ) {
350
- line += output [ i ] === "\n" ? 1 : 0 ;
351
- }
326
+ let line = numberOfLines ;
327
+ for ( let i = 0 ; i < ( match . index || 0 ) ; ++ i ) {
328
+ line += output [ i ] === "\n" ? 1 : 0 ;
329
+ }
352
330
353
- const message = match [ 2 ] ;
354
- const errorSeverity = vscode . DiagnosticSeverity . Error ;
331
+ const message = match [ 3 ] ;
332
+ const errorSeverity = vscode . DiagnosticSeverity . Error ;
355
333
356
- const diagnostic = new vscode . Diagnostic (
357
- new vscode . Range ( new vscode . Position ( line , 0 ) , new vscode . Position ( line , 0 ) ) ,
358
- message ,
359
- errorSeverity
360
- ) ;
361
- diagnostic . source = ProblemDiagnosticResolver . xcodebuild ;
362
- const value = files [ file ] || [ ] ;
363
- value . push ( diagnostic ) ;
364
- files [ file ] = value ;
334
+ const diagnostic = new vscode . Diagnostic (
335
+ new vscode . Range ( new vscode . Position ( line , 0 ) , new vscode . Position ( line , 0 ) ) ,
336
+ message ,
337
+ errorSeverity
338
+ ) ;
339
+ diagnostic . source = ProblemDiagnosticResolver . xcodebuild ;
340
+ const value = files [ file ] || [ ] ;
341
+ value . push ( diagnostic ) ;
342
+ files [ file ] = value ;
343
+ }
344
+ // parsing framework errors
345
+ matches = [ ...output . matchAll ( frameworkErrorPattern ) ] ;
346
+ for ( const match of matches ) {
347
+ const file = buildLogFile ;
348
+
349
+ let line = numberOfLines ;
350
+ for ( let i = 0 ; i < ( match . index || 0 ) ; ++ i ) {
351
+ line += output [ i ] === "\n" ? 1 : 0 ;
365
352
}
366
- } catch ( err ) {
367
- console . log ( `Error parsing build logs: ${ err } ` ) ;
353
+
354
+ const message = match [ 2 ] ;
355
+ const errorSeverity = vscode . DiagnosticSeverity . Error ;
356
+
357
+ const diagnostic = new vscode . Diagnostic (
358
+ new vscode . Range ( new vscode . Position ( line , 0 ) , new vscode . Position ( line , 0 ) ) ,
359
+ message ,
360
+ errorSeverity
361
+ ) ;
362
+ diagnostic . source = ProblemDiagnosticResolver . xcodebuild ;
363
+ const value = files [ file ] || [ ] ;
364
+ value . push ( diagnostic ) ;
365
+ files [ file ] = value ;
368
366
}
369
- return files ;
367
+ } catch ( err ) {
368
+ console . log ( `Error parsing build logs: ${ err } ` ) ;
370
369
}
370
+ return files ;
371
371
}
372
+
373
+ export const _private = {
374
+ parseBuildLog,
375
+ } ;
0 commit comments