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

fix #85180

上级 07ad6851
......@@ -239,7 +239,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
if (confirm === ConfirmResult.SAVE) {
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
}
......@@ -492,9 +492,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
}
}
const result = await this.saveAll([resource], options);
return result.results.length === 1 && !!result.results[0].success;
return !(await this.saveAll([resource], options)).results.some(result => result.error);
}
saveAll(includeUntitled?: boolean, options?: ITextFileSaveOptions): Promise<ITextFileOperationResult>;
......@@ -560,7 +558,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
result.results.push({
source: untitledResources[index],
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
await Promise.all(dirtyFileModels.map(async model => {
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);
if (result) {
result.success = true;
result.error = true;
}
}
}));
......@@ -838,9 +837,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
}
async revert(resource: URI, options?: IRevertOptions): Promise<boolean> {
const result = await this.revertAll([resource], options);
return result.results.length === 1 && !!result.results[0].success;
return !(await this.revertAll([resource], options)).results.some(result => result.error);
}
async revertAll(resources?: URI[], options?: IRevertOptions): Promise<ITextFileOperationResult> {
......@@ -850,7 +847,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
// Revert untitled
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;
}
......@@ -869,20 +866,18 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
try {
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);
if (result) {
result.success = true;
result.error = true;
}
}
} 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) {
const result = mapResourceToResult.get(model.resource);
if (result) {
result.success = true;
}
return;
}
// Otherwise bubble up the error
......
......@@ -309,7 +309,7 @@ export interface ITextFileOperationResult {
export interface IResult {
source: URI;
target?: URI;
success?: boolean;
error?: boolean;
}
export const enum LoadReason {
......
......@@ -205,7 +205,7 @@ suite('Files - TextFileService', () => {
const res = await accessor.textFileService.saveAll(true);
assert.ok(loadOrCreateStub.calledOnce);
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!.authority, untitledUncUri.authority);
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.
先完成此消息的编辑!
想要评论请 注册