#DevHack: Check if a VSCode extension is running in WSL
This post is over a year old, some of this information may be out of date.
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:
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:
const isWsl = vscode.env.remoteName === "wsl";if (isWsl) { commands.executeCommand('remote-wsl.revealInExplorer');} else { commands.executeCommand('revealFileInOS');}
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
Let's build together
Manage content in VS Code
Present from VS Code