Skip to content

Commit

Permalink
refactor - Rename to taskServerClient & remove gradle daemon status (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaaming authored Jul 29, 2024
1 parent e4d2842 commit 34e0896
Show file tree
Hide file tree
Showing 30 changed files with 58 additions and 501 deletions.
6 changes: 3 additions & 3 deletions extension/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { commands, window } from "vscode";
import { logger, LogVerbosity, Logger } from "./logger";
import { Api } from "./api";
import { GradleClient } from "./client";
import { TaskServerClient } from "./client";
import { GradleServer } from "./server";
import { Icons } from "./icons";
import { GradleDaemonsTreeDataProvider, RecentTasksTreeDataProvider, GradleTasksTreeDataProvider } from "./views";
Expand Down Expand Up @@ -42,7 +42,7 @@ import { BspProxy } from "./bs/BspProxy";

export class Extension {
private readonly bspProxy: BspProxy;
private readonly taskServerClient: GradleClient;
private readonly taskServerClient: TaskServerClient;
private readonly server: GradleServer;
private readonly pinnedTasksStore: PinnedTasksStore;
private readonly recentTasksStore: RecentTasksStore;
Expand Down Expand Up @@ -91,7 +91,7 @@ export class Extension {
const statusBarItem = vscode.window.createStatusBarItem();
this.bspProxy = new BspProxy(this.context, bspLogger);
this.server = new GradleServer({ host: "localhost" }, context, serverLogger, this.bspProxy);
this.taskServerClient = new GradleClient(this.server, statusBarItem, clientLogger);
this.taskServerClient = new TaskServerClient(this.server, statusBarItem, clientLogger);
this.pinnedTasksStore = new PinnedTasksStore(context);
this.recentTasksStore = new RecentTasksStore();
this.taskTerminalsStore = new TaskTerminalsStore();
Expand Down
4 changes: 2 additions & 2 deletions extension/src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { Output } from "../proto/gradle_pb";
import { Logger, logger } from "../logger";
import { GradleTasksTreeDataProvider } from "../views";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
import { Icons } from "../icons";
import { getRunBuildCancellationKey } from "../client/CancellationKeys";
import { GradleTaskProvider } from "../tasks";
Expand Down Expand Up @@ -40,7 +40,7 @@ export interface CancelBuildOpts {

export class Api {
constructor(
private readonly client: GradleClient,
private readonly client: TaskServerClient,
private readonly tasksTreeDataProvider: GradleTasksTreeDataProvider,
private readonly gradleTaskProvider: GradleTaskProvider,
private readonly icons: Icons
Expand Down
4 changes: 2 additions & 2 deletions extension/src/client/GradleBuildContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import AwaitLock from "await-lock";
import { GradleClient } from ".";
import { TaskServerClient } from ".";
import { syncGradleBuild } from "../languageServer/languageServer";
import { GradleBuild } from "../proto/gradle_pb";
import { RootProject } from "../rootProject";
Expand All @@ -13,7 +13,7 @@ const lock = new AwaitLock();
export class GradleBuildContentProvider {
private cachedBuild: Map<string, GradleBuild> = new Map();

constructor(private readonly client: GradleClient) {}
constructor(private readonly client: TaskServerClient) {}

public async getGradleBuild(rootProject: RootProject): Promise<GradleBuild | undefined> {
await lock.acquireAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import {
GradleBuild,
Environment,
GradleConfig,
GetDaemonsStatusReply,
GetDaemonsStatusRequest,
StopDaemonsReply,
StopDaemonsRequest,
StopDaemonRequest,
StopDaemonReply,
RunBuildRequest,
RunBuildReply,
CancelBuildRequest,
Expand Down Expand Up @@ -48,7 +42,7 @@ function logBuildEnvironment(environment: Environment): void {
logger.info("Gradle Version:", gradleEnv.getGradleVersion());
}

export class GradleClient implements vscode.Disposable {
export class TaskServerClient implements vscode.Disposable {
private readonly connectDeadline = 30; // seconds
private grpcClient: GrpcClient | null = null;
private readonly _onDidConnect: vscode.EventEmitter<null> = new vscode.EventEmitter<null>();
Expand Down Expand Up @@ -360,86 +354,6 @@ export class GradleClient implements vscode.Disposable {
}
}

public async getDaemonsStatus(
projectFolder: string,
cancelToken: vscode.CancellationToken
): Promise<GetDaemonsStatusReply | void> {
await this.waitForConnect();
logger.debug("Get daemon status");
const request = new GetDaemonsStatusRequest();
request.setProjectDir(projectFolder);
try {
return await new Promise((resolve, reject) => {
const stream = this.grpcClient!.getDaemonsStatus(
request,
(err: grpc.ServiceError | null, getDaemonsStatusReply: GetDaemonsStatusReply | undefined) => {
if (err) {
reject(err);
} else {
resolve(getDaemonsStatusReply);
}
}
);
cancelToken.onCancellationRequested(() => stream.cancel());
});
} catch (err) {
const errMessage = err.details || err.message;
if (cancelToken.isCancellationRequested) {
logger.debug("Get daemon status:", errMessage);
} else {
logger.error("Unable to get daemon status:", errMessage);
}
}
}

public async stopDaemons(projectFolder: string): Promise<StopDaemonsReply | void> {
await this.waitForConnect();
const request = new StopDaemonsRequest();
request.setProjectDir(projectFolder);
try {
return await new Promise((resolve, reject) => {
this.grpcClient!.stopDaemons(
request,
(err: grpc.ServiceError | null, stopDaemonsReply: StopDaemonsReply | undefined) => {
if (err) {
reject(err);
} else {
resolve(stopDaemonsReply);
}
}
);
});
} catch (err) {
logger.error("Error stopping daemons:", err.details || err.message);
} finally {
await vscode.commands.executeCommand(COMMAND_REFRESH_DAEMON_STATUS);
}
}

public async stopDaemon(pid: string): Promise<StopDaemonReply | void> {
await this.waitForConnect();
const request = new StopDaemonRequest();
request.setPid(pid);
try {
return await new Promise((resolve, reject) => {
this.grpcClient!.stopDaemon(
request,
(err: grpc.ServiceError | null, stopDaemonReply: StopDaemonReply | undefined) => {
if (err) {
reject(err);
} else {
resolve(stopDaemonReply);
}
}
);
});
} catch (err) {
logger.error("Error stopping daemon:", err.details || err.message);
} finally {
await vscode.commands.executeCommand(COMMAND_REFRESH_DAEMON_STATUS);
}
}

public async getNormalizedPackageName(name: string): Promise<string | undefined> {
await this.waitForConnect();
const request = new ExecuteCommandRequest();
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./GradleClient";
export * from "./TaskServerClient";
4 changes: 2 additions & 2 deletions extension/src/commands/CancelBuildCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as vscode from "vscode";
import { cancelBuild } from "../tasks/taskUtil";
import { logger } from "../logger";
import { Command } from "./Command";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
export const COMMAND_CANCEL_BUILD = "gradle.cancelBuild";

export class CancelBuildCommand extends Command {
constructor(private client: GradleClient) {
constructor(private client: TaskServerClient) {
super();
}
async run(cancellationKey: string, task?: vscode.Task): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
COMMAND_RUN_TASK_DOUBLE_CLICK,
RunTaskDoubleClickCommand,
} from ".";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
import { GradleBuildContentProvider } from "../client/GradleBuildContentProvider";
import { PinnedTasksStore, RecentTasksStore, RootProjectsStore, TaskTerminalsStore } from "../stores";
import { GradleTaskProvider } from "../tasks";
Expand All @@ -88,7 +88,7 @@ export class Commands {
private gradleTasksTreeDataProvider: GradleTasksTreeDataProvider,
private recentTasksTreeDataProvider: RecentTasksTreeDataProvider,
private gradleDaemonsTreeDataProvider: GradleDaemonsTreeDataProvider,
private client: GradleClient,
private client: TaskServerClient,
private rootProjectsStore: RootProjectsStore,
private taskTerminalsStore: TaskTerminalsStore,
private recentTasksStore: RecentTasksStore,
Expand Down
4 changes: 2 additions & 2 deletions extension/src/commands/CreateProjectCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as path from "path";
import * as vscode from "vscode";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
import { getRunTaskCommandCancellationKey } from "../client/CancellationKeys";
import { selectProjectTypeStep } from "../createProject/SelectProjectTypeStep";
import { selectScriptDSLStep } from "../createProject/SelectScriptDSLStep";
Expand All @@ -15,7 +15,7 @@ export const COMMAND_CREATE_PROJECT = "gradle.createProject";
export const COMMAND_CREATE_PROJECT_ADVANCED = "gradle.createProjectAdvanced";

export class CreateProjectCommand extends Command {
constructor(private client: GradleClient) {
constructor(private client: TaskServerClient) {
super();
}

Expand Down
4 changes: 2 additions & 2 deletions extension/src/commands/DebugTaskCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { GradleTaskTreeItem } from "../views";
import { runTask } from "../tasks/taskUtil";
import { Command } from "./Command";
import { RootProjectsStore } from "../stores";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
export const COMMAND_DEBUG_TASK = "gradle.debugTask";

export class DebugTaskCommand extends Command {
constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) {
constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) {
super();
}
async run(treeItem: GradleTaskTreeItem, args = ""): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/commands/DebugTaskWithArgsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { runTaskWithArgs } from "../tasks/taskUtil";
import { logger } from "../logger";
import { Command } from "./Command";
import { RootProjectsStore } from "../stores";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
export const COMMAND_DEBUG_TASK_WITH_ARGS = "gradle.debugTaskWithArgs";

export class DebugTaskWithArgsCommand extends Command {
constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) {
constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) {
super();
}
async run(treeItem: GradleTaskTreeItem): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/commands/RestartTaskCommand.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GradleTaskTreeItem } from "../views";
import { getTaskExecution, queueRestartTask } from "../tasks/taskUtil";
import { Command } from "./Command";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
export const COMMAND_RESTART_TASK = "gradle.restartTask";

export class RestartTaskCommand extends Command {
constructor(private client: GradleClient) {
constructor(private client: TaskServerClient) {
super();
}
async run(treeItem: GradleTaskTreeItem): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/commands/RunBuildCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { GradleRunnerTerminal } from "../terminal";
import { getRunBuildCancellationKey } from "../client/CancellationKeys";
import { Command } from "./Command";
import { RootProjectsStore } from "../stores";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
export const COMMAND_RUN_BUILD = "gradle.runBuild";

export class RunBuildCommand extends Command {
constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) {
constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) {
super();
}
async run(): Promise<void> {
Expand Down
8 changes: 4 additions & 4 deletions extension/src/commands/RunTaskCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { GradleTaskTreeItem } from "../views";
import { runTask } from "../tasks/taskUtil";
import { Command } from "./Command";
import { RootProjectsStore } from "../stores";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
import { DoubleClickChecker } from "../util/DoubleClickChecker";

export const COMMAND_RUN_TASK = "gradle.runTask";
export const COMMAND_RUN_TASK_DOUBLE_CLICK = "gradle.runTaskDoubleClick";

async function run(treeItem: GradleTaskTreeItem, rootProjectsStore: RootProjectsStore, client: GradleClient) {
async function run(treeItem: GradleTaskTreeItem, rootProjectsStore: RootProjectsStore, client: TaskServerClient) {
if (treeItem && treeItem.task) {
await runTask(rootProjectsStore, treeItem.task, client);
}
}

export class RunTaskCommand extends Command {
constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) {
constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) {
super();
}

Expand All @@ -27,7 +27,7 @@ export class RunTaskCommand extends Command {
export class RunTaskDoubleClickCommand extends Command {
private doubleClickChecker: DoubleClickChecker;

constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) {
constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) {
super();
this.doubleClickChecker = new DoubleClickChecker();
}
Expand Down
4 changes: 2 additions & 2 deletions extension/src/commands/RunTaskWithArgsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { runTaskWithArgs } from "../tasks/taskUtil";
import { logger } from "../logger";
import { Command } from "./Command";
import { RootProjectsStore } from "../stores";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
export const COMMAND_RUN_TASK_WITH_ARGS = "gradle.runTaskWithArgs";

export class RunTaskWithArgsCommand extends Command {
constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) {
constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) {
super();
}
async run(treeItem: GradleTaskTreeItem): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/createProject/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { GradleClient } from "../client";
import { TaskServerClient } from "../client";

export interface IProjectCreationMetadata {
isAdvanced: boolean;
Expand All @@ -14,7 +14,7 @@ export interface IProjectCreationMetadata {
targetFolder: string;
steps: IProjectCreationStep[];
nextStep?: IProjectCreationStep;
client: GradleClient;
client: TaskServerClient;
}

export interface IProjectCreationStep {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/tasks/GradleTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger } from "../logger";
import { loadTasksForProjectRoots, resolveTaskFromDefinition } from "./taskUtil";
import { TaskId } from "../stores/types";
import { RootProjectsStore } from "../stores";
import { GradleClient } from "../client";
import { TaskServerClient } from "../client";
import { EventWaiter } from "../util/EventWaiter";
import { GradleBuildContentProvider } from "../client/GradleBuildContentProvider";

Expand All @@ -16,7 +16,7 @@ export class GradleTaskProvider implements vscode.TaskProvider, vscode.Disposabl

constructor(
private readonly rootProjectsStore: RootProjectsStore,
private readonly client: GradleClient,
private readonly client: TaskServerClient,
private readonly gradleBuildContentProvider: GradleBuildContentProvider
) {}

Expand Down
Loading

0 comments on commit 34e0896

Please sign in to comment.