Skip to content
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

ux - display maven and gradle dependencies with pattern 'groupId:artifactId:version ' #859

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{
"type": "java",
"name": "Attach to Plugin",
"projectName": "com.microsoft.jdtls.ext.core",
"request": "attach",
"hostName": "localhost",
"port": 1044
Expand Down
37 changes: 37 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# How to Contribute
jdneo marked this conversation as resolved.
Show resolved Hide resolved

We greatly appreciate contributions to the vscode-java-dependency project. Your efforts help us maintain and improve this extension. To ensure a smooth contribution process, please follow these guidelines.

## Prerequisites
- [JDK](https://www.oracle.com/java/technologies/downloads/?er=221886)
- [Node.JS](https://nodejs.org/en/)
- [VSCode](https://code.visualstudio.com/)

## Build and Run

To set up the vscode-java-dependency project, follow these steps:

1. **Build the Server JAR**:
- The server JAR (Java application) is located in the [jdtls.ext](./jdtls.ext) directory.
- Run the following command to build the server:
```shell
npm run build-server
```

2. **Install Dependencies**:
- Execute the following command to install the necessary dependencies:
```shell
npm install
```

3. **Run/Debug the Extension**:
- Open the "Run and Debug" view in Visual Studio Code.
- Run the "Run Extension" task.

4. **Attach to Plugin[Debug Java]**:
- Prerequisite: Ensure that the extension is activated, meaning the Java process is already launched. This is required for the task to run properly.
- Open the "Run and Debug" view in Visual Studio Code.
- Run the "Attach to Plugin" task.
jdneo marked this conversation as resolved.
Show resolved Hide resolved
- Note: This task is required only if you want to debug Java code [jdtls.ext](./jdtls.ext). It requires the [vscode-pde](https://marketplace.visualstudio.com/items?itemName=yaozheng.vscode-pde) extension to be installed.

Thank you for your contributions and support!
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -78,7 +79,7 @@ public class PackageCommand {
private static final Map<NodeKind, BiFunction<PackageParams, IProgressMonitor, List<PackageNode>>> commands;

static {
commands = new HashMap<>();
commands = new EnumMap<>(NodeKind.class);
commands.put(NodeKind.PROJECT, PackageCommand::getProjectChildren);
commands.put(NodeKind.CONTAINER, PackageCommand::getContainerChildren);
commands.put(NodeKind.PACKAGEROOT, PackageCommand::getPackageRootChildren);
Expand Down
4 changes: 4 additions & 0 deletions src/views/PrimaryTypeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class PrimaryTypeNode extends DataNode {
return "";
}

public getLabel(): string {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of introducing getLabel() into all different types. What about directly set the displayName at java side?

return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<SymbolInformation[] | DocumentSymbol[] | undefined> {
if (!this.hasChildren() || !this.nodeData.uri) {
return undefined;
Expand Down
25 changes: 19 additions & 6 deletions src/views/containerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,36 @@ export class ContainerNode extends DataNode {
super(nodeData, parent);
}

private _containerType: ContainerType;
jdneo marked this conversation as resolved.
Show resolved Hide resolved

public get projectBasePath() {
return this._project.uri && Uri.parse(this._project.uri).fsPath;
}

public getContainerType(): string {
public getContainerType(): ContainerType {
if (this._containerType) {
return this._containerType;
}

const containerPath: string = this._nodeData.path || "";
if (containerPath.startsWith(ContainerPath.JRE)) {
return ContainerType.JRE;
this._containerType = ContainerType.JRE;
} else if (containerPath.startsWith(ContainerPath.Maven)) {
return ContainerType.Maven;
this._containerType = ContainerType.Maven;
} else if (containerPath.startsWith(ContainerPath.Gradle)) {
return ContainerType.Gradle;
this._containerType = ContainerType.Gradle;
} else if (containerPath.startsWith(ContainerPath.ReferencedLibrary) && this._project.isUnmanagedFolder()) {
// currently, we only support editing referenced libraries in unmanaged folders
return ContainerType.ReferencedLibrary;
this._containerType = ContainerType.ReferencedLibrary;
} else {
this._containerType = ContainerType.Unknown;
}
return ContainerType.Unknown;

return this._containerType;
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/views/dataNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class DataNode extends ExplorerNode {

public getTreeItem(): TreeItem | Promise<TreeItem> {
const item = new TreeItem(
this._nodeData.displayName || this._nodeData.name,
this.getLabel(),
this.hasChildren() ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None,
);
item.description = this.description;
Expand Down
6 changes: 6 additions & 0 deletions src/views/dependencyDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
const children = (!this._rootItems || !element) ?
await this.getRootNodes() : await element.getChildren();

if (children) {
children.sort((a, b) => {
return a.getLabel().localeCompare(b.getLabel());
});
}

explorerNodeCache.saveNodes(children || []);
return children;
}
Expand Down
6 changes: 5 additions & 1 deletion src/views/documentSymbolNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class DocumentSymbolNode extends ExplorerNode {
super(parent);
}

public getLabel(): string {
return this.symbolInfo.name;
}

public getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
const res: ExplorerNode[] = [];
if (this.symbolInfo?.children?.length) {
Expand All @@ -39,7 +43,7 @@ export class DocumentSymbolNode extends ExplorerNode {
}

public getTreeItem(): TreeItem | Promise<TreeItem> {
const item = new TreeItem(this.symbolInfo.name,
const item = new TreeItem(this.getLabel(),
this.symbolInfo?.children?.length ? TreeItemCollapsibleState.Collapsed
: TreeItemCollapsibleState.None);
item.iconPath = this.iconPath;
Expand Down
2 changes: 2 additions & 0 deletions src/views/explorerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export abstract class ExplorerNode {
public abstract getTreeItem(): TreeItem | Promise<TreeItem>;

public abstract computeContextValue(): string | undefined;

public abstract getLabel(): string;
}
4 changes: 4 additions & 0 deletions src/views/fileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export class FileNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected hasChildren(): boolean {
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions src/views/folderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class FolderNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[]> {
return Jdtls.getPackageData({
kind: NodeKind.Folder,
Expand Down
4 changes: 4 additions & 0 deletions src/views/packageNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class PackageNode extends DataNode {
return parentData.entryKind === PackageRootKind.K_SOURCE || parentData.kind === NodeKind.Project;
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[]> {
return Jdtls.getPackageData({
kind: NodeKind.Package,
Expand Down
9 changes: 8 additions & 1 deletion src/views/packageRootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { INodeData, NodeKind } from "../java/nodeData";
import { IPackageRootNodeData, PackageRootKind } from "../java/packageRootNodeData";
import { Settings } from "../settings";
import { isTest } from "../utility";
import { ContainerNode } from "./containerNode";
import { ContainerNode, ContainerType } from "./containerNode";
import { DataNode } from "./dataNode";
import { ExplorerNode } from "./explorerNode";
import { ProjectNode } from "./projectNode";
Expand All @@ -20,6 +20,13 @@ export class PackageRootNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
if (this._nodeData.metaData?.['maven.groupId']) {
return `${this._nodeData.metaData?.['maven.groupId']}:${this._nodeData.metaData?.['maven.artifactId']}:${this._nodeData.metaData?.['maven.version']}`;
}
return this._nodeData.displayName ?? this._nodeData.name;
}

public isSourceRoot(): boolean {
return (<IPackageRootNodeData>this.nodeData).entryKind === PackageRootKind.K_SOURCE;
}
Expand Down
4 changes: 4 additions & 0 deletions src/views/projectNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class ProjectNode extends DataNode {
return false;
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[]> {
return Jdtls.getPackageData({ kind: NodeKind.Project, projectUri: this.nodeData.uri });
}
Expand Down
4 changes: 4 additions & 0 deletions src/views/workspaceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class WorkspaceNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[] | undefined> {
if (!this.nodeData.uri) {
return undefined;
Expand Down