我希望能够创建/编写一个命令,将visual studio代码中所有打开的编辑器中的所有代码折叠起来。
我相信我很亲近。
我正在使用马塞尔·J·克劳伯特编写的“脚本命令”扩展
当我在一个组中与大约7个打开编辑器一起使用下面的脚本时。我的成就如下:
我使用的脚本:
// Fold all code in all open editors.
function execute(args) {
// Obtain access to vscode
var vscode = args.require('vscode');
// Set number of open editors... (future: query vscode for number of open editors)
var numOpenEditor = 20;
// Loop for numOpenEditor times
for (var i = 0; i <= numOpenEditor; i++){
// Fold the current open editor
vscode.commands.executeCommand('editor.foldAll');
// Move to the next editor to the right
vscode.commands.executeCommand('workbench.action.nextEditor');
// Loop message
var statusString = 'Loop ->' + i
// print message
vscode.window.showErrorMessage(statusString);
}
}
// Script Commands must have a public execute() function to work.
exports.execute = execute;
我已经做了一个有趣的观察,当我使用上面的脚本与大约7个开放编辑器与两个或更多的。有关切换到一个新的组将允许命令editor.foldAll
工作。注意,如果一个组有多个编辑器,那么唯一折叠其代码的编辑器就是组中的开放编辑器。因此,所有其他编辑器都不会折叠。
我还以为也许..。脚本需要放慢速度,所以我在每次迭代时都添加了一个暂停函数。这也不起作用。
任何帮助都会很好!
发布于 2019-01-05 18:22:20
您只需要完成这个函数异步,并等待executeCommand调用完成,然后才能继续:
// Fold all code in all open editors.
async function execute(args) {
// Obtain access to vscode
var vscode = args.require('vscode');
// Set number of open editors... (future: query vscode for number of open editors)
var numOpenEditor = 5;
// Loop for numOpenEditor times
for (var i = 0; i <= numOpenEditor; i++) {
// Fold the current open editor
await vscode.commands.executeCommand('editor.foldAll');
// Move to the next editor to the right
await vscode.commands.executeCommand('workbench.action.nextEditor');
// Loop message
var statusString = 'Loop ->' + i
// print message
vscode.window.showErrorMessage(statusString);
}
}
// Script Commands must have a public execute() function to work.
exports.execute = execute;
https://stackoverflow.com/questions/54057333
复制相似问题