This commit is contained in:
Benjamin Pasero
2018-07-05 15:55:28 +02:00
parent 394cd30a2c
commit e283c32b9d
4 changed files with 22 additions and 3 deletions

View File

@@ -689,8 +689,7 @@ suite('workspace-namespace', () => {
we = new vscode.WorkspaceEdit();
we.createFile(docUri, { overwrite: true });
assert.ok(await vscode.workspace.applyEdit(we));
// todo@ben
// assert.equal((await vscode.workspace.openTextDocument(docUri)).getText(), '');
assert.equal((await vscode.workspace.openTextDocument(docUri)).getText(), '');
});
test('WorkspaceEdit: create & ignoreIfExists', async function () {

View File

@@ -343,7 +343,7 @@ export class BulkEdit {
} else if (edit.newUri && !edit.oldUri) {
let ignoreIfExists = edit.options && edit.options.ignoreIfExists;
if (!ignoreIfExists || !await this._fileService.existsFile(edit.newUri)) {
await this._fileService.createFile(edit.newUri, undefined, { overwrite });
await this._textFileService.create(edit.newUri, undefined, { overwrite });
}
}
}

View File

@@ -692,6 +692,20 @@ export abstract class TextFileService extends Disposable implements ITextFileSer
});
}
create(resource: URI, contents?: string, options?: { overwrite?: boolean }): TPromise<void> {
return this.fileService.createFile(resource, contents, options).then(() => {
// If we had an existing model for the given resource, load
// it again to make sure it is up to date with the contents
// we just wrote into the underlying resource.
if (!!this.models.get(resource)) {
return this.models.loadOrCreate(resource, { reload: { async: false } }).then(() => void 0);
}
return void 0;
});
}
delete(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): TPromise<void> {
const dirtyFiles = this.getDirty().filter(dirty => isEqualOrParent(dirty, resource, !platform.isLinux /* ignorecase */));

View File

@@ -328,6 +328,12 @@ export interface ITextFileService extends IDisposable {
*/
revertAll(resources?: URI[], options?: IRevertOptions): TPromise<ITextFileOperationResult>;
/**
* Create a file. If the file exists it will be overwritten with the contents if
* the options enable to overwrite.
*/
create(resource: URI, contents?: string, options?: { overwrite?: boolean }): TPromise<void>;
/**
* Delete a file. If the file is dirty, it will get reverted and then deleted from disk.
*/