33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { IDisposable , dispose } from 'vs/base/common/lifecycle' ;
6+ import { DisposableStore } from 'vs/base/common/lifecycle' ;
77import { FileChangeType , IFileService , FileOperation } from 'vs/platform/files/common/files' ;
88import { extHostCustomer } from 'vs/workbench/api/common/extHostCustomers' ;
99import { ExtHostContext , FileSystemEvents , IExtHostContext } from '../common/extHost.protocol' ;
1010import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' ;
11+ import { IProgressService , ProgressLocation } from 'vs/platform/progress/common/progress' ;
12+ import { localize } from 'vs/nls' ;
1113
1214@extHostCustomer
1315export class MainThreadFileSystemEventService {
1416
15- private readonly _listener = new Array < IDisposable > ( ) ;
17+ private readonly _listener = new DisposableStore ( ) ;
1618
1719 constructor (
1820 extHostContext : IExtHostContext ,
1921 @IFileService fileService : IFileService ,
20- @ITextFileService textfileService : ITextFileService ,
22+ @ITextFileService textFileService : ITextFileService ,
23+ @IProgressService progressService : IProgressService
2124 ) {
2225
2326 const proxy = extHostContext . getProxy ( ExtHostContext . ExtHostFileSystemEventService ) ;
@@ -28,7 +31,7 @@ export class MainThreadFileSystemEventService {
2831 changed : [ ] ,
2932 deleted : [ ]
3033 } ;
31- fileService . onFileChanges ( event => {
34+ this . _listener . add ( fileService . onFileChanges ( event => {
3235 for ( let change of event . changes ) {
3336 switch ( change . type ) {
3437 case FileChangeType . ADDED :
@@ -47,22 +50,35 @@ export class MainThreadFileSystemEventService {
4750 events . created . length = 0 ;
4851 events . changed . length = 0 ;
4952 events . deleted . length = 0 ;
50- } , undefined , this . _listener ) ;
53+ } ) ) ;
5154
52- // file operation events - (changes the editor makes)
53- fileService . onAfterOperation ( e => {
54- if ( e . isOperation ( FileOperation . MOVE ) ) {
55- proxy . $onFileRename ( e . resource , e . target . resource ) ;
56- }
57- } , undefined , this . _listener ) ;
5855
59- textfileService . onWillMove ( e => {
60- const promise = proxy . $onWillRename ( e . oldResource , e . newResource ) ;
61- e . waitUntil ( promise ) ;
62- } , undefined , this . _listener ) ;
56+ // BEFORE file operation
57+ const messages = new Map < FileOperation , string > ( ) ;
58+ messages . set ( FileOperation . CREATE , localize ( 'msg-create' , "Running 'File Create' participants..." ) ) ;
59+ messages . set ( FileOperation . DELETE , localize ( 'msg-delete' , "Running 'File Delete' participants..." ) ) ;
60+ messages . set ( FileOperation . MOVE , localize ( 'msg-rename' , "Running 'File Rename' participants..." ) ) ;
61+
62+ this . _listener . add ( textFileService . onWillRunOperation ( e => {
63+ const p = progressService . withProgress ( { location : ProgressLocation . Window } , progress => {
64+
65+ progress . report ( { message : messages . get ( e . operation ) } ) ;
66+
67+ const p1 = proxy . $onWillRunFileOperation ( e . operation , e . target , e . source ) ;
68+ const p2 = new Promise ( ( _resolve , reject ) => {
69+ setTimeout ( ( ) => reject ( new Error ( 'timeout' ) ) , 5000 ) ;
70+ } ) ;
71+ return Promise . race ( [ p1 , p2 ] ) ;
72+ } ) ;
73+
74+ e . waitUntil ( p ) ;
75+ } ) ) ;
76+
77+ // AFTER file operation
78+ this . _listener . add ( textFileService . onDidRunOperation ( e => proxy . $onDidRunFileOperation ( e . operation , e . target , e . source ) ) ) ;
6379 }
6480
6581 dispose ( ) : void {
66- dispose ( this . _listener ) ;
82+ this . _listener . dispose ( ) ;
6783 }
6884}
0 commit comments