mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 17:48:56 +01:00
* Return resulting `URI` from commands that save the active editor (fix #178713) * 💄 * address feedback * change to real proposed API * cleanup
This commit is contained in:
@@ -1171,7 +1171,6 @@ suite('vscode API - workspace', () => {
|
||||
assert.deepStrictEqual(edt.selections, [new vscode.Selection(0, 0, 0, 3)]);
|
||||
});
|
||||
|
||||
|
||||
test('Support creating binary files in a WorkspaceEdit', async function (): Promise<any> {
|
||||
|
||||
const fileUri = vscode.Uri.parse(`${testFs.scheme}:/${rndName()}`);
|
||||
@@ -1187,4 +1186,46 @@ suite('vscode API - workspace', () => {
|
||||
|
||||
assert.deepStrictEqual(actual, data);
|
||||
});
|
||||
|
||||
test('saveAll', async () => {
|
||||
await testSave(true);
|
||||
});
|
||||
|
||||
test('save', async () => {
|
||||
await testSave(false);
|
||||
});
|
||||
|
||||
async function testSave(saveAll: boolean) {
|
||||
const file = await createRandomFile();
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
|
||||
await revertAllDirty(); // needed for a clean state for `onDidSaveTextDocument` (#102365)
|
||||
|
||||
const onDidSaveTextDocument = new Set<vscode.TextDocument>();
|
||||
|
||||
disposables.push(vscode.workspace.onDidSaveTextDocument(e => {
|
||||
onDidSaveTextDocument.add(e);
|
||||
}));
|
||||
|
||||
const doc = await vscode.workspace.openTextDocument(file);
|
||||
await vscode.window.showTextDocument(doc);
|
||||
|
||||
if (saveAll) {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(doc.uri, new vscode.Position(0, 0), 'Hello World');
|
||||
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
assert.ok(doc.isDirty);
|
||||
|
||||
await vscode.workspace.saveAll(false); // requires dirty documents
|
||||
} else {
|
||||
const res = await vscode.workspace.save(doc.uri); // enforces to save even when not dirty
|
||||
assert.ok(res?.toString() === doc.uri.toString());
|
||||
}
|
||||
|
||||
assert.ok(onDidSaveTextDocument);
|
||||
assert.ok(Array.from(onDidSaveTextDocument).find(e => e.uri.toString() === file.toString()), 'did Save: ' + file.toString());
|
||||
disposeAll(disposables);
|
||||
return deleteFile(file);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user