fix bug: show empty dependencies node (#661)

This commit is contained in:
Melody618 2021-08-17 18:51:36 +08:00 коммит произвёл GitHub
Родитель 7f5338c6fc
Коммит 7856e00c8b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 32 добавлений и 6 удалений

Просмотреть файл

@ -6,6 +6,7 @@ import { diagnosticProvider } from "../../DiagnosticProvider";
import { parseRawDependencyDataHandler } from "../../handlers/parseRawDependencyDataHandler";
import { getPathToExtensionRoot } from "../../utils/contextUtils";
import { Dependency } from "./Dependency";
import { HintNode } from "./HintNode";
import { ITreeItem } from "./ITreeItem";
import { MavenProject } from "./MavenProject";
import { Menu } from "./Menu";
@ -20,10 +21,15 @@ export class DependenciesMenu extends Menu implements ITreeItem {
return "DependenciesMenu";
}
public async getChildren() : Promise<Dependency[]> {
public async getChildren() : Promise<Dependency[] | HintNode[]> {
const [treeNodes, conflictNodes] = await parseRawDependencyDataHandler(this.project);
await diagnosticProvider.refreshDiagnostics(vscode.Uri.file(this.project.pomPath), conflictNodes);
return Promise.resolve(treeNodes);
if (treeNodes.length === 0) {
const hintNodes: HintNode[] = [new HintNode("No dependencies")];
return Promise.resolve(hintNodes);
} else {
return Promise.resolve(treeNodes);
}
}
public getTreeItem(): vscode.TreeItem | Thenable<vscode.TreeItem> {

Просмотреть файл

@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
import { ITreeItem } from "./ITreeItem";
export class HintNode implements ITreeItem {
private _msg: string;
constructor(msg: string) {
this._msg = msg;
}
public getContextValue(): string {
return "HintNode";
}
public getTreeItem(): vscode.TreeItem | Thenable<vscode.TreeItem> {
const treeItem: vscode.TreeItem = new vscode.TreeItem("");
treeItem.description = this._msg;
return treeItem;
}
}

Просмотреть файл

@ -156,9 +156,7 @@ export class MavenProject implements ITreeItem {
const ret: ITreeItem[] = [];
ret.push(new LifecycleMenu(this));
ret.push(new PluginsMenu(this));
if (this.packaging !== "pom") { // hide the "Dependencies" item for "pom" project
ret.push(new DependenciesMenu(this));
}
ret.push(new DependenciesMenu(this));
if (this.moduleNames.length > 0 && Settings.viewType() === "hierarchical") {
const projects: MavenProject[] = <MavenProject[]>this.modules.map(m => mavenExplorerProvider.getMavenProject(m)).filter(Boolean);
ret.push(...projects);

Просмотреть файл

@ -44,7 +44,7 @@ export async function rawDependencyTree(pomPath: string): Promise<any> {
const dependencyGraphPath: string = `${outputPath}.deps.txt`;
const outputDirectory: string = path.dirname(dependencyGraphPath);
const outputFileName: string = path.basename(dependencyGraphPath);
await executeInBackground(`com.github.ferstl:depgraph-maven-plugin:graph -DgraphFormat=text -DshowDuplicates -DshowConflicts -DshowVersions -DshowGroupIds -DoutputDirectory="${outputDirectory}" -DoutputFileName="${outputFileName}"`, pomPath);
await executeInBackground(`-N com.github.ferstl:depgraph-maven-plugin:graph -DgraphFormat=text -DshowDuplicates -DshowConflicts -DshowVersions -DshowGroupIds -DoutputDirectory="${outputDirectory}" -DoutputFileName="${outputFileName}"`, pomPath);
return await readFileIfExists(path.join(outputDirectory, outputFileName));
}