我尝试多次编辑代码文件。首先,我进行一些基本的格式设置,例如删除空行等。然后,我想以列样式的方式重新格式化文件。如果我两次调用该命令,它将起作用。但是它应该以一种方式做到这一点。所以我想问题出在editor.edit(builder =>命令。我怎么能两次调用?如果我已经在我的代码中调用过一次,我认为它行不通吗?
editor
.edit(newbuilder => {
for (let index = 0; index < doc.lineCount; index++) {
newPos = currentPos.with(index, 0);
editor.selection = new vscode.Selection(newPos, newPos);
let reformattedItem = reformatItem();
if (reformattedItem !== "") {
let selection = new vscode.Range(newPos, newPos.with(newPos.line, doc.lineAt(newPos.line).text.length));
newbuilder.replace(selection, reformattedItem);
}
}
})
.then(success => {
let pos = new vscode.Position(0, 0);
editor.selection = new vscode.Selection(pos, pos);
})
.then(undefined, err => {
console.error(err);
});