简体   繁体   English

有没有办法检测调试器是否创建了 VSC 窗口

[英]Is there a way of detecting if a VSC window is created by the debugger

When creating extensions the debug and run sidebar is used for starting an instance of vsc and installs the extension you are creating into it.创建扩展时,调试和运行侧栏用于启动 vsc 实例并将您正在创建的扩展安装到其中。 Is there some property that would indicate to an extension if it is running in such an instance of vsc?如果扩展在这样的 vsc 实例中运行,是否有一些属性会指示扩展? Like one started by the debugger to test an extension rather than a normal instance of VSC?就像调试器启动来测试扩展而不是 VSC 的普通实例一样?

It sounds like you want to detect whether the window is an "Extension Development Host".听起来您想检测窗口是否是“扩展开发主机”。 There's a feature request for that here:这里有一个功能请求:

While there doesn't seem to be an official way to accomplish that yet, a maintainer of the PowerShell extension has found a workaround :虽然似乎还没有正式的方法来实现这一点,但 PowerShell 扩展的维护者已经找到了一种解决方法

// When in development mode, VS Code's session ID is a fake
// value of "someValue.machineId".  Use that to detect dev
// mode for now until Microsoft/vscode#10272 gets implemented.
private readonly inDevelopmentMode =
    vscode.env.sessionId === "someValue.sessionId";

I did a quick test and it looks like this still works, but it seems rather fragile / like the sort of thing that could break at any point.我做了一个快速测试,看起来这仍然有效,但它似乎相当脆弱/就像那种随时可能破裂的东西。

issue 10272 has been merged with issue 95926 , which should be resolved with VSCode v1.46 (May 2020), with PR 97081问题 10272已与问题 95926合并,应使用 VSCode v1.46(2020 年 5 月)解决, PR 97081

The ExtensionMode is provided on the ExtensionContext and indicates the mode the specific extension is running in.所述ExtensionMode设置在ExtensionContext并指示特定的分机是否在运行模式。
This is specific to the current extension.这是特定于当前扩展的。

  • One extension may be in ExtensionMode.Development (The extension is running from an --extensionDevelopmentPath and the extension host is running unit tests), while一个扩展可能在ExtensionMode.Development (扩展从--extensionDevelopmentPath运行并且扩展主机正在运行单元测试),而
  • other extensions in the host run in ExtensionMode.Release (extension is installed normally, for example, from the marketplace or VSIX, in VSCode).主机中的其他扩展在ExtensionMode.Release运行(扩展通常安装,例如,从市场或 VSIX,在 VSCode 中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM