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

#DevHack: Check if a VSCode extension is running in WSL

post

For the Front Matter Visual Studio Code extension, I needed to know if the current instance opened a Windows Subsystem for Linux (WSL) located project folder.

By knowing this context, I could ensure that certain functionality works similarly to the default behavior on Windows and macOS.

The solution

The solution is a very simple one-liner:

1
const isWsl = vscode.env.remoteName === "wsl";

How I use it

I have two buttons in the Front Matter extension to open the project- and file folder in finder/explorer. When running in WSL, the revealFileInOS command from VSCode is not available. You need to use the remote-wsl.revealInExplorer command instead. With the one-liner, I can now do the following:

1
2
3
4
5
6
const isWsl = vscode.env.remoteName === "wsl";
if (isWsl) {
  commands.executeCommand('remote-wsl.revealInExplorer');
} else {
  commands.executeCommand('revealFileInOS');
}

Comments

Back to top