Skip to content

Commit

Permalink
Expose gradleTaskProvider in API
Browse files Browse the repository at this point in the history
  • Loading branch information
badsyntax committed Oct 17, 2020
1 parent 8d44e02 commit 1b80b83
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions extension/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class Extension {
this.api = new Api(
this.client,
this.gradleTasksTreeDataProvider,
this.gradleTaskProvider,
this.icons
);

Expand Down
6 changes: 6 additions & 0 deletions extension/src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GradleTasksTreeDataProvider } from '../views';
import { GradleClient } from '../client';
import { Icons } from '../icons';
import { getRunBuildCancellationKey } from '../client/CancellationKeys';
import { GradleTaskProvider } from '../tasks';

export interface RunTaskOpts {
projectFolder: string;
Expand Down Expand Up @@ -41,6 +42,7 @@ export class Api {
constructor(
private readonly client: GradleClient,
private readonly tasksTreeDataProvider: GradleTasksTreeDataProvider,
private readonly gradleTaskProvider: GradleTaskProvider,
private readonly icons: Icons
) {}

Expand Down Expand Up @@ -107,6 +109,10 @@ export class Api {
return this.tasksTreeDataProvider;
}

public getTaskProvider(): GradleTaskProvider {
return this.gradleTaskProvider;
}

public getIcons(): Icons {
return this.icons;
}
Expand Down
16 changes: 8 additions & 8 deletions extension/src/tasks/GradleTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class GradleTaskProvider
implements vscode.TaskProvider, vscode.Disposable {
private cachedTasks: vscode.Task[] = [];
private readonly _onDidLoadTasks: vscode.EventEmitter<
null
> = new vscode.EventEmitter<null>();
vscode.Task[]
> = new vscode.EventEmitter<vscode.Task[]>();
private readonly _onDidStartRefresh: vscode.EventEmitter<
null
> = new vscode.EventEmitter<null>();
Expand All @@ -28,15 +28,17 @@ export class GradleTaskProvider
private readonly client: GradleClient
) {}

public readonly onDidLoadTasks: vscode.Event<null> = this._onDidLoadTasks
.event;
public readonly onDidLoadTasks: vscode.Event<vscode.Task[]> = this
._onDidLoadTasks.event;
public readonly onDidStartRefresh: vscode.Event<null> = this
._onDidStartRefresh.event;
public readonly onDidStopRefresh: vscode.Event<null> = this._onDidStopRefresh
.event;
private loadTasksPromise?: Promise<vscode.Task[]>;

private readonly _waitForTasksLoad = new EventWaiter(this.onDidLoadTasks);
private readonly _waitForTasksLoad = new EventWaiter<vscode.Task[]>(
this.onDidLoadTasks
);
public readonly waitForTasksLoad = this._waitForTasksLoad.wait;

public provideTasks(): Promise<vscode.Task[] | undefined> {
Expand Down Expand Up @@ -75,8 +77,6 @@ export class GradleTaskProvider
}

public async loadTasks(): Promise<vscode.Task[]> {
// To accomodate calling loadTasks() on extension activate (when client is connected)
// and opening the treeview.
if (this.loadTasksPromise) {
return this.loadTasksPromise;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ export class GradleTaskProvider
.then(() => this.cachedTasks);

return this.loadTasksPromise.finally(() => {
this._onDidLoadTasks.fire(null);
this._onDidLoadTasks.fire(this.cachedTasks);
this._onDidStopRefresh.fire(null);
this.loadTasksPromise = undefined;
});
Expand Down
4 changes: 2 additions & 2 deletions extension/src/util/EventWaiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as vscode from 'vscode';

type callback = () => void;

export class EventWaiter {
export class EventWaiter<T = null> {
private eventRun = false;

constructor(private readonly event: vscode.Event<null>) {
constructor(private readonly event: vscode.Event<T>) {
this.waitForEvent();
}

Expand Down

0 comments on commit 1b80b83

Please sign in to comment.