Solving Manual Project Add Bug when Saving as a Workspace & Adding Unit Tests #622
Open
sharma1208 wants to merge 4 commits into
Open
Solving Manual Project Add Bug when Saving as a Workspace & Adding Unit Tests #622sharma1208 wants to merge 4 commits into
sharma1208 wants to merge 4 commits into
Conversation
…ed to test-unit in package json
- 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
mattbsox
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.
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.
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
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.
added public readonly initialRefresh: Promise to ProjectProvider that stores the Promise returned by the constructor's refresh() call.
moved handleWorkspaceSaveInProgress to run early in activate(), before startLangServer.
made it async and added await projectProvider.initialRefresh so it waits for the map to be ready.
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