diff --git a/src/fileWatcher.ts b/src/fileWatcher.ts index c5c7cb0b..14abb34a 100644 --- a/src/fileWatcher.ts +++ b/src/fileWatcher.ts @@ -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(); @@ -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 diff --git a/src/iproject.ts b/src/iproject.ts index 1d0ec930..d7c2d08f 100644 --- a/src/iproject.ts +++ b/src/iproject.ts @@ -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. @@ -362,6 +370,10 @@ export class IProject { */ public setBuildMap(buildMap: Map | undefined) { this.buildMap = buildMap; + + if (!this.buildMap) { + this.updateBuildMap(); + } } /** diff --git a/src/projectManager.ts b/src/projectManager.ts index 23c66ca0..d7176b97 100644 --- a/src/projectManager.ts +++ b/src/projectManager.ts @@ -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 @@ -47,6 +56,11 @@ export interface ProjectExplorerEvent { * Project associated with event */ iProject?: IProject + + /** + * A uri associated with the event + */ + uri?: Uri } /** @@ -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); @@ -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');