Skip to content

Commit

Permalink
changes to handle single project opened in vs code for the manual pro…
Browse files Browse the repository at this point in the history
…ject add issue
  • Loading branch information
JoshwinThomasIBM authored and JoshwinThomasIBM committed Nov 18, 2024
1 parent bbb61bf commit faae8ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 12 additions & 19 deletions src/liberty/libertyProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class ProjectProvider implements vscode.TreeDataProvider<LibertyProject>
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<void>{
public async checkUntitledWorkspaceAndSaveIt(): Promise<void> {
return new Promise((resolve) => {
try {
vscode.window.showInformationMessage(
Expand All @@ -219,35 +219,28 @@ export class ProjectProvider implements vscode.TreeDataProvider<LibertyProject>
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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/util/helperUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ export function getStorageData(context: vscode.ExtensionContext): DashboardData
export async function saveStorageData(context: vscode.ExtensionContext, dasboardData: DashboardData): Promise<void>{
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);
}

0 comments on commit faae8ce

Please sign in to comment.