Skip to content

Commit

Permalink
Merge pull request #522 from IBM/feature/build-map-event
Browse files Browse the repository at this point in the history
Add event for `buildMap` changes
  • Loading branch information
edmundreinhardt authored Jul 5, 2024
2 parents 44c6943 + 26adb7d commit 1e6683f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/fileWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export namespace ProjectFileWatcher {
iProject.setLibraryList(undefined);

ProjectManager.fire({ type: 'projects', iProject });
ProjectManager.fire({ type: 'buildMap', iProject, uri });
} else if (uri.path.endsWith('iproj.json') && (type === 'delete')) {
const activeProject = ProjectManager.getActiveProject();

Expand All @@ -64,6 +65,8 @@ export namespace ProjectFileWatcher {
}
} else if (uri.fsPath.endsWith('.ibmi.json')) {
iProject.setBuildMap(undefined);

ProjectManager.fire({ type: 'buildMap', iProject, uri });
} else if (uri.fsPath.endsWith('.env')) {
// If the .env was updated only for keeping track of the LIBL state for other
// extensions, then we don't want to refresh the UI and state
Expand Down
12 changes: 12 additions & 0 deletions src/iproject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export class IProject {
this.deploymentMethod = 'compare';
}

/**
* Load the project's `iproj.json` and all `.ibmi.json` files.
*/
public async load() {
await this.getState();
await this.getBuildMap();
}

/**
* Get the project's name. *Note* that the project's name and associated
* workspace folder name are the same.
Expand Down Expand Up @@ -362,6 +370,10 @@ export class IProject {
*/
public setBuildMap(buildMap: Map<string, IBMiJsonT> | undefined) {
this.buildMap = buildMap;

if (!this.buildMap) {
this.updateBuildMap();
}
}

/**
Expand Down
21 changes: 18 additions & 3 deletions src/projectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ export enum ProjectExplorerSchemaId {
* - `projects` event is fired when there is a change to some project (create, update, or delete)
* - `activeProject` event is fired when there is a change to the active project
* - `libraryList` event is fired when there is a change to a project's library list
* - `buildMap` event is fired when there is a change to a project's `.ibmi.json` file
* - `deployLocation` event is fired when there is a change to a project's deploy location
* - `build` event is fired when a build is finished
* - `compile` event is fired when a compile is finished
* - `includePaths` event is fired when there is a change to a project's include paths
*/
export type ProjectExplorerEventT = 'projects' | 'activeProject' | 'libraryList' | 'deployLocation' | 'build' | 'compile' | 'includePaths';
export type ProjectExplorerEventCallback = (iProject?: IProject) => void;
export type ProjectExplorerEventT =
'projects' |
'activeProject' |
'libraryList' |
'buildMap' |
'deployLocation' |
'build' |
'compile' |
'includePaths';
export type ProjectExplorerEventCallback = (iProject?: IProject, uri?: Uri) => void;

/**
* Project explorer event
Expand All @@ -47,6 +56,11 @@ export interface ProjectExplorerEvent {
* Project associated with event
*/
iProject?: IProject

/**
* A uri associated with the event
*/
uri?: Uri
}

/**
Expand Down Expand Up @@ -105,7 +119,7 @@ export class ProjectManager {

this.emitter.event(e => {
this.events.filter(event => event.event === e.type)
.forEach(event => event.callback(e.iProject));
.forEach(event => event.callback(e?.iProject, e?.uri));
});

this.activeProjectStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 9);
Expand Down Expand Up @@ -170,6 +184,7 @@ export class ProjectManager {
public static async load(workspaceFolder: WorkspaceFolder) {
const iProject = new IProject(workspaceFolder);
if (!this.loaded[workspaceFolder.index]) {
await iProject.load();
this.loaded[workspaceFolder.index] = iProject;

const metadataExists = await iProject.projectFileExists('iproj.json');
Expand Down

0 comments on commit 1e6683f

Please sign in to comment.