在vscode扩展中,有一种方法可以通过vscode.commands.executeCommand(...)

时间:2020-09-17 15:24:42

标签: visual-studio-code vscode-extensions vscode-debugger

简而言之,我正在寻找一种方法来捕获vscode扩展内的调试控制台的文本内容。以下代码片段几乎完全符合我想要的终端(而不是调试控制台)的功能。您也可以右键单击控制台,然后选择->全部复制。最后,我不会将其粘贴到新的代码窗口中,而是将其推送到端点以自动执行测试报告。

    vscode.commands.executeCommand('workbench.action.terminal.selectAll').then(() => {
        vscode.commands.executeCommand('workbench.action.terminal.copySelection').then(() => {
            vscode.commands.executeCommand('workbench.action.terminal.clearSelection').then(() => {
                vscode.commands.executeCommand('workbench.action.files.newUntitledFile').then(() => {
                    vscode.commands.executeCommand('editor.action.clipboardPasteAction');
                });
            });
        }); 
    });

我已经尝试过,但是在console.log中出现错误

    vscode.commands.executeCommand('repl.action.copyall').then(() => {
        vscode.commands.executeCommand('workbench.action.files.newUntitledFile').then(() => {
            vscode.commands.executeCommand('editor.action.clipboardPasteAction');
        });
    });

拒绝的承诺在1秒内未处理:错误:未找到命令'repl.action.copyall' extensionHostProcess.js:1048 堆栈跟踪:错误:找不到命令“ repl.action.copyall” 在u._tryExecuteCommand(文件:/// Applications / Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4213:713) 在file:/// Applications / Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4213:594

向我指出正确方向的任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

不要用Promise回调地狱

只需在then()处理程序中返回一个新的Promise

vscode.commands.executeCommand('workbench.action.terminal.selectAll')
    .then(() => vscode.commands.executeCommand('workbench.action.terminal.copySelection'))         
    .then(() => vscode.commands.executeCommand('workbench.action.terminal.clearSelection'))
    .then(() => vscode.commands.executeCommand('workbench.action.files.newUntitledFile'))
    .then(() => vscode.commands.executeCommand('editor.action.clipboardPasteAction'))