Skip to content

Commit f1c6f2c

Browse files
author
Benjamin Pasero
committed
text files - move save error handler into files model manager
1 parent 2d125bc commit f1c6f2c

8 files changed

Lines changed: 20 additions & 30 deletions

File tree

src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class TextFileSaveErrorHandler extends Disposable implements ISaveErrorHa
6464
this._register(textModelService.registerTextModelContentProvider(CONFLICT_RESOLUTION_SCHEME, provider));
6565

6666
// Set as save error handler to service for text files
67-
this.textFileService.saveErrorHandler = this;
67+
this.textFileService.files.saveErrorHandler = this;
6868

6969
this.registerListeners();
7070
}

src/vs/workbench/services/textfile/browser/textFileService.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'
3333
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
3434
import { coalesce } from 'vs/base/common/arrays';
3535
import { suggestFilename } from 'vs/base/common/mime';
36-
import { INotificationService } from 'vs/platform/notification/common/notification';
37-
import { toErrorMessage } from 'vs/base/common/errorMessage';
3836
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
3937
import { isValidBasename } from 'vs/base/common/extpath';
4038

@@ -59,16 +57,6 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
5957

6058
readonly untitled: IUntitledTextEditorModelManager = this.untitledTextEditorService;
6159

62-
saveErrorHandler = (() => {
63-
const notificationService = this.notificationService;
64-
65-
return {
66-
onSaveError(error: Error, model: ITextFileEditorModel): void {
67-
notificationService.error(nls.localize('genericSaveError', "Failed to save '{0}': {1}", model.name, toErrorMessage(error, false)));
68-
}
69-
};
70-
})();
71-
7260
abstract get encoding(): IResourceEncodings;
7361

7462
constructor(
@@ -84,7 +72,6 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
8472
@IFilesConfigurationService protected readonly filesConfigurationService: IFilesConfigurationService,
8573
@ITextModelService private readonly textModelService: ITextModelService,
8674
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
87-
@INotificationService private readonly notificationService: INotificationService,
8875
@IRemotePathService private readonly remotePathService: IRemotePathService
8976
) {
9077
super();

src/vs/workbench/services/textfile/common/textFileEditorModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
738738
}
739739

740740
// Show to user
741-
this.textFileService.saveErrorHandler.onSaveError(error, this);
741+
this.textFileService.files.saveErrorHandler.onSaveError(error, this);
742742

743743
// Emit as event
744744
this._onDidSaveError.fire();

src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { localize } from 'vs/nls';
7+
import { toErrorMessage } from 'vs/base/common/errorMessage';
68
import { Emitter } from 'vs/base/common/event';
79
import { URI } from 'vs/base/common/uri';
810
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
@@ -18,6 +20,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
1820
import { TextFileSaveParticipant } from 'vs/workbench/services/textfile/common/textFileSaveParticipant';
1921
import { SaveReason } from 'vs/workbench/common/editor';
2022
import { CancellationToken } from 'vs/base/common/cancellation';
23+
import { INotificationService } from 'vs/platform/notification/common/notification';
2124

