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 controlling whether to show stopped daemons #940

Merged
merged 3 commits into from
Aug 24, 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
32 changes: 32 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@
"command": "gradle.dependency.reveal",
"title": "Go to Dependency",
"icon": "$(references)"
},
{
"command": "gradle.showStoppedDaemons",
"title": "Show Stopped Daemons"
},
{
"command": "gradle.hideStoppedDaemons",
"title": "Hide Stopped Daemons"
}
],
"menus": {
Expand Down Expand Up @@ -405,6 +413,14 @@
{
"command": "gradle.dependency.reveal",
"when": "false"
},
{
"command": "gradle.showStoppedDaemons",
"when": "false"
},
{
"command": "gradle.hideStoppedDaemons",
"when": "false"
}
],
"view/title": [
Expand Down Expand Up @@ -456,6 +472,16 @@
"when": "view == gradleDaemonsView",
"group": "navigation@2"
},
{
"command": "gradle.showStoppedDaemons",
"when": "view == gradleDaemonsView && config.gradle.showStoppedDaemons == false",
"group": "overflow_0@0"
},
{
"command": "gradle.hideStoppedDaemons",
"when": "view == gradleDaemonsView && config.gradle.showStoppedDaemons == true",
"group": "overflow_0@0"
},
{
"command": "gradle.clearAllRecentTasks",
"when": "view == recentTasksView",
Expand Down Expand Up @@ -673,6 +699,12 @@
"integration"
]
}
},
"gradle.showStoppedDaemons": {
"type": "boolean",
"default": false,
"scope": "application",
"description": "Show stopped daemons in the Gradle Daemons view"
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions extension/src/commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ import {
RecentTasksTreeDataProvider,
} from '../views';
import { Command } from './Command';
import {
HideStoppedDaemonsCommand,
HIDE_STOPPED_DAEMONS,
} from './HideStoppedDaemonsCommand';
import {
ShowStoppedDaemonsCommand,
SHOW_STOPPED_DAEMONS,
} from './ShowStoppedDaemonsCommand';

export class Commands {
constructor(
Expand Down Expand Up @@ -269,5 +277,13 @@ export class Commands {
COMMAND_FIND_TASK,
new FindTaskCommand(this.gradleTasksTreeView, this.gradleTaskProvider)
);
this.registerCommand(
SHOW_STOPPED_DAEMONS,
new ShowStoppedDaemonsCommand(this.gradleDaemonsTreeDataProvider)
);
this.registerCommand(
HIDE_STOPPED_DAEMONS,
new HideStoppedDaemonsCommand(this.gradleDaemonsTreeDataProvider)
);
}
}
18 changes: 18 additions & 0 deletions extension/src/commands/HideStoppedDaemonsCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { GradleDaemonsTreeDataProvider } from '../views';
import { Command } from './Command';
export const HIDE_STOPPED_DAEMONS = 'gradle.hideStoppedDaemons';

export class HideStoppedDaemonsCommand extends Command {
constructor(
private gradleDaemonsTreeDataProvider: GradleDaemonsTreeDataProvider
) {
super();
}

async run(): Promise<void> {
this.gradleDaemonsTreeDataProvider.hideStoppedDaemons();
}
}
18 changes: 18 additions & 0 deletions extension/src/commands/ShowStoppedDaemonsCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { GradleDaemonsTreeDataProvider } from '../views';
import { Command } from './Command';
export const SHOW_STOPPED_DAEMONS = 'gradle.showStoppedDaemons';

export class ShowStoppedDaemonsCommand extends Command {
constructor(
private gradleDaemonsTreeDataProvider: GradleDaemonsTreeDataProvider
) {
super();
}

async run(): Promise<void> {
this.gradleDaemonsTreeDataProvider.showStoppedDaemons();
}
}
21 changes: 19 additions & 2 deletions extension/src/test/unit/gradleDaemons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ describe(getSuiteName('Gradle daemons'), () => {
});

it('should build the daemon treeitems', async () => {
await vscode.workspace
.getConfiguration('gradle')
.update('showStoppedDaemons', true, true);

const mockDaemonInfoBusy = new DaemonInfo();
mockDaemonInfoBusy.setStatus(DaemonInfo.DaemonStatus.BUSY);
mockDaemonInfoBusy.setPid('41716');
Expand Down Expand Up @@ -139,12 +143,12 @@ describe(getSuiteName('Gradle daemons'), () => {
// NOTE: no reason to mock reply for mockWorkspaceFolder3 as it should be ignored due to
// dupicate gradle version

const children = await gradleDaemonsTreeDataProvider.getChildren();
let children = await gradleDaemonsTreeDataProvider.getChildren();

assert.strictEqual(
children.length,
4,
'There should be 6 items in the tree'
'There should be 4 items in the tree'
);

const treeItemBusy = children[0];
Expand Down Expand Up @@ -206,6 +210,19 @@ describe(getSuiteName('Gradle daemons'), () => {
idleIconPath.light,
path.join('resources', 'light', ICON_DAEMON_IDLE)
);

// test for hide stopped daemons
await vscode.workspace
.getConfiguration('gradle')
.update('showStoppedDaemons', false, true);

children = await gradleDaemonsTreeDataProvider.getChildren();

assert.strictEqual(
children.length,
2,
'There should be 2 items in the tree'
);
});

it('should stop a daemon', async () => {
Expand Down
12 changes: 12 additions & 0 deletions extension/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ export function getNestedProjectsConfig(
.get<boolean | ReadonlyArray<string>>('nestedProjects', false);
}

export function getShowStoppedDaemons(): boolean {
return vscode.workspace
.getConfiguration('gradle')
.get<boolean>('showStoppedDaemons', false);
}

export function setShowStoppedDaemons(value: boolean): void {
void vscode.workspace
.getConfiguration('gradle')
.update('showStoppedDaemons', value, true);
}

export type JavaDebug = {
tasks: ReadonlyArray<string>;
clean: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as vscode from 'vscode';
import { GradleDaemonTreeItem } from '.';
import { RootProjectsStore } from '../../stores';
import { GradleClient } from '../../client';
import { DaemonInfo } from '../../proto/gradle_pb';
import { RootProjectsStore } from '../../stores';
import {
getShowStoppedDaemons,
setShowStoppedDaemons,
} from '../../util/config';
import { Deferred } from '../../util/Deferred';

export class GradleDaemonsTreeDataProvider
Expand Down Expand Up @@ -39,25 +44,31 @@ export class GradleDaemonsTreeDataProvider
this.cancelDeferred.promise.then(() => cancellationToken.cancel());

const projectRootFolders = await this.getProjectRootFolders();
const promises: Promise<
GradleDaemonTreeItem[]
>[] = projectRootFolders.map((projectRootFolder) =>
this.client
.getDaemonsStatus(projectRootFolder, cancellationToken.token)
.then((getDaemonsStatusReply) =>
getDaemonsStatusReply
? getDaemonsStatusReply
.getDaemonInfoList()
.map(
(daemonInfo) =>
new GradleDaemonTreeItem(
this.context,
daemonInfo.getPid(),
daemonInfo
)
const promises: Promise<GradleDaemonTreeItem[]>[] = projectRootFolders.map(
(projectRootFolder) =>
this.client
.getDaemonsStatus(projectRootFolder, cancellationToken.token)
.then((daemonsStatusReply) => {
if (!daemonsStatusReply) {
return [];
}
let daemonInfoList = daemonsStatusReply.getDaemonInfoList();
if (!getShowStoppedDaemons()) {
daemonInfoList = daemonInfoList.filter((daemonInfo) => {
return (
daemonInfo.getStatus() !== DaemonInfo.DaemonStatus.STOPPED
);
});
}
return daemonInfoList.map(
(daemonInfo) =>
new GradleDaemonTreeItem(
this.context,
daemonInfo.getPid(),
daemonInfo
)
: []
)
);
})
);
this.treeItems = await Promise.race([
Promise.all(promises).then((items) => items.flat()),
Expand All @@ -72,4 +83,14 @@ export class GradleDaemonsTreeDataProvider
await this.rootProjectsStore.getProjectRootsWithUniqueVersions()
).map((rootProject) => rootProject.getProjectUri().fsPath);
}

public showStoppedDaemons(): void {
setShowStoppedDaemons(true);
this.refresh();
}

public hideStoppedDaemons(): void {
setShowStoppedDaemons(false);
this.refresh();
}
}