提交 e2e55d63 编写于 作者: B Benjamin Pasero

fix #85180

上级 07ad6851
...@@ -239,7 +239,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex ...@@ -239,7 +239,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
if (confirm === ConfirmResult.SAVE) { if (confirm === ConfirmResult.SAVE) {
const result = await this.saveAll(true /* includeUntitled */, { skipSaveParticipants: true }); const result = await this.saveAll(true /* includeUntitled */, { skipSaveParticipants: true });
if (result.results.some(r => !r.success)) { if (result.results.some(r => r.error)) {
return true; // veto if some saves failed return true; // veto if some saves failed
} }
...@@ -492,9 +492,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex ...@@ -492,9 +492,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
} }
} }
const result = await this.saveAll([resource], options); return !(await this.saveAll([resource], options)).results.some(result => result.error);
return result.results.length === 1 && !!result.results[0].success;
} }
saveAll(includeUntitled?: boolean, options?: ITextFileSaveOptions): Promise<ITextFileOperationResult>; saveAll(includeUntitled?: boolean, options?: ITextFileSaveOptions): Promise<ITextFileOperationResult>;
...@@ -560,7 +558,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex ...@@ -560,7 +558,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
result.results.push({ result.results.push({
source: untitledResources[index], source: untitledResources[index],
target: uri, target: uri,
success: !!uri error: !uri // the operation was canceled or failed, so mark as error
}); });
})); }));
...@@ -648,10 +646,11 @@ export abstract class AbstractTextFileService extends Disposable implements ITex ...@@ -648,10 +646,11 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
await Promise.all(dirtyFileModels.map(async model => { await Promise.all(dirtyFileModels.map(async model => {
await model.save(options); await model.save(options);
if (!model.isDirty()) { // If model is still dirty, mark the resulting operation as error
if (model.isDirty()) {
const result = mapResourceToResult.get(model.resource); const result = mapResourceToResult.get(model.resource);
if (result) { if (result) {
result.success = true; result.error = true;
} }
} }
})); }));
...@@ -838,9 +837,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex ...@@ -838,9 +837,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
} }
async revert(resource: URI, options?: IRevertOptions): Promise<boolean> { async revert(resource: URI, options?: IRevertOptions): Promise<boolean> {
const result = await this.revertAll([resource], options); return !(await this.revertAll([resource], options)).results.some(result => result.error);
return result.results.length === 1 && !!result.results[0].success;
} }
async revertAll(resources?: URI[], options?: IRevertOptions): Promise<ITextFileOperationResult> { async revertAll(resources?: URI[], options?: IRevertOptions): Promise<ITextFileOperationResult> {
...@@ -850,7 +847,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex ...@@ -850,7 +847,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
// Revert untitled // Revert untitled
const untitledReverted = this.untitledTextEditorService.revertAll(resources); const untitledReverted = this.untitledTextEditorService.revertAll(resources);
untitledReverted.forEach(untitled => revertOperationResult.results.push({ source: untitled, success: true })); untitledReverted.forEach(untitled => revertOperationResult.results.push({ source: untitled }));
return revertOperationResult; return revertOperationResult;
} }
...@@ -869,20 +866,18 @@ export abstract class AbstractTextFileService extends Disposable implements ITex ...@@ -869,20 +866,18 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
try { try {
await model.revert(options); await model.revert(options);
if (!model.isDirty()) { // If model is still dirty, mark the resulting operation as error
if (model.isDirty()) {
const result = mapResourceToResult.get(model.resource); const result = mapResourceToResult.get(model.resource);
if (result) { if (result) {
result.success = true; result.error = true;
} }
} }
} catch (error) { } catch (error) {
// FileNotFound means the file got deleted meanwhile, so still record as successful revert // FileNotFound means the file got deleted meanwhile, so ignore it
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) { if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) {
const result = mapResourceToResult.get(model.resource); return;
if (result) {
result.success = true;
}
} }
// Otherwise bubble up the error // Otherwise bubble up the error
......
...@@ -309,7 +309,7 @@ export interface ITextFileOperationResult { ...@@ -309,7 +309,7 @@ export interface ITextFileOperationResult {
export interface IResult { export interface IResult {
source: URI; source: URI;
target?: URI; target?: URI;
success?: boolean; error?: boolean;
} }
export const enum LoadReason { export const enum LoadReason {
......
...@@ -205,7 +205,7 @@ suite('Files - TextFileService', () => { ...@@ -205,7 +205,7 @@ suite('Files - TextFileService', () => {
const res = await accessor.textFileService.saveAll(true); const res = await accessor.textFileService.saveAll(true);
assert.ok(loadOrCreateStub.calledOnce); assert.ok(loadOrCreateStub.calledOnce);
assert.equal(res.results.length, 1); assert.equal(res.results.length, 1);
assert.ok(res.results[0].success); assert.ok(!res.results[0].error);
assert.equal(res.results[0].target!.scheme, Schemas.file); assert.equal(res.results[0].target!.scheme, Schemas.file);
assert.equal(res.results[0].target!.authority, untitledUncUri.authority); assert.equal(res.results[0].target!.authority, untitledUncUri.authority);
assert.equal(res.results[0].target!.path, untitledUncUri.path); assert.equal(res.results[0].target!.path, untitledUncUri.path);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册