OPEN TO WORK

Available for new opportunities! Let's build something amazing together.

#DevHack: check how your VSCode extension is running

Extensions VSCode Development
post

This post is over a year old, some of this information may be out of date.

When developing Visual Studio Code extensions, it might come in handy to know when running a production- or debug-build.

Typically in Node.js projects, we verify this by using the NODE_ENV environment variable. Unfortunately, this approach cannot be used as VS Code runs in a different instance, and environment variables are lost.

Solution

Luckily, there is a way to check how your extension is running. You can check this via the vscode extension API.

You can retrieve the mode your extension is started with via the context.extensionMode property.

import { ExtensionContext, ExtensionMode } from 'vscode';
export function activate(context: ExtensionContext) {
if (context.extensionMode === ExtensionMode.Development) {
// Running in development mode
} else if (context.extensionMode === ExtensionMode.Test) {
// Running in test mode
} else {
// Running in production mode
}
}

There are three modes:

  • Development
  • Production
  • Test

Hopefully, this #DevHack helps you to tweak your development flow when creating VS Code extensions.

Related articles

Report issues or make changes on GitHub

Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.

Comments

Elio Struyf

Solutions Architect & Developer Expert

Loading...

Let's build together

Manage content in VS Code

Present from VS Code