Skip to content

Conversation

@Flanker32
Copy link
Member

Add hierarchical package view, for issue #57

@Flanker32 Flanker32 requested a review from andxu November 30, 2018 08:52
}

protected createChildNodeList(): ExplorerNode[] {
if (Settings.isHierarchicalView()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simple to ? :

Copy link
Contributor

@yaohaizh yaohaizh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See commends. Mostly, you need packagerootnode designed.

package.json Outdated
"description": "Synchronize dependency viewer selection with folder explorer",
"default": true
},
"java.dependency.isHierarchicalView": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should avoid use this value. It is not clear to the end user what the opposite is?

Should be enum values: "flat", "hierarchy"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

if (!current) {
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the empty diff if possible. You can always provide another PR for format/coding convention to avoid distraction.

private packageTree: PackageTreeNode;

constructor(nodeData: INodeData, parent: DataNode, private _project: ProjectNode, packageTree: PackageTreeNode = null) {
super(nodeData, parent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should NOT mixed the flat package node and hierarchy package node in the same class. It violate SRP and will make the code hard to main in the future.

You can create two class/types for different purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an abstract class named HierarchicalNode , which includes createFlatChildNodeList , createHierarchicalChildNodeList and revealPath, and PackageRootNode extends it, i didn't split packagenode into two parts for there are still some common methods like loadData and getIconPath, other methods for Hierarchical was moved to HierachicalPackageRootSubNode

} else {
paths.shift();
this.revealPath(c, paths);
// Resove Hierarchical packages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Resolve ==> Resolve

src/settings.ts Outdated
}

public static isHierarchicalView(): boolean {
return this._depdendencyConfig.get("packagePresentation") === "hierarchical";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should avoid to use the configuration directly since the config may change at runtime, in your impl, change of this options will take effective on next update. see https://github.com/Microsoft/vscode-java-debug/blob/bcd69b52e4d941323cae662a154afd2a7852f43d/src/debugCodeLensProvider.ts#L38

package.json Outdated
"java.dependency.packagePresentation": {
"type": "string",
"enum":["flat","hierarchical"],
"description": "Set the presentation model of packages",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package presentation mode: flat or hierarchical

}
}

public addPackage(packageName: string): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addPackage constructor compressTree should be better organized to clearance to detect tree structures based on a list of packages:
a.b
a.b.c.d
a.b.c.d.e

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second this. Currently, the compressTree will not work for this case.


public static async convertPaths(paths: INodeData[]): Promise<INodeData[]> {
const index = paths.findIndex((nodeData) => nodeData.kind === NodeKind.PackageRoot);
const projectNodeData = paths.find((nodeData) => nodeData.kind === NodeKind.Project);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these operations are model oriented. You can compute the tree without creating a view.

For example, you can make the packagetree as a the model and build the hierarchy model outof the the view.


public addPackage(packageName: string): void {
const packages = packageName.split(".");
this.addSubPackage(packages);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.addSubPackage(packageName.split("."));

}
});
}
const packageNodeList = this.getHierarchicalPackageNodes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't introduce local var here


public packageTree: PackageTreeNode;

constructor(nodeData: INodeData, parent: DataNode, private _project: ProjectNode, packageTree: PackageTreeNode = null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= null should be removed

}

public async getRootNodeByData(nodeData: INodeData): Promise<DataNode> {
// Server only return project nodes, so use get root projects function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said, in order to get the data, creating the view is not an acceptable solution here. DON't mix the model with your view. You either either directly get the data from the server, or patch the Workspsace data to the path side.


export class HierachicalPackageRootSubNode extends DataNode {

public packageTree: PackageTreeNode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class code is duplicate with the HierarchicalPackageRootNode, could we model these two types in one class?

}

public getNodeDataFromPackageTreeNode(nodeData: INodeData): INodeData {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, this is an adapter that we can apply here.

}
}

public addPackage(packageName: string): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second this. Currently, the compressTree will not work for this case.

andxu
andxu previously approved these changes Dec 10, 2018
public async revealPaths(paths: INodeData[]): Promise<DataNode> {
const hierachicalNodeData = paths[0];
const childs: ExplorerNode[] = await this.getChildren();
const childNode = <DataNode>childs.find((child: DataNode) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null reference check.

Copy link
Contributor

@yaohaizh yaohaizh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix merge conflication

return HierachicalPackageNodeData.createHierachicalNodeDataByPackageList(nodeDataList);
} else {
// Return a empty hierachical node
return HierachicalPackageNodeData.createHierachicalNodeDataByPackageList([]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate call. You just need create package list with arguments. Not necessary two calls here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants