allow workspace edit to "create" untitled files (#191779)

https://github.com/microsoft/vscode-copilot/issues/1261
This commit is contained in:
Johannes Rieken 2023-08-30 15:24:37 +02:00 committed by GitHub
parent eef56ce7d3
commit bee68cee69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -977,6 +977,22 @@ suite('vscode API - workspace', () => {
assert.strictEqual(document.getText(), expected);
});
test('[Bug] Failed to create new test file when in an untitled file #1261', async function () {
const uri = vscode.Uri.parse('untitled:Untitled-5.test');
const contents = `Hello Test File ${uri.toString()}`;
const we = new vscode.WorkspaceEdit();
we.createFile(uri, { ignoreIfExists: true });
we.replace(uri, new vscode.Range(0, 0, 0, 0), contents);
const success = await vscode.workspace.applyEdit(we);
assert.ok(success);
const doc = await vscode.workspace.openTextDocument(uri);
assert.strictEqual(doc.getText(), contents);
});
test('Should send a single FileWillRenameEvent instead of separate events when moving multiple files at once#111867, 1/3', async function () {
const file1 = await createRandomFile();

View file

@ -18,6 +18,7 @@ import { ResourceFileEdit } from 'vs/editor/browser/services/bulkEditService';
import { CancellationToken } from 'vs/base/common/cancellation';
import { tail } from 'vs/base/common/arrays';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { Schemas } from 'vs/base/common/network';
interface IFileOperation {
uris: URI[];
@ -173,6 +174,9 @@ class CreateOperation implements IFileOperation {
const undoes: DeleteEdit[] = [];
for (const edit of this._edits) {
if (edit.newUri.scheme === Schemas.untitled) {
continue; // ignore, will be handled by a later edit
}
if (edit.options.overwrite === undefined && edit.options.ignoreIfExists && await this._fileService.exists(edit.newUri)) {
continue; // not overwriting, but ignoring, and the target file exists
}