简体   繁体   中英

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. Is there some property that would indicate to an extension if it is running in such an instance of vsc? Like one started by the debugger to test an extension rather than a normal instance of 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 :

// 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

The ExtensionMode is provided on the ExtensionContext and indicates the mode the specific extension is running in.
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
  • other extensions in the host run in ExtensionMode.Release (extension is installed normally, for example, from the marketplace or VSIX, in VSCode).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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