11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT license.
3- import * as path from "path" ;
43import * as vscode from "vscode" ;
54import { instrumentOperation , sendInfo , sendOperationError , setErrorCode } from "vscode-extension-telemetry-wrapper" ;
65
@@ -56,8 +55,9 @@ async function handleBuildFailure(operationId: string, err: any, progressReporte
5655 } ) ;
5756 setErrorCode ( error , Number ( err ) ) ;
5857 sendOperationError ( operationId , "build" , error ) ;
58+ const errorDiagnostics = traceErrorTypes ( operationId ) ;
5959 if ( ! onBuildFailureProceed && err ) {
60- if ( checkErrorsReportedByJavaExtension ( ) ) {
60+ if ( errorDiagnostics ) {
6161 vscode . commands . executeCommand ( "workbench.actions.view.problems" ) ;
6262 }
6363
@@ -79,18 +79,28 @@ async function handleBuildFailure(operationId: string, err: any, progressReporte
7979 return true ;
8080}
8181
82- function checkErrorsReportedByJavaExtension ( ) : boolean {
82+ function traceErrorTypes ( operationId : string ) : boolean {
8383 const problems = vscode . languages . getDiagnostics ( ) || [ ] ;
84+ const errorTypes : { [ key : string ] : number } = { } ;
85+ let errorCount = 0 ;
8486 for ( const problem of problems ) {
85- const fileName = path . basename ( problem [ 0 ] . fsPath || "" ) ;
86- if ( fileName . endsWith ( ".java" ) || fileName === "pom.xml" || fileName . endsWith ( ".gradle" ) ) {
87- if ( problem [ 1 ] . filter ( ( diagnostic ) => diagnostic . severity === vscode . DiagnosticSeverity . Error ) . length ) {
88- return true ;
87+ for ( const diagnostic of problem [ 1 ] ) {
88+ if ( diagnostic . severity === vscode . DiagnosticSeverity . Error && diagnostic . source === "Java" ) {
89+ const errorCode = typeof diagnostic . code === 'object' ? String ( diagnostic . code . value ) : String ( diagnostic . code ) ;
90+ errorTypes [ errorCode ] = ( errorTypes [ errorCode ] || 0 ) + 1 ;
91+ errorCount ++ ;
8992 }
9093 }
9194 }
9295
93- return false ;
96+ if ( errorCount ) {
97+ sendInfo ( operationId , {
98+ buildErrorTypes : JSON . stringify ( errorTypes ) ,
99+ buildErrorCount : errorCount ,
100+ } ) ;
101+ }
102+
103+ return errorCount > 0 ;
94104}
95105
96106async function showFixSuggestions ( operationId : string ) {
0 commit comments