From 79b1bb723d01a4f212065ae22a2d69c3830149f4 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Mon, 11 Nov 2024 12:30:26 +0530 Subject: [PATCH 01/15] Changes for asking the user to save the workspace when multiple projects are added --- src/extension.ts | 6 +++++- src/liberty/devCommands.ts | 16 ++++++++++---- src/liberty/libertyProject.ts | 40 +++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a609f5f9..3b1389c6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -109,7 +109,11 @@ function registerCommands(context: ExtensionContext) { projectProvider = new ProjectProvider(context); ProjectProvider.setInstance(projectProvider); } - + 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); + } if (vscode.workspace.workspaceFolders !== undefined) { registerFileWatcher(projectProvider); vscode.window.registerTreeDataProvider("liberty-dev", projectProvider); diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 456fbea9..1216d94e 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -173,10 +173,11 @@ function showListOfPathsToAdd(uris: string[]) { if (!selection) { return; } - const result = await projectProvider.addUserSelectedPath(selection, projectProvider.getProjects()); - const message = localize(`add.project.manually.message.${result}`, selection); - (result !== 0) ? console.error(message) : console.info(message); projectProvider.fireChangeEvent(); - vscode.window.showInformationMessage(message); + if(projectProvider.isUntitledWorkspace()){ + await projectProvider.getContext().globalState.update('selectedProject',selection); + await projectProvider.checkUntitledWorkspaceAndSaveIt(); + } + await addProjectsToTheDashBoard(projectProvider,selection); }); } @@ -610,4 +611,11 @@ async function getLocalGradleWrapper(projectFolder: string): Promise{ + const result = await projectProvider.addUserSelectedPath(selection,projectProvider.getProjects()); + const message = localize(`add.project.manually.message.${result}`, selection); + (result !== 0) ? console.error(message) : console.info(message); projectProvider.fireChangeEvent(); + vscode.window.showInformationMessage(message); + return Promise.resolve(); } \ No newline at end of file diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 8c860c09..8b21054c 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -203,6 +203,46 @@ export class ProjectProvider implements vscode.TreeDataProvider statusMessage.dispose(); } + /* + Method asks the user to save the workspace first if it is untitled and the workspace contains morethan + 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{ + return new Promise((resolve) => { + try { + vscode.window.showInformationMessage( + 'You are currently in an untitled workspace. Would you like to save it?', + { modal: true }, + 'Save Workspace' + ).then(async (selection) => { + if (selection === 'Save Workspace') { + await this._context.globalState.update('workspaceSaveInProgress',true); + await vscode.commands.executeCommand('workbench.action.saveWorkspaceAs'); + }else { + // No workspace save was initiated + resolve(); + } + }); + } catch (error) { + console.debug("exception while saving the workspace"+error); + + } + }); + } + /* + Method identifies a workspace that is untitled and containing morethan one project + */ + public isUntitledWorkspace():boolean{ + const workspaceFolders = vscode.workspace.workspaceFolders; + if (workspaceFolders && workspaceFolders.length > 1 + && vscode.workspace.name === "Untitled (Workspace)"){ + return true; + } + + return false; + } + public fireChangeEvent(): void { this._onDidChangeTreeData.fire(undefined); } From 21b32ac6ca9eb693e2ce764a3f22659412f70eeb Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Mon, 11 Nov 2024 16:48:50 +0530 Subject: [PATCH 02/15] Added comments to the newly added methods --- src/liberty/devCommands.ts | 7 +++++++ src/liberty/libertyProject.ts | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 1216d94e..9650fee4 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -174,7 +174,11 @@ function showListOfPathsToAdd(uris: string[]) { return; } if(projectProvider.isUntitledWorkspace()){ + //Saving the selected project to globalstate for adding it to the dashboard after reinitialization of the extension when workspace is saved await projectProvider.getContext().globalState.update('selectedProject',selection); + /* + if the workspace is untitled suggest the user to save the workspace first + */ await projectProvider.checkUntitledWorkspaceAndSaveIt(); } await addProjectsToTheDashBoard(projectProvider,selection); @@ -612,6 +616,9 @@ async function getLocalGradleWrapper(projectFolder: string): Promise{ const result = await projectProvider.addUserSelectedPath(selection,projectProvider.getProjects()); const message = localize(`add.project.manually.message.${result}`, selection); diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 8b21054c..b563f8aa 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -217,7 +217,10 @@ export class ProjectProvider implements vscode.TreeDataProvider 'Save Workspace' ).then(async (selection) => { 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 adde projects to the dashboard await this._context.globalState.update('workspaceSaveInProgress',true); + //opens the saveWorkspace as dialog box await vscode.commands.executeCommand('workbench.action.saveWorkspaceAs'); }else { // No workspace save was initiated From 8de7a683db8cbb07a216fb61c837e9b89ce2e912 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Tue, 12 Nov 2024 09:18:36 +0530 Subject: [PATCH 03/15] Updated the year in copyright header --- src/extension.ts | 2 +- src/liberty/devCommands.ts | 2 +- src/liberty/libertyProject.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 3b1389c6..63b78bf9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020, 2022 IBM Corporation. + * Copyright (c) 2020, 2024 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 9650fee4..b943bda7 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020, 2022 IBM Corporation. + * Copyright (c) 2020, 2024 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index b563f8aa..c6d8605a 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020, 2023 IBM Corporation. + * Copyright (c) 2020, 2024 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at From bbb61bf425b7159ae1e669868fe1de9afdc22850 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Fri, 15 Nov 2024 09:03:02 +0530 Subject: [PATCH 04/15] updated the message and clear the global states if the user ops not to save the workspace --- src/liberty/devCommands.ts | 2 +- src/liberty/libertyProject.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index b943bda7..f756fbe7 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -619,7 +619,7 @@ function isWin(): boolean { /* Method adds a project which is selected by the user from the list to the liberty dashboard */ -export async function addProjectsToTheDashBoard(projectProvider : ProjectProvider,selection:string): Promise{ +export async function addProjectsToTheDashBoard(projectProvider : ProjectProvider,selection:string): Promise{ const result = await projectProvider.addUserSelectedPath(selection,projectProvider.getProjects()); const message = localize(`add.project.manually.message.${result}`, selection); (result !== 0) ? console.error(message) : console.info(message); projectProvider.fireChangeEvent(); diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index c6d8605a..952dfb6e 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -212,16 +212,22 @@ export class ProjectProvider implements vscode.TreeDataProvider return new Promise((resolve) => { try { vscode.window.showInformationMessage( - 'You are currently in an untitled workspace. Would you like to save it?', + 'Please save the workspace first, as manually added projects to the dashboard may not persist in the next VS Code session if the workspace is not saved.', { modal: true }, 'Save Workspace' ).then(async (selection) => { 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 adde projects to the dashboard + //save the manually added projects to the dashboard 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(); From faae8ce96d789f80e5bd7dc62b57ab873877380f Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Mon, 18 Nov 2024 12:00:12 +0530 Subject: [PATCH 05/15] 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); +} From 5937255984c1bd9979404cacb013d96db5c65a04 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Mon, 18 Nov 2024 16:17:13 +0530 Subject: [PATCH 06/15] code formatted --- src/liberty/devCommands.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index f756fbe7..9d1a1f4f 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -173,15 +173,15 @@ function showListOfPathsToAdd(uris: string[]) { if (!selection) { return; } - if(projectProvider.isUntitledWorkspace()){ + if (projectProvider.isUntitledWorkspace()) { //Saving the selected project to globalstate for adding it to the dashboard after reinitialization of the extension when workspace is saved - await projectProvider.getContext().globalState.update('selectedProject',selection); + await projectProvider.getContext().globalState.update('selectedProject', selection); /* if the workspace is untitled suggest the user to save the workspace first - */ + */ await projectProvider.checkUntitledWorkspaceAndSaveIt(); } - await addProjectsToTheDashBoard(projectProvider,selection); + await addProjectsToTheDashBoard(projectProvider, selection); }); } @@ -619,8 +619,8 @@ function isWin(): boolean { /* Method adds a project which is selected by the user from the list to the liberty dashboard */ -export async function addProjectsToTheDashBoard(projectProvider : ProjectProvider,selection:string): Promise{ - const result = await projectProvider.addUserSelectedPath(selection,projectProvider.getProjects()); +export async function addProjectsToTheDashBoard(projectProvider: ProjectProvider, selection: string): Promise { + const result = await projectProvider.addUserSelectedPath(selection, projectProvider.getProjects()); const message = localize(`add.project.manually.message.${result}`, selection); (result !== 0) ? console.error(message) : console.info(message); projectProvider.fireChangeEvent(); vscode.window.showInformationMessage(message); From 388aceda66eb4295f42979a0556312132d28e7c0 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Wed, 20 Nov 2024 12:02:56 +0530 Subject: [PATCH 07/15] Removed the prompt for the user to save workspace when project is added to the dashboard for single projects --- src/liberty/libertyProject.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 1df908a2..fc965fd7 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -238,7 +238,7 @@ export class ProjectProvider implements vscode.TreeDataProvider public isUntitledWorkspace(): boolean { const workspaceFolders = vscode.workspace.workspaceFolders; if ((workspaceFolders && workspaceFolders.length > 1 - && vscode.workspace.name === "Untitled (Workspace)") || (vscode.workspace.workspaceFile == undefined)) { + && vscode.workspace.name === "Untitled (Workspace)")) { return true; } From 482fd270830757a06237ecc1bfab242b8a0c9ecf Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Wed, 20 Nov 2024 12:05:45 +0530 Subject: [PATCH 08/15] Formatted code --- src/liberty/libertyProject.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index fc965fd7..e45b3d57 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -233,7 +233,7 @@ export class ProjectProvider implements vscode.TreeDataProvider }); } /* - Method identifies a workspace that is untitled and containing morethan one project + Method identifies a workspace that is untitled and containing more than one project */ public isUntitledWorkspace(): boolean { const workspaceFolders = vscode.workspace.workspaceFolders; From 2799a127fba339821a009dda60dfcf1cbd4ebbad Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Wed, 20 Nov 2024 12:27:30 +0530 Subject: [PATCH 09/15] Corrected typo and formatted code --- src/extension.ts | 2 +- src/liberty/libertyProject.ts | 5 ++--- src/util/helperUtil.ts | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 9ccea3e9..074b144b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -113,7 +113,7 @@ function registerCommands(context: ExtensionContext) { if (projectProvider.getContext().globalState.get('workspaceSaveInProgress') && projectProvider.getContext().globalState.get('selectedProject') !== undefined) { devCommands.addProjectsToTheDashBoard(projectProvider, projectProvider.getContext().globalState.get('selectedProject') as string); - helperUtil.clearDataSavedInglobalState(projectProvider.getContext()); + helperUtil.clearDataSavedInGlobalState(projectProvider.getContext()); } if (vscode.workspace.workspaceFolders !== undefined) { registerFileWatcher(projectProvider); diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index e45b3d57..76ba2492 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -223,15 +223,15 @@ export class ProjectProvider implements vscode.TreeDataProvider //opens the saveWorkspace as dialog box await vscode.commands.executeCommand('workbench.action.saveWorkspaceAs'); } - util.clearDataSavedInglobalState(this._context); + util.clearDataSavedInGlobalState(this._context); resolve(); }); } catch (error) { console.debug("exception while saving the workspace" + error); - } }); } + /* Method identifies a workspace that is untitled and containing more than one project */ @@ -241,7 +241,6 @@ export class ProjectProvider implements vscode.TreeDataProvider && vscode.workspace.name === "Untitled (Workspace)")) { return true; } - return false; } diff --git a/src/util/helperUtil.ts b/src/util/helperUtil.ts index 60414573..4201975e 100644 --- a/src/util/helperUtil.ts +++ b/src/util/helperUtil.ts @@ -75,7 +75,7 @@ export async function saveStorageData(context: vscode.ExtensionContext, dasboard * clears the states saved in global state * @param context */ -export function clearDataSavedInglobalState(context: vscode.ExtensionContext) { +export function clearDataSavedInGlobalState(context: vscode.ExtensionContext) { context.globalState.update('workspaceSaveInProgress', false); context.globalState.update('selectedProject', undefined); } From e01d73642f98f96a1e59b30258643a00908c37d5 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Wed, 20 Nov 2024 19:33:17 +0530 Subject: [PATCH 10/15] Addressed the review comments --- src/definitions/constants.ts | 1 + src/liberty/devCommands.ts | 6 +++++- src/liberty/libertyProject.ts | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/definitions/constants.ts b/src/definitions/constants.ts index c05d7176..0bae8045 100644 --- a/src/definitions/constants.ts +++ b/src/definitions/constants.ts @@ -34,6 +34,7 @@ export const COMMAND_AND_PROJECT_TYPE_MAP: { [command: string]: string[] } = { }; export const EXCLUDED_DIR_PATTERN = "**/{bin,classes,target}/**"; export const COMMAND_TITLES = new Map(); +export const UNTITLED_WORKSPACE="Untitled (Workspace)"; COMMAND_TITLES.set(localize("hotkey.commands.title.refresh"), "liberty.explorer.refresh"); COMMAND_TITLES.set(localize("hotkey.commands.title.start"), "liberty.dev.start"); diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 9d1a1f4f..5b9a1b7c 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -174,7 +174,10 @@ function showListOfPathsToAdd(uris: string[]) { return; } if (projectProvider.isUntitledWorkspace()) { - //Saving the selected project to globalstate for adding it to the dashboard after reinitialization of the extension when workspace is saved + /** + * Saving the selected project to globalstate for adding it to the dashboard after + * reinitialization of the extension when workspace is saved + */ await projectProvider.getContext().globalState.update('selectedProject', selection); /* if the workspace is untitled suggest the user to save the workspace first @@ -616,6 +619,7 @@ async function getLocalGradleWrapper(projectFolder: string): Promise statusMessage.dispose(); } - /* - Method asks the user to save the workspace first if it is untitled and the workspace contains morethan - 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 - */ + /** + * Method asks the user to save the workspace first if it is untitled and the workspace contains morethan + * 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 { return new Promise((resolve) => { try { @@ -217,8 +217,10 @@ export class ProjectProvider implements vscode.TreeDataProvider 'Save Workspace' ).then(async (selection) => { 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 + /** + * 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); //opens the saveWorkspace as dialog box await vscode.commands.executeCommand('workbench.action.saveWorkspaceAs'); @@ -238,7 +240,7 @@ export class ProjectProvider implements vscode.TreeDataProvider public isUntitledWorkspace(): boolean { const workspaceFolders = vscode.workspace.workspaceFolders; if ((workspaceFolders && workspaceFolders.length > 1 - && vscode.workspace.name === "Untitled (Workspace)")) { + && vscode.workspace.name === UNTITLED_WORKSPACE)) { return true; } return false; From df90fcbd51cd4c6a02685981d616fa906e2bc9e9 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Fri, 22 Nov 2024 13:46:50 +0530 Subject: [PATCH 11/15] Addressed review comments --- src/definitions/constants.ts | 2 +- src/extension.ts | 16 +++++++++++----- src/liberty/dashboard.ts | 2 +- src/liberty/devCommands.ts | 2 +- src/liberty/libertyProject.ts | 16 +++++++++------- src/locales/en.json | 3 ++- src/util/helperUtil.ts | 2 +- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/definitions/constants.ts b/src/definitions/constants.ts index 0bae8045..4c42c9d7 100644 --- a/src/definitions/constants.ts +++ b/src/definitions/constants.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020, 2022 IBM Corporation. + * Copyright (c) 2020, 2024 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/extension.ts b/src/extension.ts index 074b144b..4c777888 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -110,11 +110,9 @@ function registerCommands(context: ExtensionContext) { projectProvider = new ProjectProvider(context); ProjectProvider.setInstance(projectProvider); } - if (projectProvider.getContext().globalState.get('workspaceSaveInProgress') && - projectProvider.getContext().globalState.get('selectedProject') !== undefined) { - devCommands.addProjectsToTheDashBoard(projectProvider, projectProvider.getContext().globalState.get('selectedProject') as string); - helperUtil.clearDataSavedInGlobalState(projectProvider.getContext()); - } + + handleWorkspaceSaveInProgress(projectProvider); + if (vscode.workspace.workspaceFolders !== undefined) { registerFileWatcher(projectProvider); vscode.window.registerTreeDataProvider("liberty-dev", projectProvider); @@ -262,3 +260,11 @@ async function getJavaExtensionAPI(): Promise { } return Promise.resolve(api); } + +function handleWorkspaceSaveInProgress(projectProvider: ProjectProvider) { + if (projectProvider.getContext().globalState.get('workspaceSaveInProgress') && + projectProvider.getContext().globalState.get('selectedProject') !== undefined) { + devCommands.addProjectsToTheDashBoard(projectProvider, projectProvider.getContext().globalState.get('selectedProject') as string); + helperUtil.clearDataSavedInGlobalState(projectProvider.getContext()); + } +} \ No newline at end of file diff --git a/src/liberty/dashboard.ts b/src/liberty/dashboard.ts index 901fed40..25f22e61 100644 --- a/src/liberty/dashboard.ts +++ b/src/liberty/dashboard.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2022 IBM Corporation. + * Copyright (c) 2024 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 93224138..2bf0db27 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -173,7 +173,7 @@ function showListOfPathsToAdd(uris: string[]) { if (!selection) { return; } - if (projectProvider.isUntitledWorkspace()) { + if (projectProvider.isMultiProjectUntitledWorkspace()) { /** * Saving the selected project to globalstate for adding it to the dashboard after * reinitialization of the extension when workspace is saved diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index eff8b87e..6ec07cb9 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -14,7 +14,7 @@ import * as gradleUtil from "../util/gradleUtil"; import * as mavenUtil from "../util/mavenUtil"; import * as util from "../util/helperUtil"; import { localize } from "../util/i18nUtil"; -import { EXCLUDED_DIR_PATTERN, LIBERTY_GRADLE_PROJECT, LIBERTY_GRADLE_PROJECT_CONTAINER, LIBERTY_MAVEN_PROJECT, LIBERTY_MAVEN_PROJECT_CONTAINER,UNTITLED_WORKSPACE } from "../definitions/constants"; +import { EXCLUDED_DIR_PATTERN, LIBERTY_GRADLE_PROJECT, LIBERTY_GRADLE_PROJECT_CONTAINER, LIBERTY_MAVEN_PROJECT, LIBERTY_MAVEN_PROJECT_CONTAINER, UNTITLED_WORKSPACE } from "../definitions/constants"; import { BuildFileImpl, GradleBuildFile } from "../util/buildFile"; import { DashboardData } from "./dashboard"; import { BaseLibertyProject } from "./baseLibertyProject"; @@ -204,15 +204,15 @@ export class ProjectProvider implements vscode.TreeDataProvider } /** - * Method asks the user to save the workspace first if it is untitled and the workspace contains morethan - * 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. + * This method asks the user to save the workspace first if it is untitled and the workspace contains more than + * one project. If the workspace is not saved, there are chances that the project's state may not be saved and + * manually added projects may not be visible in the Liberty dashboard in a new VS Code session. */ public async checkUntitledWorkspaceAndSaveIt(): Promise { return new Promise((resolve) => { try { vscode.window.showInformationMessage( - 'Please save the workspace first, as manually added projects to the dashboard may not persist in the next VS Code session if the workspace is not saved.', + localize("workspace.not.saved.projects.may.not.persist"), { modal: true }, 'Save Workspace' ).then(async (selection) => { @@ -229,15 +229,17 @@ export class ProjectProvider implements vscode.TreeDataProvider resolve(); }); } catch (error) { + util.clearDataSavedInGlobalState(this._context); + resolve(); console.debug("exception while saving the workspace" + error); } }); } /* - Method identifies a workspace that is untitled and containing more than one project + This method identifies a workspace that is untitled and contains more than one project */ - public isUntitledWorkspace(): boolean { + public isMultiProjectUntitledWorkspace(): boolean { const workspaceFolders = vscode.workspace.workspaceFolders; if ((workspaceFolders && workspaceFolders.length > 1 && vscode.workspace.name === UNTITLED_WORKSPACE)) { diff --git a/src/locales/en.json b/src/locales/en.json index 265ec37b..31389d78 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -71,5 +71,6 @@ "hotkey.commands.title.view.test.report": "Liberty: View test report", "hotkey.commands.title.add.project": "Liberty: Add Project to Liberty Dashboard", "hotkey.commands.title.remove.project": "Liberty: Remove Project from Liberty Dashboard", - "hotkey.commands.title.show.commands": "Liberty: Show Liberty commands" + "hotkey.commands.title.show.commands": "Liberty: Show Liberty commands", + "workspace.not.saved.projects.may.not.persist": "Please save the workspace first. Projects that are manually added to the Liberty dashboard may not persist in the next VS Code session if the workspace is not saved before adding the project." } diff --git a/src/util/helperUtil.ts b/src/util/helperUtil.ts index 4201975e..277ed455 100644 --- a/src/util/helperUtil.ts +++ b/src/util/helperUtil.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020, 2022 IBM Corporation. + * Copyright (c) 2020, 2024 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at From 98edff980201fbd8cddc744731b89aea8317d249 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Fri, 22 Nov 2024 14:16:19 +0530 Subject: [PATCH 12/15] added comment for clearing global state --- src/liberty/libertyProject.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 6ec07cb9..575f42d2 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -225,6 +225,11 @@ export class ProjectProvider implements vscode.TreeDataProvider //opens the saveWorkspace as dialog box await vscode.commands.executeCommand('workbench.action.saveWorkspaceAs'); } + /** + * If the user cancels saving the workspace and exits without saving, the data stays in the global state, + * which is shared across all VS Code instances. To prevent this data from being mistakenly used in other + * sessions and added to the dashboard, it should be cleared if the user cancels the save. + */ util.clearDataSavedInGlobalState(this._context); resolve(); }); From 822f81bfc341d0ef3c397acf8bdc0d8aa9c43c6d Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Sat, 23 Nov 2024 08:42:30 +0530 Subject: [PATCH 13/15] code changes after review --- src/liberty/dashboard.ts | 2 +- src/liberty/libertyProject.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liberty/dashboard.ts b/src/liberty/dashboard.ts index 25f22e61..901fed40 100644 --- a/src/liberty/dashboard.ts +++ b/src/liberty/dashboard.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024 IBM Corporation. + * Copyright (c) 2022 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 37586cb6..6672977b 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -234,9 +234,9 @@ export class ProjectProvider implements vscode.TreeDataProvider resolve(); }); } catch (error) { + console.debug("exception while saving the workspace" + error); util.clearDataSavedInGlobalState(this._context); resolve(); - console.debug("exception while saving the workspace" + error); } }); } From b9473a4e28f6c592efe8a40e3f0b30e52690e188 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Mon, 25 Nov 2024 11:44:55 +0530 Subject: [PATCH 14/15] calling handleWorkspaceSaveInProgress from activate --- src/extension.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 4c777888..5236345b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -63,7 +63,7 @@ export async function activate(context: vscode.ExtensionContext): Promise item.text = localize("liberty.ls.thumbs.up"); item.tooltip = localize("liberty.ls.started"); toggleItem(window.activeTextEditor, item); - + handleWorkspaceSaveInProgress(getProjectProvider(context)); registerCommands(context); }, (error: any) => { console.log("Liberty client was not ready. Did not initialize"); @@ -105,13 +105,7 @@ function bindRequest(request: string) { } function registerCommands(context: ExtensionContext) { - let projectProvider = ProjectProvider.getInstance(); - if ( !projectProvider ) { - projectProvider = new ProjectProvider(context); - ProjectProvider.setInstance(projectProvider); - } - - handleWorkspaceSaveInProgress(projectProvider); + let projectProvider = getProjectProvider(context); if (vscode.workspace.workspaceFolders !== undefined) { registerFileWatcher(projectProvider); @@ -267,4 +261,13 @@ function handleWorkspaceSaveInProgress(projectProvider: ProjectProvider) { devCommands.addProjectsToTheDashBoard(projectProvider, projectProvider.getContext().globalState.get('selectedProject') as string); helperUtil.clearDataSavedInGlobalState(projectProvider.getContext()); } +} + +function getProjectProvider(context: vscode.ExtensionContext) : ProjectProvider{ + let projectProvider = ProjectProvider.getInstance(); + if ( !projectProvider ) { + projectProvider = new ProjectProvider(context); + ProjectProvider.setInstance(projectProvider); + } + return projectProvider; } \ No newline at end of file From 883928ad327d1c1cf68cfdddb0702de050f222fd Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Mon, 25 Nov 2024 18:55:22 +0530 Subject: [PATCH 15/15] Passing context insted of projectProvider directly --- src/extension.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 5236345b..c1adf8f2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -63,7 +63,7 @@ export async function activate(context: vscode.ExtensionContext): Promise item.text = localize("liberty.ls.thumbs.up"); item.tooltip = localize("liberty.ls.started"); toggleItem(window.activeTextEditor, item); - handleWorkspaceSaveInProgress(getProjectProvider(context)); + handleWorkspaceSaveInProgress(context); registerCommands(context); }, (error: any) => { console.log("Liberty client was not ready. Did not initialize"); @@ -255,7 +255,8 @@ async function getJavaExtensionAPI(): Promise { return Promise.resolve(api); } -function handleWorkspaceSaveInProgress(projectProvider: ProjectProvider) { +function handleWorkspaceSaveInProgress(context: vscode.ExtensionContext) { + let projectProvider = getProjectProvider(context); if (projectProvider.getContext().globalState.get('workspaceSaveInProgress') && projectProvider.getContext().globalState.get('selectedProject') !== undefined) { devCommands.addProjectsToTheDashBoard(projectProvider, projectProvider.getContext().globalState.get('selectedProject') as string); @@ -263,11 +264,11 @@ function handleWorkspaceSaveInProgress(projectProvider: ProjectProvider) { } } -function getProjectProvider(context: vscode.ExtensionContext) : ProjectProvider{ +function getProjectProvider(context: vscode.ExtensionContext): ProjectProvider { let projectProvider = ProjectProvider.getInstance(); - if ( !projectProvider ) { - projectProvider = new ProjectProvider(context); - ProjectProvider.setInstance(projectProvider); - } + if (!projectProvider) { + projectProvider = new ProjectProvider(context); + ProjectProvider.setInstance(projectProvider); + } return projectProvider; } \ No newline at end of file