@@ -11,6 +11,7 @@ import * as utility from "./utility";
1111
1212const JAVA_DEBUG_CONFIGURATION = "java.debug.settings" ;
1313const ON_BUILD_FAILURE_PROCEED = "onBuildFailureProceed" ;
14+ const CANCELLED_CODE = - 32800 ;
1415
1516enum CompileWorkspaceStatus {
1617 FAILED = 0 ,
@@ -19,25 +20,44 @@ enum CompileWorkspaceStatus {
1920 CANCELLED = 3 ,
2021}
2122
22- export async function buildWorkspace ( progressReporter : IProgressReporter ) : Promise < boolean > {
23+ export interface BuildParams {
24+ readonly mainClass : string ;
25+ readonly projectName ?: string ;
26+ readonly filePath ?: string ;
27+ readonly isFullBuild : boolean ;
28+ }
29+
30+ export async function buildWorkspace ( params : BuildParams , progressReporter : IProgressReporter ) : Promise < boolean > {
31+ const startAt = new Date ( ) . getTime ( ) ;
2332 const buildResult = await instrumentOperation ( "build" , async ( operationId : string ) => {
24- let error ;
33+ let status ;
2534 try {
26- await commands . executeJavaExtensionCommand ( commands . JAVA_BUILD_WORKSPACE , false , progressReporter . getCancellationToken ( ) ) ;
35+ status = await commands . executeJavaLanguageServerCommand ( commands . JAVA_BUILD_WORKSPACE ,
36+ JSON . stringify ( params ) ,
37+ progressReporter . getCancellationToken ( ) ) ;
2738 } catch ( err ) {
28- error = err ;
39+ status = ( err && err . code === CANCELLED_CODE ) ? CompileWorkspaceStatus . CANCELLED : err ;
2940 }
3041
3142 return {
32- error ,
43+ status ,
3344 operationId,
3445 } ;
3546 } ) ( ) ;
3647
37- if ( progressReporter . isCancelled ( ) || buildResult . error === CompileWorkspaceStatus . CANCELLED ) {
48+ if ( progressReporter . isCancelled ( ) || buildResult . status === CompileWorkspaceStatus . CANCELLED ) {
3849 return false ;
50+ } else if ( buildResult . status === CompileWorkspaceStatus . SUCCEED ) {
51+ return true ;
3952 } else {
40- return handleBuildFailure ( buildResult . operationId , buildResult . error , progressReporter ) ;
53+ const elapsed = new Date ( ) . getTime ( ) - startAt ;
54+ const humanVisibleDelay = elapsed < 150 ? 150 : 0 ;
55+ await new Promise ( resolve => {
56+ setTimeout ( ( ) => { // set a timeout so user still can see a compiling message.
57+ resolve ( null ) ;
58+ } , humanVisibleDelay ) ;
59+ } ) ;
60+ return handleBuildFailure ( buildResult . operationId , buildResult . status , progressReporter ) ;
4161 }
4262}
4363
@@ -62,12 +82,16 @@ async function handleBuildFailure(operationId: string, err: any, progressReporte
6282 }
6383
6484 progressReporter . hide ( true ) ;
65- const ans = await vscode . window . showErrorMessage ( "Build failed, do you want to continue?" , "Proceed " , "Fix... " , "Cancel " ) ;
85+ const ans = await vscode . window . showErrorMessage ( "Build failed, do you want to continue?" , "Continue " , "Always Continue " , "Fix... " ) ;
6686 sendInfo ( operationId , {
6787 operationName : "build" ,
6888 choiceForBuildError : ans || "esc" ,
6989 } ) ;
70- if ( ans === "Proceed" ) {
90+ if ( ans === "Continue" ) {
91+ return true ;
92+ } else if ( ans === "Always Continue" ) {
93+ const debugSettings : vscode . WorkspaceConfiguration = vscode . workspace . getConfiguration ( "java.debug.settings" ) ;
94+ debugSettings ?. update ( "onBuildFailureProceed" , true ) ;
7195 return true ;
7296 } else if ( ans === "Fix..." ) {
7397 showFixSuggestions ( operationId ) ;
0 commit comments