-
Notifications
You must be signed in to change notification settings - Fork 91
Add hierarchical package view, for issue #57 #117
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
Conversation
…efactor get node function of package root
src/views/packageRootNode.ts
Outdated
| } | ||
|
|
||
| protected createChildNodeList(): ExplorerNode[] { | ||
| if (Settings.isHierarchicalView()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simple to ? :
yaohaizh
left a comment
There was a problem hiding this 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": { |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
| if (!current) { | ||
| return; | ||
| } | ||
|
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
src/views/dependencyExplorer.ts
Outdated
| } else { | ||
| paths.shift(); | ||
| this.revealPath(c, paths); | ||
| // Resove Hierarchical packages |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
src/java/packageTreeNode.ts
Outdated
| } | ||
| } | ||
|
|
||
| public addPackage(packageName: string): void { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
src/java/packageTreeNode.ts
Outdated
|
|
||
| public addPackage(packageName: string): void { | ||
| const packages = packageName.split("."); | ||
| this.addSubPackage(packages); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= null should be removed
src/views/dependencyDataProvider.ts
Outdated
| } | ||
|
|
||
| public async getRootNodeByData(nodeData: INodeData): Promise<DataNode> { | ||
| // Server only return project nodes, so use get root projects function |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
src/java/packageTreeNode.ts
Outdated
| } | ||
|
|
||
| public getNodeDataFromPackageTreeNode(nodeData: INodeData): INodeData { | ||
| return { |
There was a problem hiding this comment.
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.
src/java/packageTreeNode.ts
Outdated
| } | ||
| } | ||
|
|
||
| public addPackage(packageName: string): void { |
There was a problem hiding this comment.
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 async revealPaths(paths: INodeData[]): Promise<DataNode> { | ||
| const hierachicalNodeData = paths[0]; | ||
| const childs: ExplorerNode[] = await this.getChildren(); | ||
| const childNode = <DataNode>childs.find((child: DataNode) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null reference check.
yaohaizh
left a comment
There was a problem hiding this 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([]); |
There was a problem hiding this comment.
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.
Add hierarchical package view, for issue #57