-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The api workspace.applyEdit drops the TextEdit if there is a RenameFile later #77735
Labels
Milestone
Comments
I have added an unit test and I cannot reproduce. Please provide extension code that demonstrates this... |
Below is my reproducing script.
import * as vscode from 'vscode';
import * as path from 'path';
export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('extension.helloWorld', async () => {
await testApplyEdit(false);
});
let disposable1 = vscode.commands.registerCommand('extension.helloWorld1', async () => {
await testApplyEdit(true);
});
context.subscriptions.push(disposable);
context.subscriptions.push(disposable1);
}
async function testApplyEdit(closeEditor: boolean) {
const result = await vscode.workspace.findFiles("file1");
if (!result || !result.length) {
vscode.window.showErrorMessage("Cannot find file1.");
return;
}
let docUri = result[0];
for (let i = 0; i < 10; i++) {
if (closeEditor) {
await vscode.commands.executeCommand("workbench.action.closeAllEditors");
}
let we = new vscode.WorkspaceEdit();
let oldUri, newUri;
let expected;
if (i % 2 === 0) {
oldUri = docUri;
newUri = vscode.Uri.parse(docUri.toString().replace('file1', 'newfile1'));
we.insert(oldUri, new vscode.Position(0, 0), 'Hello');
expected = 'Hello';
} else {
oldUri = vscode.Uri.parse(docUri.toString().replace('file1', 'newfile1'));
newUri = docUri;
we.delete(oldUri, new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 5)));
expected = '';
}
console.log(`${i}: Dealing with ${oldUri.toString()} - ${newUri.toString()}`);
we.renameFile(oldUri, newUri);
await vscode.workspace.applyEdit(we);
const document = await vscode.workspace.openTextDocument(newUri);
await document.save();
if (document.getText() !== expected) {
vscode.window.showErrorMessage(`${i}: ${path.basename(newUri.fsPath)} failed. Expected: '${expected}', Actual: '${document.getText()}'`);
}
await delay(1000);
}
}
function delay(ms: number) {
return new Promise( resolve => setTimeout(resolve, ms) );
}
export function deactivate() {} |
Thanks, I can now reproduce. @bpasero It seems that textFileEditorManager knows that the file is dirty but that it doesn't get saved before moving/renaming the file. Calling |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have a WorkspaceEdit as below:
A simplified sample:
{
documentChanges: [
TextEdit to file1,
TextEdit to file2,
TextEdit to file1,
Move file1 to file1New
]
}
A real WorkspaceEdit for apply
Log from the command "Developer: Open Log File... -> Window"
[2019-07-22 17:27:29.179] [renderer11] [debug] _performTextEdits
[2019-07-22 17:27:29.184] [renderer11] [debug] _performFileEdits
The edits are supposed to be applied by order, the text edits for the old file should be applied first, then move to the new file.
But actually the change for file2 is always applied correctly, but sometimes the text changes for file1 don't take effect. Especially when file1 is not opened in VS Code before applying, the text changes for file1 are often dropped. Besides, if i move the same file back and forth, it can be easily reproduced.
The text was updated successfully, but these errors were encountered: