Skip to content

Commit

Permalink
Merge pull request #234 from sebjulliand/fix/clearExtensibleChildren
Browse files Browse the repository at this point in the history
Fixed explorer crashing when refreshing project with extensible children
  • Loading branch information
edmundreinhardt authored Oct 3, 2023
2 parents 05e8711 + de9f113 commit e43e932
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions src/views/projectExplorer/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
*/

import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder, l10n } from "vscode";
import { ProjectExplorerTreeItem } from "./projectExplorerTreeItem";
import { ProjectManager } from "../../projectManager";
import { IProjectT } from "../../iProjectT";
import { getInstance } from "../../ibmi";
import ErrorItem from "./errorItem";
import Variables from "./variables";
import ObjectLibraries from "./objectlibraries";
import { ContextValue } from "../../ibmiProjectExplorer";
import { IProject } from "../../iproject";
import { ProjectManager } from "../../projectManager";
import ErrorItem from "./errorItem";
import IncludePaths from "./includePaths";
import Source from "./source";
import LibraryList from "./libraryList";
import { IProjectT } from "../../iProjectT";
import ObjectLibraries from "./objectlibraries";
import { ProjectExplorerTreeItem } from "./projectExplorerTreeItem";
import Source from "./source";
import Variables from "./variables";

/**
* Tree item for a project.
*/
export default class Project extends TreeItem implements ProjectExplorerTreeItem {
static contextValue = ContextValue.project;
static callBack: ((iProject: IProject) => Promise<ProjectExplorerTreeItem[]>)[] = [];
private extensibleChildren: ProjectExplorerTreeItem[] = [];
public children: ProjectExplorerTreeItem[] = [];
private readonly extensibleChildren: ProjectExplorerTreeItem[] = [];
public readonly children: ProjectExplorerTreeItem[] = [];

constructor(public workspaceFolder: WorkspaceFolder, state?: IProjectT) {
super(workspaceFolder.name, TreeItemCollapsibleState.Collapsed);
Expand All @@ -42,21 +42,22 @@ export default class Project extends TreeItem implements ProjectExplorerTreeItem
}

async getChildren(): Promise<ProjectExplorerTreeItem[]> {
let items: ProjectExplorerTreeItem[] = [];

this.children.splice(0, this.children.length);
this.extensibleChildren.splice(0, this.extensibleChildren.length);

const ibmi = getInstance();
const iProject = ProjectManager.get(this.workspaceFolder);

if (ibmi && ibmi.getConnection()) {
const deploymentParameters = await iProject?.getDeploymentParameters();

if (deploymentParameters && deploymentParameters.remotePath) {
items.push(new Source(this.workspaceFolder, deploymentParameters));
this.children.push(new Source(this.workspaceFolder, deploymentParameters));
} else {
items.push(ErrorItem.createNoDeployLocationError(this.workspaceFolder));
this.children.push(ErrorItem.createNoDeployLocationError(this.workspaceFolder));
}
} else {
items.push(ErrorItem.createNoConnectionError(this.workspaceFolder, l10n.t('Source')));
this.children.push(ErrorItem.createNoConnectionError(this.workspaceFolder, l10n.t('Source')));
}

const hasEnv = await iProject?.projectFileExists('.env');
Expand All @@ -69,21 +70,21 @@ export default class Project extends TreeItem implements ProjectExplorerTreeItem
unresolvedVariableCount = possibleVariables.filter(varName => !actualValues[varName]).length;
}

items.push(new Variables(this.workspaceFolder, unresolvedVariableCount));
this.children.push(new Variables(this.workspaceFolder, unresolvedVariableCount));

} else {
items.push(ErrorItem.createNoEnvironmentVariablesError(this.workspaceFolder));
this.children.push(ErrorItem.createNoEnvironmentVariablesError(this.workspaceFolder));
}

if (ibmi && ibmi.getConnection()) {
items.push(new LibraryList(this.workspaceFolder));
items.push(new ObjectLibraries(this.workspaceFolder));
this.children.push(new LibraryList(this.workspaceFolder));
this.children.push(new ObjectLibraries(this.workspaceFolder));
} else {
items.push(ErrorItem.createNoConnectionError(this.workspaceFolder, l10n.t('Library List')));
items.push(ErrorItem.createNoConnectionError(this.workspaceFolder, l10n.t('Object Libraries')));
this.children.push(ErrorItem.createNoConnectionError(this.workspaceFolder, l10n.t('Library List')));
this.children.push(ErrorItem.createNoConnectionError(this.workspaceFolder, l10n.t('Object Libraries')));
}

items.push(new IncludePaths(this.workspaceFolder));
this.children.push(new IncludePaths(this.workspaceFolder));

for await (const extensibleChildren of Project.callBack) {
let children: ProjectExplorerTreeItem[] = [];
Expand All @@ -93,10 +94,8 @@ export default class Project extends TreeItem implements ProjectExplorerTreeItem

this.extensibleChildren.push(...children);
}
items.push(...this.extensibleChildren);

this.children = items;
return items;
return [...this.children, ...this.extensibleChildren];
}

getExtensibleChildren() {
Expand Down

0 comments on commit e43e932

Please sign in to comment.