@@ -9,7 +9,7 @@ import * as gradleUtil from "../util/gradleUtil";
99import * as mavenUtil from "../util/mavenUtil" ;
1010import * as util from "../util/helperUtil" ;
1111import { localize } from "../util/i18nUtil" ;
12- import { EXCLUDED_DIR_PATTERN , LIBERTY_GRADLE_PROJECT , LIBERTY_GRADLE_PROJECT_CONTAINER , LIBERTY_MAVEN_PROJECT , LIBERTY_MAVEN_PROJECT_CONTAINER , UNTITLED_WORKSPACE } from "../definitions/constants" ;
12+ import { EXCLUDED_DIR_PATTERN , LIBERTY_GRADLE_PROJECT , LIBERTY_GRADLE_PROJECT_CONTAINER , LIBERTY_MAVEN_PROJECT , LIBERTY_MAVEN_PROJECT_CONTAINER } from "../definitions/constants" ;
1313import { BuildFileImpl , GradleBuildFile } from "../util/buildFile" ;
1414import { DashboardData } from "./dashboard" ;
1515import { BaseLibertyProject } from "./baseLibertyProject" ;
@@ -31,11 +31,15 @@ export class ProjectProvider implements vscode.TreeDataProvider<LibertyProject>
3131
3232 private _context : vscode . ExtensionContext ;
3333
34+ // Resolves when the first refresh() completes. Callers that need a stable
35+ // project map before acting (e.g. handleWorkspaceSaveInProgress) must await this.
36+ public readonly initialRefresh : Promise < void > ;
37+
3438 constructor ( context : vscode . ExtensionContext ) {
3539 this . _context = context ;
3640 this . _onDidChangeTreeData = new vscode . EventEmitter < LibertyProject | undefined > ( ) ;
3741 this . onDidChangeTreeData = this . _onDidChangeTreeData . event ;
38- this . refresh ( ) ;
42+ this . initialRefresh = this . refresh ( ) ;
3943 }
4044
4145 public getContext ( ) : vscode . ExtensionContext {
@@ -212,20 +216,20 @@ export class ProjectProvider implements vscode.TreeDataProvider<LibertyProject>
212216 'Save Workspace'
213217 ) . then ( async ( selection ) => {
214218 if ( selection === 'Save Workspace' ) {
219+ await this . _context . globalState . update ( 'workspaceSaveInProgress' , true ) ;
220+ console . log ( '[checkUntitledWorkspaceAndSaveIt] wrote workspaceSaveInProgress=true, selectedProject=' + this . _context . globalState . get ( 'selectedProject' ) ) ;
221+ // Do NOT clear globalState here: the new session needs workspaceSaveInProgress
222+ // and selectedProject to restore the manually-added project to the dashboard.
223+ await vscode . commands . executeCommand ( 'workbench.action.saveWorkspaceAs' ) ;
224+ console . log ( '[checkUntitledWorkspaceAndSaveIt] saveWorkspaceAs command returned' ) ;
225+ } else {
215226 /**
216- * setting workspaceSaveInProgress to true and storing it in globalstate for identifyting that the
217- * workspace is saved and needs to save the manually added projects to the dashboard
227+ * If the user cancels saving the workspace and exits without saving, the data stays in the global state,
228+ * which is shared across all VS Code instances. To prevent this data from being mistakenly used in other
229+ * sessions and added to the dashboard, it should be cleared if the user cancels the save.
218230 */
219- await this . _context . globalState . update ( 'workspaceSaveInProgress' , true ) ;
220- //opens the saveWorkspace as dialog box
221- await vscode . commands . executeCommand ( 'workbench.action.saveWorkspaceAs' ) ;
231+ util . clearDataSavedInGlobalState ( this . _context ) ;
222232 }
223- /**
224- * If the user cancels saving the workspace and exits without saving, the data stays in the global state,
225- * which is shared across all VS Code instances. To prevent this data from being mistakenly used in other
226- * sessions and added to the dashboard, it should be cleared if the user cancels the save.
227- */
228- util . clearDataSavedInGlobalState ( this . _context ) ;
229233 resolve ( ) ;
230234 } ) ;
231235 } catch ( error ) {
@@ -237,12 +241,15 @@ export class ProjectProvider implements vscode.TreeDataProvider<LibertyProject>
237241 }
238242
239243 /*
240- This method identifies a workspace that is untitled and contains more than one project
241- */
244+ * Returns true when the workspace has not yet been saved to a .code-workspace file,
245+ * meaning workspaceState will be lost if the user does "Save Workspace As...".
246+ * This covers both plain single-folder windows (workspace.name == folder name)
247+ * and VS Code's auto-created "Untitled (Workspace)" multi-root workspaces.
248+ */
242249 public isMultiProjectUntitledWorkspace ( ) : boolean {
243250 const workspaceFolders = vscode . workspace . workspaceFolders ;
244- if ( ( workspaceFolders && workspaceFolders . length > 1
245- && vscode . workspace . name === UNTITLED_WORKSPACE ) ) {
251+ if ( workspaceFolders && workspaceFolders . length >= 1
252+ && vscode . workspace . workspaceFile === undefined ) {
246253 return true ;
247254 }
248255 return false ;
0 commit comments