Describe the bug
When starting an empty workspace (one whose devfile has no projects, dependentProjects, or starterProjects, e.g. the dashboard's built-in "Empty Workspace" sample), the che-code launcher generates a .code-workspace file that has no folders array. As a result, VS Code / che-code opens with an empty Explorer and no folder mounted, even though /projects exists and is where the user is expected to work.
The generated /projects/.code-workspace looks like this:
{
"extensions": {
"recommendations": [
"eamodio.gitlens",
"redhat.vscode-yaml",
"..."
]
}
}
Note the extensions.recommendations block is present (injected by the vscode-editor-configurations handling) but there is no folders entry, so nothing is open.
Che version
7.119.0 (also reproduced on current che-incubator/che-code main)
Steps to reproduce
- Open the Dashboard and go to Create Workspace.
- Under "Select a Sample", filter by
Empty and start the Empty Workspace sample (a devfile that is just schemaVersion + generateName: empty, with no projects).
- Wait for the workspace to start and the editor to open.
- Open a terminal and inspect the generated workspace file:
cat /projects/.code-workspace
Expected behavior
The workspace should open with the /projects directory mounted in the Explorer. The generated .code-workspace should contain a folders entry pointing at PROJECTS_ROOT when there are no devfile projects to add, e.g.:
{
"folders": [
{ "name": "projects", "path": "/projects" }
],
"extensions": { "recommendations": ["..."] }
}
Runtime
OpenShift Dev Spaces / che-code
Root cause
The workspace file is generated by the che-code launcher in launcher/src/code-workspace.ts, CodeWorkspace.generate().
For an empty workspace:
- No
VSCODE_DEFAULT_WORKSPACE is set and there are no projects, so generate() falls through to the default path branch and creates a brand-new empty object:
workspace = {} as Workspace; // no `folders` key
saveRequired = true;
- It then calls
synchronizeProjects() for projects, dependentProjects, and starterProjects. synchronizeProjects() bails out on the first line when the array is undefined:
async synchronizeProjects(workspace, projects?) {
if (!projects) { return false; } // empty workspace: returns here, folders never initialized
...
}
So folders is never populated (and never even initialized to []).
- The launcher writes
{} to /projects/.code-workspace. Later, extension recommendations are merged into the same file, producing the extensions-only file shown above.
Because the resulting file is a multi-root .code-workspace with no folders, VS Code opens a zero-folder workspace and the Explorer is empty.
Suggested fix
In CodeWorkspace.generate(), after the synchronizeProjects() calls and before writing the file, ensure folders always contains at least PROJECTS_ROOT when it would otherwise be empty:
if (!workspace!.folders || workspace!.folders.length === 0) {
workspace!.folders = [{ name: 'projects', path: env.PROJECTS_ROOT }];
saveRequired = true;
}
This is a no-op for workspaces that already resolve folders (single-project, multi-repo, or a VSCODE_DEFAULT_WORKSPACE file that already lists folders), and it fixes the empty-workspace case at the source.
A PR against che-incubator/che-code implementing this will be linked to this issue.
Describe the bug
When starting an empty workspace (one whose devfile has no
projects,dependentProjects, orstarterProjects, e.g. the dashboard's built-in "Empty Workspace" sample), the che-code launcher generates a.code-workspacefile that has nofoldersarray. As a result, VS Code / che-code opens with an empty Explorer and no folder mounted, even though/projectsexists and is where the user is expected to work.The generated
/projects/.code-workspacelooks like this:{ "extensions": { "recommendations": [ "eamodio.gitlens", "redhat.vscode-yaml", "..." ] } }Note the
extensions.recommendationsblock is present (injected by thevscode-editor-configurationshandling) but there is nofoldersentry, so nothing is open.Che version
7.119.0 (also reproduced on current
che-incubator/che-codemain)Steps to reproduce
Emptyand start the Empty Workspace sample (a devfile that is justschemaVersion+generateName: empty, with no projects).Expected behavior
The workspace should open with the
/projectsdirectory mounted in the Explorer. The generated.code-workspaceshould contain afoldersentry pointing atPROJECTS_ROOTwhen there are no devfile projects to add, e.g.:{ "folders": [ { "name": "projects", "path": "/projects" } ], "extensions": { "recommendations": ["..."] } }Runtime
OpenShift Dev Spaces / che-code
Root cause
The workspace file is generated by the che-code launcher in
launcher/src/code-workspace.ts,CodeWorkspace.generate().For an empty workspace:
VSCODE_DEFAULT_WORKSPACEis set and there are no projects, sogenerate()falls through to the default path branch and creates a brand-new empty object:synchronizeProjects()forprojects,dependentProjects, andstarterProjects.synchronizeProjects()bails out on the first line when the array isundefined:foldersis never populated (and never even initialized to[]).{}to/projects/.code-workspace. Later, extension recommendations are merged into the same file, producing theextensions-only file shown above.Because the resulting file is a multi-root
.code-workspacewith nofolders, VS Code opens a zero-folder workspace and the Explorer is empty.Suggested fix
In
CodeWorkspace.generate(), after thesynchronizeProjects()calls and before writing the file, ensurefoldersalways contains at leastPROJECTS_ROOTwhen it would otherwise be empty:This is a no-op for workspaces that already resolve folders (single-project, multi-repo, or a
VSCODE_DEFAULT_WORKSPACEfile that already lists folders), and it fixes the empty-workspace case at the source.A PR against
che-incubator/che-codeimplementing this will be linked to this issue.