Virtual Workspaces
Extensions like the GitHub Repositories extension open VS Code on one or more folders backed by a file system provider. When an extension implements a file system provider, workspace resources may not be located on the local disk, but be virtual, located on a server or the cloud, and editing operations happen there.
This configuration is called a virtual workspace. When a virtual workspace is open in a VS Code window, this is indicated by a label in the remote indicator in the lower left corner, similar to other remote development windows.
Not all extensions are able to work with virtual resources and may require resources to be on disk. Some extensions use tools that rely on disk access, need synchronous file access, or don't have the necessary file system abstractions. In these cases, when in a virtual workspace, VS Code indicates to the user that they are running in a restricted mode and that some extensions are deactivated or work with limited functionality.
In general, users want as many extensions as possible to work in virtual workspaces and to have a good user experience when browsing and editing remote resources. This guide shows how extensions can test against virtual workspaces, describes modifications to allow them to work in virtual workspaces, and introduces the virtualWorkspaces
capability property.
Modifying an extension to work with virtual workspaces is also an important step for working well in VS Code for the Web. VS Code for the Web runs entirely inside a browser and workspaces are virtual due to the browser sandbox. See the Web Extensions guide for more details.
Is my extension affected?
When an extension has no executable code but is purely declarative like themes, keybindings, snippets, or grammar extensions, it can run in a virtual workspace and no modification is necessary.
Extensions with code, meaning extensions that define a main
entry point, require inspection and, possibly, modification.
Run your extension against a virtual workspace
Install the GitHub Repositories extension and run the Open GitHub Repository... command from the Command Palette. The command shows a Quick Pick dropdown and you can paste in any GitHub URL, or choose to search for a specific repository or pull request.
This opens a VS Code window for a virtual workspace where all resources are virtual.
Review that the extension code is ready for virtual resources
The VS Code API support for virtual file systems has been around for quite a while. You can check out the file system provider API.
A file system provider is registered for a new URI scheme (for example, vscode-vfs
) and resources on that file system will be represented by URIs using that schema (vscode-vfs://github/microsoft/vscode/package.json
)
Check how your extension deals with URIs returned from the VS Code APIs:
- Never assume that the URI scheme is
file
.URI.fsPath
can only be used when the URI scheme isfile
. - Look out for usages of the
fs
node module for file system operations. If possible, use thevscode.workspace.fs
API, which delegates to the appropriate file system provider. - Check for third-party components that depend on a
fs
access (for example, a language server or a node module). - If you run executables and tasks from commands, check whether these commands make sense in a virtual workspace window or whether they should be disabled.
Signal whether your extension can handle virtual workspaces
The virtualWorkspaces
property under capabilities
in package.json
is used to signal whether an extension works with virtual workspaces.
No support for virtual workspaces
The example below declares that an extension does not support virtual workspaces and should not be enabled by VS Code in this setup.
{
"capabilities": {
"virtualWorkspaces": {
"supported": false,
"description": "Debugging is not possible in virtual workspaces."
}
}
}
Partial and full support for virtual workspaces
When an extension works or partially works with virtual workspaces, it should define "virtualWorkspaces": true
.
{
"capabilities": {
"virtualWorkspaces": true
}
}
If an extension works, but has limited functionality, it should explain the limitation to the user:
{
"capabilities": {
"virtualWorkspaces": {
"supported": "limited",
"description": "In virtual workspaces, resolving and finding references across files is not supported."
}
}
}