Skip to content

Commit

Permalink
refactor: print label for maven packages only
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Milic committed Oct 18, 2024
1 parent 6800491 commit b0a6425
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 15 deletions.
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 {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<SymbolInformation[] | DocumentSymbol[] | undefined> {
if (!this.hasChildren() || !this.nodeData.uri) {
return undefined;
Expand Down
6 changes: 1 addition & 5 deletions src/views/containerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ export class ContainerNode extends DataNode {
}

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']}`;
} else {
return this._nodeData.displayName ?? this._nodeData.name;
}
return this._nodeData.displayName ?? this._nodeData.name;
}

public isMavenType(): boolean {
Expand Down
8 changes: 0 additions & 8 deletions src/views/dataNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ export abstract class DataNode extends ExplorerNode {
return item;
}

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']}`;
} else {
return this._nodeData.displayName ?? this._nodeData.name;
}
}

public get nodeData(): INodeData {
return this._nodeData;
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/dependencyDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
await this.getRootNodes() : await element.getChildren();

if (children && element instanceof ContainerNode) {
if (element.isMavenType() || element.isGradleType()) {
if (element.isMavenType()) {
children.sort((a, b) => {
return a.getLabel().localeCompare(b.getLabel());
});
Expand Down
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
12 changes: 11 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,16 @@ export class PackageRootNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
if (this.getParent() instanceof ContainerNode) {
const parent = this.getParent() as ContainerNode;
if (parent.getContainerType() == ContainerType.Maven) {
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

0 comments on commit b0a6425

Please sign in to comment.