mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
allow workspace edit to "create" untitled files (#191779)
https://github.com/microsoft/vscode-copilot/issues/1261
This commit is contained in:
parent
eef56ce7d3
commit
bee68cee69
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue