From faae8ce96d789f80e5bd7dc62b57ab873877380f Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Mon, 18 Nov 2024 12:00:12 +0530 Subject: [PATCH] changes to handle single project opened in vs code for the manual project add issue --- src/extension.ts | 7 ++++--- src/liberty/libertyProject.ts | 31 ++++++++++++------------------- src/util/helperUtil.ts | 8 ++++++++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 63b78bf9..9ccea3e9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -19,6 +19,7 @@ import { JAVA_EXTENSION_ID, waitForStandardMode } from "./util/javaServerMode"; import { localize } from "./util/i18nUtil"; import { RequirementsData, resolveRequirements, resolveLclsRequirements } from "./util/requirements"; import { prepareExecutable } from "./util/javaServerStarter"; +import * as helperUtil from "./util/helperUtil"; const LIBERTY_CLIENT_ID = "LANGUAGE_ID_LIBERTY"; const JAKARTA_CLIENT_ID = "LANGUAGE_ID_JAKARTA"; @@ -109,10 +110,10 @@ function registerCommands(context: ExtensionContext) { projectProvider = new ProjectProvider(context); ProjectProvider.setInstance(projectProvider); } - if (projectProvider.getContext().globalState.get('workspaceSaveInProgress') && projectProvider.getContext().globalState.get('selectedProject') !== undefined) { + if (projectProvider.getContext().globalState.get('workspaceSaveInProgress') && + projectProvider.getContext().globalState.get('selectedProject') !== undefined) { devCommands.addProjectsToTheDashBoard(projectProvider, projectProvider.getContext().globalState.get('selectedProject') as string); - projectProvider.getContext().globalState.update('workspaceSaveInProgress', false); - projectProvider.getContext().globalState.update('selectedProject', undefined); + helperUtil.clearDataSavedInglobalState(projectProvider.getContext()); } if (vscode.workspace.workspaceFolders !== undefined) { registerFileWatcher(projectProvider); diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 952dfb6e..1df908a2 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -208,7 +208,7 @@ export class ProjectProvider implements vscode.TreeDataProvider one project. if not saved there are chances for the projects state not being saved and manually added projects might not be visible in the liberty dashboard */ - public async checkUntitledWorkspaceAndSaveIt():Promise{ + public async checkUntitledWorkspaceAndSaveIt(): Promise { return new Promise((resolve) => { try { vscode.window.showInformationMessage( @@ -219,35 +219,28 @@ export class ProjectProvider implements vscode.TreeDataProvider if (selection === 'Save Workspace') { //setting workspaceSaveInProgress to true and storing it in globalstate for identifyting that the workspace is saved and needs to //save the manually added projects to the dashboard - await this._context.globalState.update('workspaceSaveInProgress',true); + await this._context.globalState.update('workspaceSaveInProgress', true); //opens the saveWorkspace as dialog box await vscode.commands.executeCommand('workbench.action.saveWorkspaceAs'); - //after execution of above line , if save is opted the workspace reloads and reinitialisation of the workspace happens based on the - //activation events in package.json, if cancel is opted then the workspace is not going to be saved - //so below lines will clear workspaceSaveInProgress and selectedProject from the global state - await this._context.globalState.update('workspaceSaveInProgress',false); - await this._context.globalState.update('selectedProject',undefined); - resolve(); - }else { - // No workspace save was initiated - resolve(); } + util.clearDataSavedInglobalState(this._context); + resolve(); }); } catch (error) { - console.debug("exception while saving the workspace"+error); + console.debug("exception while saving the workspace" + error); - } - }); + } + }); } /* Method identifies a workspace that is untitled and containing morethan one project */ - public isUntitledWorkspace():boolean{ + public isUntitledWorkspace(): boolean { const workspaceFolders = vscode.workspace.workspaceFolders; - if (workspaceFolders && workspaceFolders.length > 1 - && vscode.workspace.name === "Untitled (Workspace)"){ - return true; - } + if ((workspaceFolders && workspaceFolders.length > 1 + && vscode.workspace.name === "Untitled (Workspace)") || (vscode.workspace.workspaceFile == undefined)) { + return true; + } return false; } diff --git a/src/util/helperUtil.ts b/src/util/helperUtil.ts index 46582534..60414573 100644 --- a/src/util/helperUtil.ts +++ b/src/util/helperUtil.ts @@ -71,4 +71,12 @@ export function getStorageData(context: vscode.ExtensionContext): DashboardData export async function saveStorageData(context: vscode.ExtensionContext, dasboardData: DashboardData): Promise{ await context.workspaceState.update(LIBERTY_DASHBOARD_WORKSPACE_STORAGE_KEY, dasboardData); } +/** + * clears the states saved in global state + * @param context + */ +export function clearDataSavedInglobalState(context: vscode.ExtensionContext) { + context.globalState.update('workspaceSaveInProgress', false); + context.globalState.update('selectedProject', undefined); +}