首页 > 解决方案 > 同时调试两个 VSCode 扩展?

问题描述

我有两个 VSCode 扩展,扩展 A 和扩展 B。它们的实现使得扩展 A 和扩展 B 可以使用扩展 A 的activate()函数返回的导出相互通信。

为了测试这种通信,我将构建一个扩展作为 vsix,将其安装在 VSCode 中,然后调试另一个扩展。但理想情况下,我不希望构建和安装其中一个扩展。

是否可以同时调试两个扩展?如果我可以在 VSCode(多根工作区)中打开这两个扩展,并且能够在同一个 [Extension Development Host] 窗口中运行这两个扩展,那就太好了。

标签: visual-studio-code

解决方案


我向上帝发誓,我一个小时前刚读到这个……

首先,可以从命令行安装扩展。但是您必须以某种方式通过代码调用 CLI...

啊哈!找到了

const cp = require('child_process');
const { downloadAndUnzipVSCode, resolveCliPathFromExecutablePath } = require('vscode-test');
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.34.0');
const cliPath = resolveCliPathFromExecutablePath(vscodeExecutablePath);

// Use cp.spawn / cp.exec for custom setup
cp.spawnSync(cliPath, ['--install-other-extension', '<EXTENSION-ID-OR-PATH-TO-VSIX>'], {
  encoding: 'utf-8',
  stdio: 'inherit'
});

// Run the extension test
await runTests({
  // Use the specified `code` executable
  vscodeExecutablePath,
  extensionPath,
  testRunnerPath
});

推荐阅读