You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VSCode扩展中按名称指定并启动调试配置

如何在VSCode扩展中启动指定的调试配置

完全可以实现从扩展中直接启动指定的调试配置,不用弹出选择面板。你不需要依赖workbench.action.debug.start命令,而是用VSCode官方提供的vscode.debug.startDebugging API来完成这个需求。

具体实现步骤

  • 从launch.json中筛选出你想要启动的目标配置
  • 调用startDebugging API直接启动该配置

代码示例

import * as vscode from 'vscode';

async function launchSpecificDebugConfig(configName: string) {
    // 获取launch.json里的所有调试配置
    const allLaunchConfigs = vscode.workspace.getConfiguration('launch').get<vscode.DebugConfiguration[]>('configurations') || [];
    // 找出名称匹配的目标配置
    const targetConfig = allLaunchConfigs.find(config => config.name === configName);

    if (targetConfig) {
        // 启动调试,第一个参数传当前工作区(或undefined使用默认工作区)
        await vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], targetConfig);
    } else {
        vscode.window.showErrorMessage(`未找到名为「${configName}」的调试配置`);
    }
}

// 调用方法启动指定配置
launchSpecificDebugConfig('Debug Configuration A');

补充说明

你提到的相关PR是给workbench.action.debug.start命令添加参数支持,但目前它仍然会弹出选择面板,无法直接跳过选择步骤。相比之下,startDebugging API是更稳定、符合需求的方案,它属于VSCode扩展API的正式部分,不会有弹出面板的问题。

内容的提问来源于stack exchange,提问作者Rijesh Augustine

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 05:19:50