2225
export class TextFileEditorModelManager extends Disposable implements ITextFileEditorModelManager {
2326

@@ -42,6 +45,16 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE
4245
private readonly _onDidChangeOrphaned = this._register(new Emitter<ITextFileEditorModel>());
4346
readonly onDidChangeOrphaned = this._onDidChangeOrphaned.event;
4447

48+
saveErrorHandler = (() => {
49+
const notificationService = this.notificationService;
50+
51+
return {
52+
onSaveError(error: Error, model: ITextFileEditorModel): void {
53+
notificationService.error(localize('genericSaveError', "Failed to save '{0}': {1}", model.name, toErrorMessage(error, false)));
54+
}
55+
};
56+
})();
57+
4558
private readonly mapResourceToModel = new ResourceMap<ITextFileEditorModel>();
4659
private readonly mapResourceToModelListeners = new ResourceMap<IDisposable>();
4760
private readonly mapResourceToDisposeListener = new ResourceMap<IDisposable>();
@@ -52,7 +65,8 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE
5265
constructor(
5366
@ILifecycleService private readonly lifecycleService: ILifecycleService,
5467
@IInstantiationService private readonly instantiationService: IInstantiationService,
55-
@IFileService private readonly fileService: IFileService
68+
@IFileService private readonly fileService: IFileService,
69+
@INotificationService private readonly notificationService: INotificationService
5670
) {
5771
super();
5872

src/vs/workbench/services/textfile/common/textfiles.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ export interface ITextFileService extends IDisposable {
5252
*/
5353
readonly encoding: IResourceEncodings;
5454

55-
/**
56-
* The handler that should be called when saving fails. Can be overridden
57-
* to handle save errors in a custom way.
58-
*/
59-
saveErrorHandler: ISaveErrorHandler;
60-
6155
/**
6256
* A resource is dirty if it has unsaved changes or is an untitled file not yet saved.
6357
*
@@ -377,6 +371,8 @@ export interface ITextFileEditorModelManager {
377371
addSaveParticipant(participant: ITextFileSaveParticipant): IDisposable;
378372
runSaveParticipants(model: IResolvedTextFileEditorModel, context: { reason: SaveReason; }, token: CancellationToken): Promise<void>
379373

374+
saveErrorHandler: ISaveErrorHandler;
375+
380376
disposeModel(model: ITextFileEditorModel): void;
381377
}
382378

src/vs/workbench/services/textfile/electron-browser/nativeTextFileService.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { assign } from 'vs/base/common/objects';
3737
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
3838
import { ITextModelService } from 'vs/editor/common/services/resolverService';
3939
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
40-
import { INotificationService } from 'vs/platform/notification/common/notification';
4140
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
4241

4342
export class NativeTextFileService extends AbstractTextFileService {
@@ -56,10 +55,9 @@ export class NativeTextFileService extends AbstractTextFileService {
5655
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
5756
@ITextModelService textModelService: ITextModelService,
5857
@ICodeEditorService codeEditorService: ICodeEditorService,
59-
@INotificationService notificationService: INotificationService,
6058
@IRemotePathService remotePathService: IRemotePathService
6159
) {
62-
super(fileService, untitledTextEditorService, lifecycleService, instantiationService, modelService, environmentService, dialogService, fileDialogService, textResourceConfigurationService, filesConfigurationService, textModelService, codeEditorService, notificationService, remotePathService);
60+
super(fileService, untitledTextEditorService, lifecycleService, instantiationService, modelService, environmentService, dialogService, fileDialogService, textResourceConfigurationService, filesConfigurationService, textModelService, codeEditorService, remotePathService);
6361
}
6462

6563
private _encoding: EncodingOracle | undefined;

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export class TestTextFileService extends BrowserTextFileService {
121121
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
122122
@ITextModelService textModelService: ITextModelService,
123123
@ICodeEditorService codeEditorService: ICodeEditorService,
124-
@INotificationService notificationService: INotificationService,
125124
@IRemotePathService remotePathService: IRemotePathService
126125
) {
127126
super(
@@ -137,7 +136,6 @@ export class TestTextFileService extends BrowserTextFileService {
137136
filesConfigurationService,
138137
textModelService,
139138
codeEditorService,
140-
notificationService,
141139
remotePathService
142140
);
143141
}

src/vs/workbench/test/electron-browser/workbenchTestServices.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { IProductService } from 'vs/platform/product/common/productService';
2222
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
2323
import { ITextModelService } from 'vs/editor/common/services/resolverService';
2424
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
25-
import { INotificationService } from 'vs/platform/notification/common/notification';
2625
import { URI } from 'vs/base/common/uri';
2726
import { IReadTextFileOptions, ITextFileStreamContent, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
2827
import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel';
@@ -62,7 +61,6 @@ export class TestTextFileService extends NativeTextFileService {
6261
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
6362
@ITextModelService textModelService: ITextModelService,
6463
@ICodeEditorService codeEditorService: ICodeEditorService,
65-
@INotificationService notificationService: INotificationService,
6664
@IRemotePathService remotePathService: IRemotePathService
6765
) {
6866
super(
@@ -79,7 +77,6 @@ export class TestTextFileService extends NativeTextFileService {
7977
filesConfigurationService,
8078
textModelService,
8179
codeEditorService,
82-
notificationService,
8380
remotePathService
8481
);
8582
}

0 commit comments

Comments
 (0)