Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #264 - Fixes for manually added projects not being listed in the dashboard after re-opening IDE or workspace #372

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,7 +110,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);
helperUtil.clearDataSavedInGlobalState(projectProvider.getContext());
}
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved
if (vscode.workspace.workspaceFolders !== undefined) {
registerFileWatcher(projectProvider);
vscode.window.registerTreeDataProvider("liberty-dev", projectProvider);
Expand Down
25 changes: 20 additions & 5 deletions src/liberty/devCommands.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -173,10 +173,15 @@ 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()) {
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved
//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);
JoshwinThomasIBM marked this conversation as resolved.
Show resolved Hide resolved
/*
if the workspace is untitled suggest the user to save the workspace first
*/
await projectProvider.checkUntitledWorkspaceAndSaveIt();
}
await addProjectsToTheDashBoard(projectProvider, selection);
});
}

Expand Down Expand Up @@ -610,4 +615,14 @@ async function getLocalGradleWrapper(projectFolder: string): Promise<string | un
*/
function isWin(): boolean {
return process.platform.startsWith("win");
}
/*
aparnamichael marked this conversation as resolved.
Show resolved Hide resolved
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<void> {
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();
}
43 changes: 42 additions & 1 deletion src/liberty/libertyProject.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -203,6 +203,47 @@ export class ProjectProvider implements vscode.TreeDataProvider<LibertyProject>
statusMessage.dispose();
}

/*
Method asks the user to save the workspace first if it is untitled and the workspace contains morethan
aparnamichael marked this conversation as resolved.
Show resolved Hide resolved
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> {
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.',
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved
{ 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 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');
}
util.clearDataSavedInGlobalState(this._context);
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved
resolve();
});
} catch (error) {
console.debug("exception while saving the workspace" + error);
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved
}
});
}

/*
Method identifies a workspace that is untitled and containing more than one project
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved
*/
public isUntitledWorkspace(): boolean {
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved
const workspaceFolders = vscode.workspace.workspaceFolders;
if ((workspaceFolders && workspaceFolders.length > 1
&& vscode.workspace.name === "Untitled (Workspace)")) {
aparnamichael marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
return false;
}

public fireChangeEvent(): void {
this._onDidChangeTreeData.fire(undefined);
}
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);
}
TrevCraw marked this conversation as resolved.
Show resolved Hide resolved

Loading