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

feat: Support dependency view #887

Merged
merged 3 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[java]": {
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle",
"editor.defaultFormatter": "redhat.java",
"editor.codeActionsOnSave": {
"source.fixAll.spotlessGradle": true
}
Expand Down
20 changes: 17 additions & 3 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"gradleContainerView": [
{
"id": "gradleTasksView",
"name": "Gradle Tasks",
"name": "Gradle Projects",
"when": "gradle:activated"
},
{
Expand Down Expand Up @@ -216,15 +216,15 @@
},
{
"command": "gradle.explorerFlat",
"title": "Show Flat List",
"title": "Show Flat Tasks",
"icon": {
"light": "resources/light/list-flat.svg",
"dark": "resources/dark/list-flat.svg"
}
},
{
"command": "gradle.explorerTree",
"title": "Show Tree",
"title": "Show Hierarchical Tasks",
"icon": {
"light": "resources/light/list-tree.svg",
"dark": "resources/dark/list-tree.svg"
Expand Down Expand Up @@ -285,6 +285,11 @@
"light": "resources/light/loading.svg",
"dark": "resources/dark/loading.svg"
}
},
{
"command": "gradle.omitted.reveal",
"title": "Go to Omitted Dependency",
"icon": "$(go-to-file)"
}
],
"menus": {
Expand Down Expand Up @@ -396,6 +401,10 @@
{
"command": "gradle.removeRecentTask",
"when": "false"
},
{
"command": "gradle.omitted.reveal",
"when": "false"
}
],
"view/title": [
Expand Down Expand Up @@ -539,6 +548,11 @@
"when": "view == gradleDaemonsView && viewItem =~ /^busy$|^idle$/",
"group": "inline@0"
},
{
"command": "gradle.omitted.reveal",
"when": "view == gradleTasksView && viewItem == omitted",
"group": "inline@0"
},
{
"command": "gradle.stopDaemon",
"when": "view == gradleDaemonsView && viewItem =~ /^busy$|^idle$/",
Expand Down
15 changes: 14 additions & 1 deletion extension/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
getConfigReuseTerminals,
} from './util/config';
import { FileWatcher } from './util/FileWatcher';
import { DependencyTreeItem } from './views/gradleTasks/DependencyTreeItem';
import { GRADLE_OMITTED_REVEAL } from './views/gradleTasks/DependencyUtils';

