Skip to content

Solving Manual Project Add Bug when Saving as a Workspace & Adding Unit Tests #622

Open
sharma1208 wants to merge 4 commits into
OpenLiberty:mainfrom
sharma1208:workspace-bug
Open

Solving Manual Project Add Bug when Saving as a Workspace & Adding Unit Tests #622
sharma1208 wants to merge 4 commits into
OpenLiberty:mainfrom
sharma1208:workspace-bug

Conversation

@sharma1208

@sharma1208 sharma1208 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Addresses Issue #386, relies on some changes from PR #618

The existing bug was the following: After manually adding a project to the liberty tools dashboard, if a user were to attempt to save their project as a workspace when it was originally just a folder name, this would cause the project to disappear from the dashboard in the new workspace, when it should've persisted.

Fixes to address this problem:

  1. A main issue was that projects within the dashboard were not being saved across sessions/ not surviving a reload because globalState was not being updated. The isMultiProjectUntitledWorkspace() method was the check that needed to return true to allow for globalState updates. Within isMultiProjectUntitledWorkspace(), the method was originally checking workspaceFolders.length > 1 && workspace.name === "Untitled (Workspace)". This brought up two problems.

    1. . workspaceFolders.length > 1 excluded single-folder windows from saving the projects within the dashboard
    2. workspace.name === "Untitled (Workspace)" set the expectation that globalState would be updated only if an untitled workspace was created and didn't address what to do when a workspace was not yet created (Untiled (Workspace) automatically created for projects with more than one folder, but for a one folder project it was ignored).

Updates made: workspaceFolders.length >= 1 && vscode.workspace.workspaceFile === undefined. Use vscode.workspace.workspaceFile is undefined for any unsaved workspace (plain folder or untitled), and has a value only once a .code-workspace file is open.

  1. clearDataSavedInGlobalState() ran unconditionally and wiped flags before new session, causing project dashboard data to be lost across sessions. Solution was to only call clearDataSavedInGlobalState() when user clicked Cancel instead of Save Workspace

  2. Race condition: handleWorkspaceSaveInProgress ran before refresh() finished
    The function that restores the project after reload calls addUserSelectedPath() which checks the projects map, but refresh() (which builds the map) hadn't finished yet. Also, it was called inside startLangServer().then() which can take 30+ seconds.

    1. added public readonly initialRefresh: Promise to ProjectProvider that stores the Promise returned by the constructor's refresh() call.

    2. moved handleWorkspaceSaveInProgress to run early in activate(), before startLangServer.

    3. made it async and added await projectProvider.initialRefresh so it waits for the map to be ready.

    4. added projectProvider.refresh() in registerCommands() so the tree re-renders after the project is written.

Approached this problem with a TDD approach, creating a unit test for isMultiProiectUntitledWorkspace() to make sure that the scenario with 1 folder and no Untitled (Workspace) would now pass. See the solution to the bug working below:

Screen.Recording.2026-07-07.at.4.44.37.PM.MOV

- Extracted shared fakeVscode.ts with installFakeVscode()

- Remove TS_NODE_COMPILER_OPTIONS from test-unit script in package.json since tsconfig.json already specifies module: commonjs
- Simplify addUserSelectedPath Test 1 — remove unnecessary existsSyncStub
  and readFileStub wrappers since createLibertyProject is fully replaced
  with a fake and no real file I/O occurs
@sharma1208 sharma1208 requested a review from mattbsox July 8, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants