-
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
Changes from 10 commits
95bf714
6c8fad4
11269cd
4cbf6f7
19e1c0b
8b29ec1
053c463
cc21dcd
bfd578b
4e75cad
fdc2cb7
44fb789
6055b4b
bc78c92
7854efc
3543836
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { INodeData, NodeKind } from "./nodeData"; | ||
|
|
||
| export class PackageTreeNode { | ||
|
|
||
| public static createEmptyRootNode(): PackageTreeNode { | ||
| return new PackageTreeNode("", ""); | ||
| } | ||
|
|
||
| public name: string; | ||
| public fullName: string; | ||
| public childs: PackageTreeNode[] = []; | ||
| public isPackage: boolean = false; | ||
|
|
||
| private constructor(name: string, parentFullName: string) { | ||
| this.name = name; | ||
| this.fullName = parentFullName === "" ? name : parentFullName + "." + name; | ||
| } | ||
|
|
||
| public addPackage(packageName: string): void { | ||
| const packages = packageName.split("."); | ||
| this.addSubPackage(packages); | ||
|
||
| } | ||
|
|
||
| public compressTree(): void { | ||
Flanker32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Don't compress the root node | ||
| while (this.name !== "" && this.childs.length === 1 && !this.isPackage) { | ||
| const child = this.childs[0]; | ||
| this.fullName = this.fullName + "." + child.name; | ||
| this.name = this.name + "." + child.name; | ||
| this.childs = child.childs; | ||
| this.isPackage = child.isPackage; | ||
| } | ||
| this.childs.forEach((child) => child.compressTree()); | ||
| } | ||
|
|
||
| public getNodeDataFromPackageTreeNode(nodeData: INodeData): INodeData { | ||
| return { | ||
|
||
| name: this.name, | ||
| moduleName: nodeData.moduleName, | ||
| path: nodeData.path, | ||
| uri: null, | ||
| kind: NodeKind.PackageRoot, | ||
| children: null, | ||
| }; | ||
| } | ||
|
|
||
| private addSubPackage(packages: string[]): void { | ||
| if (!packages.length) { | ||
| this.isPackage = true; | ||
| return; | ||
| } | ||
| const subPackageName = packages.shift(); | ||
| const childNode = this.childs.find((child) => child.name === subPackageName); | ||
| if (childNode) { | ||
| childNode.addSubPackage(packages); | ||
| } else { | ||
| const newNode = new PackageTreeNode(subPackageName, this.fullName); | ||
| newNode.addSubPackage(packages); | ||
| this.childs.push(newNode); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,8 @@ export class Settings { | |
| return; | ||
| } | ||
| const updatedConfig = workspace.getConfiguration("java.dependency"); | ||
| if (updatedConfig.showOutline !== this._depdendencyConfig.showOutline) { | ||
| if (updatedConfig.showOutline !== this._depdendencyConfig.showOutline | ||
| || updatedConfig.packagePresentation !== this._depdendencyConfig.packagePresentation) { | ||
| commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH); | ||
| } | ||
| this._depdendencyConfig = updatedConfig; | ||
|
|
@@ -28,5 +29,9 @@ export class Settings { | |
| return this._depdendencyConfig.get("syncWithFolderExplorer"); | ||
| } | ||
|
|
||
| public static isHierarchicalView(): boolean { | ||
| return this._depdendencyConfig.get("packagePresentation") === "hierarchical"; | ||
|
||
| } | ||
|
|
||
| private static _depdendencyConfig: WorkspaceConfiguration = workspace.getConfiguration("java.dependency"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { Commands } from "../commands"; | |
| import { Jdtls } from "../java/jdtls"; | ||
| import { INodeData, NodeKind } from "../java/nodeData"; | ||
| import { Telemetry } from "../telemetry"; | ||
| import { DataNode } from "./dataNode"; | ||
| import { ExplorerNode } from "./explorerNode"; | ||
| import { ProjectNode } from "./projectNode"; | ||
| import { WorkspaceNode } from "./workspaceNode"; | ||
|
|
@@ -67,6 +68,37 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> { | |
| return element.getParent(); | ||
| } | ||
|
|
||
| public async getRootNodeByData(nodeData: INodeData): Promise<DataNode> { | ||
| // Server only return project nodes, so use get root projects function | ||
|
||
| const rootNodes: ExplorerNode[] = await this.getRootProjects(); | ||
| return <DataNode>rootNodes.find((node: DataNode) => node.path === nodeData.path && node.nodeData.name === nodeData.name); | ||
| } | ||
|
|
||
| private async getRootProjects(): Promise<ExplorerNode[]> { | ||
| let result = new Array<ExplorerNode>(); | ||
| const folders = workspace.workspaceFolders; | ||
| if (folders && folders.length) { | ||
| if (folders.length > 1) { | ||
| const workspaces = folders.map((folder) => new WorkspaceNode({ | ||
| name: folder.name, | ||
| uri: folder.uri.toString(), | ||
| kind: NodeKind.Workspace, | ||
| }, null)); | ||
| // return projects of all workspaces | ||
| for (const singleworkspace of workspaces) { | ||
| const projects = await singleworkspace.getChildren(); | ||
| result = result.concat(projects); | ||
| } | ||
| } else { | ||
| const projectsNodeData = await Jdtls.getProjects(folders[0].uri.toString()); | ||
| projectsNodeData.forEach((project) => { | ||
| result.push(new ProjectNode(project, null)); | ||
| }); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| private getRootNodes(): Thenable<ExplorerNode[]> { | ||
| return new Promise((resolve, reject) => { | ||
| this._rootItems = new Array<ExplorerNode>(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,10 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { ExtensionContext, ProviderResult, TextEditor, TreeView, TreeViewVisibilityChangeEvent, Uri, window } from "vscode"; | ||
| import { ExtensionContext, TextEditor, TreeView, TreeViewVisibilityChangeEvent, Uri, window } from "vscode"; | ||
| import { Jdtls } from "../java/jdtls"; | ||
| import { INodeData } from "../java/nodeData"; | ||
| import { Settings } from "../settings"; | ||
| import { Utility } from "../utility"; | ||
| import { DataNode } from "./dataNode"; | ||
| import { DependencyDataProvider } from "./dependencyDataProvider"; | ||
| import { ExplorerNode } from "./explorerNode"; | ||
|
|
@@ -39,44 +38,17 @@ export class DependencyExplorer { | |
| public dispose(): void { | ||
| } | ||
|
|
||
| public reveal(uri: Uri): void { | ||
| Jdtls.resolvePath(uri.toString()).then((paths: INodeData[]) => { | ||
| this.revealPath(this._dataProvider, paths); | ||
| }); | ||
| } | ||
|
|
||
| private revealPath(current: { getChildren: (element?: ExplorerNode) => ProviderResult<ExplorerNode[]> }, paths: INodeData[]) { | ||
| if (!current) { | ||
| return; | ||
| public async reveal(uri: Uri): Promise<void> { | ||
| const paths: INodeData[] = await Jdtls.resolvePath(uri.toString()); | ||
| // Get correspond project node from dataProvider | ||
| let node = await this._dataProvider.getRootNodeByData(paths.shift()); | ||
| while (paths.length && node) { | ||
| node = await node.getCorrespondChildNodeWithNodeData(paths.shift()); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| const res = current.getChildren(); | ||
| if (Utility.isThenable(res)) { | ||
| res.then((children: DataNode[]) => { | ||
| this.visitChildren(children, paths); | ||
| }); | ||
| if (this._dependencyViewer.visible) { | ||
| this._dependencyViewer.reveal(node); | ||
| } else { | ||
| this.visitChildren(<DataNode[]>res, paths); | ||
| } | ||
| } | ||
|
|
||
| private visitChildren(children: DataNode[], paths: INodeData[]): void { | ||
| if (children && paths) { | ||
| for (const c of children) { | ||
| if (paths[0] && c.path === paths[0].path && c.nodeData.name === paths[0].name) { | ||
| if (paths.length === 1) { | ||
| if (this._dependencyViewer.visible) { | ||
| this._dependencyViewer.reveal(c); | ||
| } else { | ||
| this._selectionWhenHidden = c; | ||
| } | ||
| } else { | ||
| paths.shift(); | ||
| this.revealPath(c, paths); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| this._selectionWhenHidden = node; | ||
| } | ||
| } | ||
| } | ||
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.