66
77import { TPromise } from 'vs/base/common/winjs.base' ;
88import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
9- import * as errors from 'vs/base/common/errors' ;
109import URI from 'vs/base/common/uri' ;
1110import * as paths from 'vs/base/common/paths' ;
1211import { IEditorViewState } from 'vs/editor/common/editorCommon' ;
1312import { toResource , SideBySideEditorInput , IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor' ;
14- import { ITextFileService , ITextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles' ;
13+ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' ;
1514import { FileOperationEvent , FileOperation , IFileService , FileChangeType , FileChangesEvent } from 'vs/platform/files/common/files' ;
1615import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput' ;
1716import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle' ;
@@ -20,7 +19,6 @@ import { distinct } from 'vs/base/common/arrays';
2019import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
2120import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
2221import { isLinux } from 'vs/base/common/platform' ;
23- import { ResourceQueue } from 'vs/base/common/async' ;
2422import { ResourceMap } from 'vs/base/common/map' ;
2523import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
2624import { isCodeEditor } from 'vs/editor/browser/editorBrowser' ;
@@ -34,7 +32,6 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
3432
3533 protected closeOnFileDelete : boolean ;
3634
37- private modelLoadQueue : ResourceQueue ;
3835 private activeOutOfWorkspaceWatchers : ResourceMap < URI > ;
3936
4037 constructor (
@@ -50,7 +47,6 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
5047 ) {
5148 super ( ) ;
5249
53- this . modelLoadQueue = new ResourceQueue ( ) ;
5450 this . activeOutOfWorkspaceWatchers = new ResourceMap < URI > ( ) ;
5551
5652 this . onConfigurationUpdated ( configurationService . getValue < IWorkbenchEditorConfiguration > ( ) ) ;
@@ -101,7 +97,7 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
10197 } )
10298 . filter ( model => model && ! model . isDirty ( ) ) ,
10399 m => m . getResource ( ) . toString ( )
104- ) . forEach ( model => this . queueModelLoad ( model ) ) ;
100+ ) . forEach ( model => this . textFileService . models . reload ( model ) ) ;
105101 }
106102 }
107103
@@ -125,7 +121,9 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
125121 private onFileChanges ( e : FileChangesEvent ) : void {
126122
127123 // Handle updates
128- this . handleUpdates ( e ) ;
124+ if ( e . gotAdded ( ) || e . gotUpdated ( ) ) {
125+ this . handleUpdates ( e ) ;
126+ }
129127
130128 // Handle deletes
131129 if ( e . gotDeleted ( ) ) {
@@ -286,11 +284,23 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
286284
287285 private handleUpdates ( e : FileChangesEvent ) : void {
288286
287+ // Handle updates to text models
288+ this . handleUpdatesToTextModels ( e ) ;
289+
289290 // Handle updates to visible binary editors
290291 this . handleUpdatesToVisibleBinaryEditors ( e ) ;
292+ }
291293
292- // Handle updates to text models
293- this . handleUpdatesToTextModels ( e ) ;
294+ private handleUpdatesToTextModels ( e : FileChangesEvent ) : void {
295+
296+ // Collect distinct (saved) models to update.
297+ //
298+ // Note: we also consider the added event because it could be that a file was added
299+ // and updated right after.
300+ distinct ( [ ...e . getUpdated ( ) , ...e . getAdded ( ) ]
301+ . map ( u => this . textFileService . models . get ( u . resource ) )
302+ . filter ( model => model && ! model . isDirty ( ) ) , m => m . getResource ( ) . toString ( ) )
303+ . forEach ( model => this . textFileService . models . reload ( model ) ) ;
294304 }
295305
296306 private handleUpdatesToVisibleBinaryEditors ( e : FileChangesEvent ) : void {
@@ -313,29 +323,6 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
313323 } ) ;
314324 }
315325
316- private handleUpdatesToTextModels ( e : FileChangesEvent ) : void {
317-
318- // Collect distinct (saved) models to update.
319- //
320- // Note: we also consider the added event because it could be that a file was added
321- // and updated right after.
322- distinct ( [ ...e . getUpdated ( ) , ...e . getAdded ( ) ]
323- . map ( u => this . textFileService . models . get ( u . resource ) )
324- . filter ( model => model && ! model . isDirty ( ) ) , m => m . getResource ( ) . toString ( ) )
325- . forEach ( model => this . queueModelLoad ( model ) ) ;
326- }
327-
328- private queueModelLoad ( model : ITextFileEditorModel ) : void {
329-
330- // Load model to update (use a queue to prevent accumulation of loads
331- // when the load actually takes long. At most we only want the queue
332- // to have a size of 2 (1 running load and 1 queued load).
333- const queue = this . modelLoadQueue . queueFor ( model . getResource ( ) ) ;
334- if ( queue . size <= 1 ) {
335- queue . queue ( ( ) => model . load ( ) . then ( null , errors . onUnexpectedError ) ) ;
336- }
337- }
338-
339326 private handleOutOfWorkspaceWatchers ( ) : void {
340327 const visibleOutOfWorkspacePaths = new ResourceMap < URI > ( ) ;
341328 this . editorService . visibleEditors . map ( editorInput => {
0 commit comments