@@ -19,21 +19,58 @@ import { l10n } from "../localiser";
1919import { extCommands , nbCommands } from "./commands" ;
2020import { ICommand } from "./types" ;
2121import { wrapCommandWithProgress , wrapProjectActionWithProgress } from "./utils" ;
22+ import { workspace } from "vscode" ;
23+ import * as fs from 'fs' ;
24+
25+ const saveFilesInWorkspaceBeforeBuild = async ( callbackFn : Function ) => {
26+ const docsTosave : Thenable < boolean > [ ] = workspace . textDocuments .
27+ filter ( d => fs . existsSync ( d . uri . fsPath ) ) .
28+ map ( d => d . save ( ) ) ;
29+ await Promise . all ( docsTosave ) ;
30+
31+ return callbackFn ( ) ;
32+ }
2233
2334const compileWorkspaceHandler = ( ) => {
24- return wrapCommandWithProgress ( nbCommands . buildWorkspace , l10n . value ( 'jdk.extension.command.progress.compilingWorkSpace' ) , LOGGER . getOutputChannel ( ) ) ;
35+ const complileFunction = ( ) =>
36+ wrapCommandWithProgress ( nbCommands . buildWorkspace ,
37+ l10n . value ( 'jdk.extension.command.progress.compilingWorkSpace' ) ,
38+ LOGGER . getOutputChannel ( )
39+ ) ;
40+
41+ return saveFilesInWorkspaceBeforeBuild ( complileFunction ) ;
2542}
2643
2744const cleanWorkspaceHandler = ( ) => {
28- return wrapCommandWithProgress ( nbCommands . cleanWorkspace , l10n . value ( 'jdk.extension.command.progress.cleaningWorkSpace' ) , LOGGER . getOutputChannel ( ) ) ;
45+ const cleanFunction = ( ) => wrapCommandWithProgress (
46+ nbCommands . cleanWorkspace ,
47+ l10n . value ( 'jdk.extension.command.progress.cleaningWorkSpace' ) ,
48+ LOGGER . getOutputChannel ( )
49+ ) ;
50+
51+ return saveFilesInWorkspaceBeforeBuild ( cleanFunction ) ;
2952}
3053
3154const compileProjectHandler = ( args : any ) => {
32- wrapProjectActionWithProgress ( 'build' , undefined , l10n . value ( 'jdk.extension.command.progress.compilingProject' ) , LOGGER . getOutputChannel ( ) , args ) ;
55+ const compileProjectFunction = ( ) =>
56+ wrapProjectActionWithProgress ( 'build' ,
57+ undefined , l10n . value ( 'jdk.extension.command.progress.compilingProject' ) ,
58+ LOGGER . getOutputChannel ( ) ,
59+ args
60+ ) ;
61+
62+ saveFilesInWorkspaceBeforeBuild ( compileProjectFunction ) ;
3363}
3464
3565const cleanProjectHandler = ( args : any ) => {
36- wrapProjectActionWithProgress ( 'clean' , undefined , l10n . value ( 'jdk.extension.command.progress.cleaningProject' ) , LOGGER . getOutputChannel ( ) , args ) ;
66+ const cleanProjectHandler = ( ) => wrapProjectActionWithProgress ( 'clean' ,
67+ undefined ,
68+ l10n . value ( 'jdk.extension.command.progress.cleaningProject' ) ,
69+ LOGGER . getOutputChannel ( ) ,
70+ args
71+ ) ;
72+
73+ saveFilesInWorkspaceBeforeBuild ( cleanProjectHandler ) ;
3774}
3875
3976
@@ -44,10 +81,10 @@ export const registerBuildOperationCommands: ICommand[] = [
4481 } , {
4582 command : extCommands . cleanWorkspace ,
4683 handler : cleanWorkspaceHandler
47- } , {
84+ } , {
4885 command : extCommands . compileProject ,
4986 handler : compileProjectHandler
50- } , {
87+ } , {
5188 command : extCommands . cleanProject ,
5289 handler : cleanProjectHandler
5390 }
0 commit comments