export class Extension {
private readonly client: GradleClient;
Expand Down Expand Up @@ -104,7 +106,8 @@ export class Extension {
this.context,
this.rootProjectsStore,
this.gradleTaskProvider,
this.icons
this.icons,
this.client
);
this.gradleTasksTreeView = vscode.window.createTreeView(GRADLE_TASKS_VIEW, {
treeDataProvider: this.gradleTasksTreeDataProvider,
Expand Down Expand Up @@ -182,6 +185,16 @@ export class Extension {
this.handleWatchEvents();
this.handleEditorEvents();

vscode.commands.registerCommand(
GRADLE_OMITTED_REVEAL,
async (item: DependencyTreeItem) => {
const omittedTreeItem = item.getOmittedTreeItem();
if (omittedTreeItem) {
await this.gradleTasksTreeView.reveal(omittedTreeItem);
}
}
);

void this.activate();
}

Expand Down
39 changes: 39 additions & 0 deletions extension/src/client/GradleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import {
CancelBuildReply,
CancelBuildsRequest,
CancelBuildsReply,
DependencyItem,
GetDependenciesRequest,
GetDependenciesReply,
} from '../proto/gradle_pb';

import { GradleClient as GrpcClient } from '../proto/gradle_grpc_pb';
Expand Down Expand Up @@ -223,6 +226,42 @@ export class GradleClient implements vscode.Disposable {
);
}

public async getDependencies(
projectDir: string,
gradleConfig: GradleConfig
): Promise<DependencyItem | undefined> {
await this.waitForConnect();
const request = new GetDependenciesRequest();
request.setProjectDir(projectDir);
request.setGradleConfig(gradleConfig);
try {
return await new Promise((resolve, reject) => {
this.grpcClient!.getDependencies(
request,
(
err: grpc.ServiceError | null,
getDependenciesReply: GetDependenciesReply | undefined
) => {
if (err) {
reject(err);
} else {
resolve(getDependenciesReply?.getItem());
}
}
);
});
} catch (err) {
logger.error(
`Error getting dependencies for ${projectDir}: ${
err.details || err.message
}`
);
this.statusBarItem.command = COMMAND_SHOW_LOGS;
this.statusBarItem.text = '$(warning) Gradle: Get Dependencies Error';
this.statusBarItem.show();
}
}

public async runBuild(
projectFolder: string,
cancellationKey: string,
Expand Down
4 changes: 2 additions & 2 deletions extension/src/test/unit/gradleTasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ describe(getSuiteName('Gradle tasks'), () => {
mockContext,
rootProjectsStore,
gradleTaskProvider,
new Icons(mockContext)
new Icons(mockContext),
client
);
logger.reset();
logger.setLoggingChannel(buildMockOutputChannel());
Expand Down Expand Up @@ -234,7 +235,6 @@ describe(getSuiteName('Gradle tasks'), () => {
groupItem.label,
mockTaskDefinition1ForFolder1.group
);
assert.strictEqual(groupItem.iconPath, vscode.ThemeIcon.Folder);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since we changed the themeicon in https://github.com/microsoft/vscode-gradle/pull/887/files#diff-183471d1a24e3c81ad33c4c977c62b13d94770466ca974bb60b5efcf3d6778d2 , IMO there is no way to check the icon so I simply remove it.

assert.strictEqual(
groupItem.parentTreeItem,
projectItem,
Expand Down
3 changes: 2 additions & 1 deletion extension/src/test/unit/pinnedTasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ describe(getSuiteName('Pinned tasks'), () => {
mockContext,
rootProjectsStore,
gradleTaskProvider,
icons
icons,
client
);
pinnedTasksStore = new PinnedTasksStore(mockContext);
pinnedTasksTreeDataProvider = new PinnedTasksTreeDataProvider(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as vscode from 'vscode';

export class DependencyConfigurationTreeItem extends vscode.TreeItem {
private children: vscode.TreeItem[] | undefined;
constructor(
name: string,
collapsibleState: vscode.TreeItemCollapsibleState,
public readonly parentTreeItem: vscode.TreeItem,
// TODO: https://github.com/microsoft/vscode-codicons/issues/77
iconPath: vscode.ThemeIcon = new vscode.ThemeIcon('file-submodule')
) {
super(name, collapsibleState);
this.iconPath = iconPath;
}

public setChildren(children: vscode.TreeItem[]): void {
this.children = children;
}

public getChildren(): vscode.TreeItem[] | undefined {
return this.children;
}
}
34 changes: 34 additions & 0 deletions extension/src/views/gradleTasks/DependencyTreeItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as vscode from 'vscode';

export class DependencyTreeItem extends vscode.TreeItem {
private children: vscode.TreeItem[] | undefined;
private omittedTreeItem: vscode.TreeItem | undefined;
constructor(
name: string,
collapsibleState: vscode.TreeItemCollapsibleState,
public readonly parentTreeItem: vscode.TreeItem,
iconPath: vscode.ThemeIcon = new vscode.ThemeIcon('library')
) {
super(name, collapsibleState);
this.iconPath = iconPath;
}

public setChildren(children: vscode.TreeItem[]): void {
this.children = children;
}

public getChildren(): vscode.TreeItem[] | undefined {
return this.children;
}

public setOmittedTreeItem(item: vscode.TreeItem): void {
this.omittedTreeItem = item;
}

public getOmittedTreeItem(): vscode.TreeItem | undefined {
return this.omittedTreeItem;
}
}
108 changes: 108 additions & 0 deletions extension/src/views/gradleTasks/DependencyUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as vscode from 'vscode';
import { DependencyItem, GradleDependencyType } from '../../proto/gradle_pb';
import { DependencyConfigurationTreeItem } from './DependencyConfigurationTreeItem';
import { DependencyTreeItem } from './DependencyTreeItem';
import { ProjectDependencyTreeItem } from './ProjectDependencyTreeItem';
export const GRADLE_OMITTED_REVEAL = 'gradle.omitted.reveal';

export function protocolItem2ProjectDependencyTreeItem(
protocolItem: DependencyItem,
parent: vscode.TreeItem
): ProjectDependencyTreeItem | undefined {
const name = 'Dependencies';
const projectItem: ProjectDependencyTreeItem = new ProjectDependencyTreeItem(
name,
vscode.TreeItemCollapsibleState.Collapsed,
parent
);
const children = protocolItem.getChildrenList();
const treeChildren = [];
for (const child of children) {
if (child.getType() !== GradleDependencyType.CONFIGURATION) {
continue;
}
const configurationItem = protocolItem2DependencyConfigurationTreeItem(
child,
projectItem
);
if (configurationItem) {
treeChildren.push(configurationItem);
}
}
if (!treeChildren.length) {
return undefined;
}
projectItem.setChildren(treeChildren);
return projectItem;
}

function protocolItem2DependencyConfigurationTreeItem(
protocolItem: DependencyItem,
parent: vscode.TreeItem
): DependencyConfigurationTreeItem | undefined {
const name = protocolItem.getName();
const storageMap = new Map();
const configurationItem: DependencyConfigurationTreeItem = new DependencyConfigurationTreeItem(
name,
vscode.TreeItemCollapsibleState.Collapsed,
parent
);
const children = protocolItem.getChildrenList();
const treeChildren = [];
for (const child of children) {
if (child.getType() !== GradleDependencyType.DEPENDENCY) {
continue;
}
treeChildren.push(
protocolItem2DependencyTreeItem(child, configurationItem, storageMap)
);
}
if (!treeChildren.length) {
return undefined;
}
configurationItem.setChildren(treeChildren);
return configurationItem;
}

function protocolItem2DependencyTreeItem(
protocolItem: DependencyItem,
parent: vscode.TreeItem,
storageMap: Map<string, vscode.TreeItem>
): DependencyTreeItem {
const name = protocolItem.getName();
const dependencyItem: DependencyTreeItem = new DependencyTreeItem(
name,
vscode.TreeItemCollapsibleState.Collapsed,
parent
);
if (storageMap.has(name)) {
const omittedTreeItem = storageMap.get(name);
if (omittedTreeItem) {
dependencyItem.setOmittedTreeItem(omittedTreeItem);
}
dependencyItem.contextValue = 'omitted';
dependencyItem.label = dependencyItem.label + ' (*)';
dependencyItem.collapsibleState = vscode.TreeItemCollapsibleState.None;
} else {
storageMap.set(name, dependencyItem);
const children = protocolItem.getChildrenList();
const treeChildren = [];
for (const child of children) {
if (child.getType() !== GradleDependencyType.DEPENDENCY) {
continue;
}
treeChildren.push(
protocolItem2DependencyTreeItem(child, dependencyItem, storageMap)
);
}
dependencyItem.collapsibleState =
treeChildren.length > 0
? vscode.TreeItemCollapsibleState.Collapsed
: vscode.TreeItemCollapsibleState.None;
dependencyItem.setChildren(treeChildren);
}
return dependencyItem;
}
Loading