Skip to content

Commit 2902a13

Browse files
author
Benjamin Pasero
committed
Editor: load changes to file in the background if file already loaded (fixes microsoft#53532)
1 parent e0a5cf1 commit 2902a13

24 files changed

Lines changed: 102 additions & 95 deletions

File tree

src/vs/workbench/browser/parts/editor/binaryEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
7373

7474
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Thenable<void> {
7575
return super.setInput(input, options, token).then(() => {
76-
return input.resolve(true).then(model => {
76+
return input.resolve().then(model => {
7777

7878
// Check for cancellation
7979
if (token.isCancellationRequested) {

src/vs/workbench/browser/parts/editor/textDiffEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
104104

105105
// Set input and resolve
106106
return super.setInput(input, options, token).then(() => {
107-
return input.resolve(true).then(resolvedModel => {
107+
return input.resolve().then(resolvedModel => {
108108

109109
// Check for cancellation
110110
if (token.isCancellationRequested) {

src/vs/workbench/browser/parts/editor/textResourceEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class AbstractTextResourceEditor extends BaseTextEditor {
6161

6262
// Set input and resolve
6363
return super.setInput(input, options, token).then(() => {
64-
return input.resolve(true).then((resolvedModel: EditorModel) => {
64+
return input.resolve().then((resolvedModel: EditorModel) => {
6565

6666
// Check for cancellation
6767
if (token.isCancellationRequested) {

src/vs/workbench/common/editor.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,9 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
395395

396396
/**
397397
* Returns a type of EditorModel that represents the resolved input. Subclasses should
398-
* override to provide a meaningful model. The optional second argument allows to specify
399-
* if the EditorModel should be refreshed before returning it. Depending on the implementation
400-
* this could mean to refresh the editor model contents with the version from disk.
398+
* override to provide a meaningful model.
401399
*/
402-
abstract resolve(refresh?: boolean): TPromise<IEditorModel>;
400+
abstract resolve(): TPromise<IEditorModel>;
403401

404402
/**
405403
* An editor that is dirty will be asked to be saved once it closes.
@@ -582,7 +580,7 @@ export class SideBySideEditorInput extends EditorInput {
582580
this._register(this.master.onDidChangeLabel(() => this._onDidChangeLabel.fire()));
583581
}
584582

585-
resolve(refresh?: boolean): TPromise<EditorModel> {
583+
resolve(): TPromise<EditorModel> {
586584
return TPromise.as(null);
587585
}
588586

src/vs/workbench/common/editor/dataUriEditorInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class DataUriEditorInput extends EditorInput {
6565
return this.description;
6666
}
6767

68-
resolve(refresh?: boolean): TPromise<BinaryEditorModel> {
68+
resolve(): TPromise<BinaryEditorModel> {
6969
return this.instantiationService.createInstance(BinaryEditorModel, this.resource, this.getName()).load().then(m => m as BinaryEditorModel);
7070
}
7171

src/vs/workbench/common/editor/diffEditorInput.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,13 @@ export class DiffEditorInput extends SideBySideEditorInput {
3636
return this.master;
3737
}
3838

39-
resolve(refresh?: boolean): TPromise<EditorModel> {
40-
let modelPromise: TPromise<EditorModel>;
41-
42-
// Use Cached Model
43-
if (this.cachedModel && !refresh) {
44-
modelPromise = TPromise.as<EditorModel>(this.cachedModel);
45-
}
39+
resolve(): TPromise<EditorModel> {
4640

4741
// Create Model - we never reuse our cached model if refresh is true because we cannot
4842
// decide for the inputs within if the cached model can be reused or not. There may be
4943
// inputs that need to be loaded again and thus we always recreate the model and dispose
5044
// the previous one - if any.
51-
else {
52-
modelPromise = this.createModel(refresh);
53-
}
54-
55-
return modelPromise.then((resolvedModel: DiffEditorModel) => {
45+
return this.createModel().then(resolvedModel => {
5646
if (this.cachedModel) {
5747
this.cachedModel.dispose();
5848
}
@@ -71,9 +61,9 @@ export class DiffEditorInput extends SideBySideEditorInput {
7161

7262
// Join resolve call over two inputs and build diff editor model
7363
return TPromise.join([
74-
this.originalInput.resolve(refresh),
75-
this.modifiedInput.resolve(refresh)
76-
]).then((models) => {
64+
this.originalInput.resolve(),
65+
this.modifiedInput.resolve()
66+
]).then(models => {
7767
const originalEditorModel = models[0];
7868
const modifiedEditorModel = models[1];
7969

src/vs/workbench/common/editor/resourceEditorInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ResourceEditorInput extends EditorInput {
8282
return descriptor;
8383
}
8484

85-
resolve(refresh?: boolean): TPromise<ITextEditorModel> {
85+
resolve(): TPromise<ITextEditorModel> {
8686
if (!this.modelReference) {
8787
this.modelReference = this.textModelResolverService.createModelReference(this.resource);
8888
}

src/vs/workbench/parts/extensions/common/extensionsInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class ExtensionsInput extends EditorInput {
4444
return this.extension === otherExtensionInput.extension;
4545
}
4646

47-
resolve(refresh?: boolean): TPromise<any> {
47+
resolve(): TPromise<any> {
4848
return TPromise.as(null);
4949
}
5050

src/vs/workbench/parts/extensions/electron-browser/runtimeExtensionsEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export class RuntimeExtensionsInput extends EditorInput {
443443
return true;
444444
}
445445

446-
resolve(refresh?: boolean): TPromise<any> {
446+
resolve(): TPromise<any> {
447447
return TPromise.as(null);
448448
}
449449

src/vs/workbench/parts/files/browser/editors/fileEditorTracker.ts

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
import { TPromise } from 'vs/base/common/winjs.base';
88
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
9-
import * as errors from 'vs/base/common/errors';
109
import URI from 'vs/base/common/uri';
1110
import * as paths from 'vs/base/common/paths';
1211
import { IEditorViewState } from 'vs/editor/common/editorCommon';
1312
import { 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';
1514
import { FileOperationEvent, FileOperation, IFileService, FileChangeType, FileChangesEvent } from 'vs/platform/files/common/files';
1615
import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput';
1716
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
@@ -20,7 +19,6 @@ import { distinct } from 'vs/base/common/arrays';
2019
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
2120
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2221
import { isLinux } from 'vs/base/common/platform';
23-
import { ResourceQueue } from 'vs/base/common/async';
2422
import { ResourceMap } from 'vs/base/common/map';
2523
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
2624
import { 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

Comments
 (0)