Skip to content

Commit

Permalink
add ignoreIfExists-option #10659
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 20, 2018
1 parent 991b74b commit 257ae9f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,12 @@ suite('workspace-namespace', () => {
// todo@ben
// assert.equal((await vscode.workspace.openTextDocument(docUri)).getText(), '');
});

test('WorkspaceEdit: create & ignoreIfExists', async function () {
let docUri = await createRandomFile('before');
let we = new vscode.WorkspaceEdit();
we.createFile(docUri, { ignoreIfExists: true });
assert.ok(await vscode.workspace.applyEdit(we));
assert.equal((await vscode.workspace.openTextDocument(docUri)).getText(), 'before');
});
});
2 changes: 1 addition & 1 deletion src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ export function isResourceTextEdit(thing: any): thing is ResourceTextEdit {
export interface ResourceFileEdit {
oldUri: URI;
newUri: URI;
options: { overwrite: boolean };
options: { overwrite?: boolean, ignoreIfExists?: boolean };
}

export interface ResourceTextEdit {
Expand Down
3 changes: 2 additions & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5101,7 +5101,8 @@ declare namespace monaco.languages {
oldUri: Uri;
newUri: Uri;
options: {
overwrite: boolean;
overwrite?: boolean;
ignoreIfExists?: boolean;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ declare module 'vscode' {
//#region joh: https://github.com/Microsoft/vscode/issues/10659

export interface WorkspaceEdit {
createFile(uri: Uri, options?: { overwrite?: boolean }): void;
createFile(uri: Uri, options?: { overwrite?: boolean, ignoreIfExists?: boolean }): void;
deleteFile(uri: Uri): void;
renameFile(oldUri: Uri, newUri: Uri, options?: { overwrite?: boolean }): void;

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ export interface WorkspaceSymbolsDto extends IdObject {
export interface ResourceFileEditDto {
oldUri: UriComponents;
newUri: UriComponents;
options: { overwrite?: boolean };
options: { overwrite?: boolean, ignoreIfExists?: boolean };
}

export interface ResourceTextEditDto {
Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/api/node/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export interface IFileOperation {
_type: 1;
from: URI;
to: URI;
options?: { overwrite?: boolean };
options?: { overwrite?: boolean, ignoreIfExists?: boolean; };
}

export interface IFileTextEdit {
Expand All @@ -516,12 +516,12 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit {
this._edits.push({ _type: 1, from, to, options });
}

createFile(uri: vscode.Uri, options?: { overwrite?: boolean }): void {
this.renameFile(undefined, uri, options);
createFile(uri: vscode.Uri, options?: { overwrite?: boolean, ignoreIfExists?: boolean }): void {
this._edits.push({ _type: 1, from: undefined, to: uri, options });
}

deleteFile(uri: vscode.Uri): void {
this.renameFile(uri, undefined);
this._edits.push({ _type: 1, from: uri, to: undefined });
}

replace(uri: URI, range: Range, newText: string): void {
Expand Down Expand Up @@ -593,8 +593,8 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit {
return values(textEdits);
}

allEntries(): ([URI, TextEdit[]] | [URI, URI, { overwrite?: boolean }])[] {
let res: ([URI, TextEdit[]] | [URI, URI, { overwrite?: boolean }])[] = [];
allEntries(): ([URI, TextEdit[]] | [URI, URI, { overwrite?: boolean, ignoreIfExists?: boolean }])[] {
let res: ([URI, TextEdit[]] | [URI, URI, { overwrite?: boolean, ignoreIfExists?: boolean }])[] = [];
for (let edit of this._edits) {
if (edit._type === 1) {
res.push([edit.from, edit.to, edit.options]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ export class BulkEdit {
} else if (!edit.newUri && edit.oldUri) {
await this._textFileService.delete(edit.oldUri, true);
} else if (edit.newUri && !edit.oldUri) {
await this._fileService.createFile(edit.newUri, undefined, { overwrite });
let ignoreIfExists = edit.options && edit.options.ignoreIfExists;
if (!ignoreIfExists || !await this._fileService.existsFile(edit.newUri)) {
await this._fileService.createFile(edit.newUri, undefined, { overwrite });
}
}
}
}
Expand Down

0 comments on commit 257ae9f

Please sign in to comment.