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

use _ for private task vars #151637

Merged
merged 3 commits into from
Jun 9, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
994 changes: 497 additions & 497 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,40 @@ const ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE = 'tasks.run.allowAutomatic';

export class RunAutomaticTasks extends Disposable implements IWorkbenchContribution {
constructor(
@ITaskService private readonly taskService: ITaskService,
@IStorageService private readonly storageService: IStorageService,
@IWorkspaceTrustManagementService private readonly workspaceTrustManagementService: IWorkspaceTrustManagementService,
@ILogService private readonly logService: ILogService) {
@ITaskService private readonly _taskService: ITaskService,
@IStorageService private readonly _storageService: IStorageService,
@IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService: IWorkspaceTrustManagementService,
@ILogService private readonly _logService: ILogService) {
super();
this.tryRunTasks();
this._tryRunTasks();
}

private async tryRunTasks() {
this.logService.trace('RunAutomaticTasks: Trying to run tasks.');
private async _tryRunTasks() {
this._logService.trace('RunAutomaticTasks: Trying to run tasks.');
// Wait until we have task system info (the extension host and workspace folders are available).
if (!this.taskService.hasTaskSystemInfo) {
this.logService.trace('RunAutomaticTasks: Awaiting task system info.');
await Event.toPromise(Event.once(this.taskService.onDidChangeTaskSystemInfo));
if (!this._taskService.hasTaskSystemInfo) {
this._logService.trace('RunAutomaticTasks: Awaiting task system info.');
await Event.toPromise(Event.once(this._taskService.onDidChangeTaskSystemInfo));
}

this.logService.trace('RunAutomaticTasks: Checking if automatic tasks should run.');
const isFolderAutomaticAllowed = this.storageService.getBoolean(ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE, StorageScope.WORKSPACE, undefined);
await this.workspaceTrustManagementService.workspaceTrustInitialized;
const isWorkspaceTrusted = this.workspaceTrustManagementService.isWorkspaceTrusted();
this._logService.trace('RunAutomaticTasks: Checking if automatic tasks should run.');
const isFolderAutomaticAllowed = this._storageService.getBoolean(ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE, StorageScope.WORKSPACE, undefined);
await this._workspaceTrustManagementService.workspaceTrustInitialized;
const isWorkspaceTrusted = this._workspaceTrustManagementService.isWorkspaceTrusted();
// Only run if allowed. Prompting for permission occurs when a user first tries to run a task.
if (isFolderAutomaticAllowed && isWorkspaceTrusted) {
this.taskService.getWorkspaceTasks(TaskRunSource.FolderOpen).then(workspaceTaskResult => {
let { tasks } = RunAutomaticTasks.findAutoTasks(this.taskService, workspaceTaskResult);
this.logService.trace(`RunAutomaticTasks: Found ${tasks.length} automatic tasks tasks`);
this._taskService.getWorkspaceTasks(TaskRunSource.FolderOpen).then(workspaceTaskResult => {
let { tasks } = RunAutomaticTasks._findAutoTasks(this._taskService, workspaceTaskResult);
this._logService.trace(`RunAutomaticTasks: Found ${tasks.length} automatic tasks tasks`);

if (tasks.length > 0) {
RunAutomaticTasks.runTasks(this.taskService, tasks);
RunAutomaticTasks._runTasks(this._taskService, tasks);
}
});
}
}

private static runTasks(taskService: ITaskService, tasks: Array<Task | Promise<Task | undefined>>) {
private static _runTasks(taskService: ITaskService, tasks: Array<Task | Promise<Task | undefined>>) {
tasks.forEach(task => {
if (task instanceof Promise) {
task.then(promiseResult => {
Expand All @@ -73,7 +73,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
});
}

private static getTaskSource(source: TaskSource): URI | undefined {
private static _getTaskSource(source: TaskSource): URI | undefined {
const taskKind = TaskSourceKind.toConfigurationTarget(source.kind);
switch (taskKind) {
case ConfigurationTarget.WORKSPACE_FOLDER: {
Expand All @@ -86,7 +86,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
return undefined;
}

private static findAutoTasks(taskService: ITaskService, workspaceTaskResult: Map<string, IWorkspaceFolderTaskResult>): { tasks: Array<Task | Promise<Task | undefined>>; taskNames: Array<string>; locations: Map<string, URI> } {
private static _findAutoTasks(taskService: ITaskService, workspaceTaskResult: Map<string, IWorkspaceFolderTaskResult>): { tasks: Array<Task | Promise<Task | undefined>>; taskNames: Array<string>; locations: Map<string, URI> } {
const tasks = new Array<Task | Promise<Task | undefined>>();
const taskNames = new Array<string>();
const locations = new Map<string, URI>();
Expand All @@ -98,7 +98,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
if (task.runOptions.runOn === RunOnOptions.folderOpen) {
tasks.push(task);
taskNames.push(task._label);
const location = RunAutomaticTasks.getTaskSource(task._source);
const location = RunAutomaticTasks._getTaskSource(task._source);
if (location) {
locations.set(location.fsPath, location);
}
Expand All @@ -116,7 +116,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
} else {
taskNames.push(configedTask.value.configures.task);
}
const location = RunAutomaticTasks.getTaskSource(configedTask.value._source);
const location = RunAutomaticTasks._getTaskSource(configedTask.value._source);
if (location) {
locations.set(location.fsPath, location);
}
Expand All @@ -140,18 +140,18 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
return;
}

let { tasks, taskNames, locations } = RunAutomaticTasks.findAutoTasks(taskService, workspaceTaskResult);
let { tasks, taskNames, locations } = RunAutomaticTasks._findAutoTasks(taskService, workspaceTaskResult);
if (taskNames.length > 0) {
// We have automatic tasks, prompt to allow.
this.showPrompt(notificationService, storageService, taskService, openerService, taskNames, locations).then(allow => {
this._showPrompt(notificationService, storageService, taskService, openerService, taskNames, locations).then(allow => {
if (allow) {
RunAutomaticTasks.runTasks(taskService, tasks);
RunAutomaticTasks._runTasks(taskService, tasks);
}
});
}
}

private static showPrompt(notificationService: INotificationService, storageService: IStorageService, taskService: ITaskService,
private static _showPrompt(notificationService: INotificationService, storageService: IStorageService, taskService: ITaskService,
openerService: IOpenerService, taskNames: Array<string>, locations: Map<string, URI>): Promise<boolean> {
return new Promise<boolean>(resolve => {
notificationService.prompt(Severity.Info, nls.localize('tasks.run.allowAutomatic',
Expand Down
58 changes: 29 additions & 29 deletions src/vs/workbench/contrib/tasks/browser/task.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
});

export class TaskStatusBarContributions extends Disposable implements IWorkbenchContribution {
private runningTasksStatusItem: IStatusbarEntryAccessor | undefined;
private activeTasksCount: number = 0;
private _runningTasksStatusItem: IStatusbarEntryAccessor | undefined;
private _activeTasksCount: number = 0;

constructor(
@ITaskService private readonly taskService: ITaskService,
@IStatusbarService private readonly statusbarService: IStatusbarService,
@IProgressService private readonly progressService: IProgressService
@ITaskService private readonly _taskService: ITaskService,
@IStatusbarService private readonly _statusbarService: IStatusbarService,
@IProgressService private readonly _progressService: IProgressService
) {
super();
this.registerListeners();
this._registerListeners();
}

private registerListeners(): void {
private _registerListeners(): void {
let promise: Promise<void> | undefined = undefined;
let resolver: (value?: void | Thenable<void>) => void;
this.taskService.onDidStateChange(event => {
this._taskService.onDidStateChange(event => {
if (event.kind === TaskEventKind.Changed) {
this.updateRunningTasksStatus();
this._updateRunningTasksStatus();
}

if (!this.ignoreEventForUpdateRunningTasksCount(event)) {
if (!this._ignoreEventForUpdateRunningTasksCount(event)) {
switch (event.kind) {
case TaskEventKind.Active:
this.activeTasksCount++;
if (this.activeTasksCount === 1) {
this._activeTasksCount++;
if (this._activeTasksCount === 1) {
if (!promise) {
promise = new Promise<void>((resolve) => {
resolver = resolve;
Expand All @@ -91,18 +91,18 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench
case TaskEventKind.Inactive:
// Since the exiting of the sub process is communicated async we can't order inactive and terminate events.
// So try to treat them accordingly.
if (this.activeTasksCount > 0) {
this.activeTasksCount--;
if (this.activeTasksCount === 0) {
if (this._activeTasksCount > 0) {
this._activeTasksCount--;
if (this._activeTasksCount === 0) {
if (promise && resolver!) {
resolver!();
}
}
}
break;
case TaskEventKind.Terminated:
if (this.activeTasksCount !== 0) {
this.activeTasksCount = 0;
if (this._activeTasksCount !== 0) {
this._activeTasksCount = 0;
if (promise && resolver!) {
resolver!();
}
Expand All @@ -111,8 +111,8 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench
}
}

if (promise && (event.kind === TaskEventKind.Active) && (this.activeTasksCount === 1)) {
this.progressService.withProgress({ location: ProgressLocation.Window, command: 'workbench.action.tasks.showTasks' }, progress => {
if (promise && (event.kind === TaskEventKind.Active) && (this._activeTasksCount === 1)) {
this._progressService.withProgress({ location: ProgressLocation.Window, command: 'workbench.action.tasks.showTasks' }, progress => {
progress.report({ message: nls.localize('building', 'Building...') });
return promise!;
}).then(() => {
Expand All @@ -122,12 +122,12 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench
});
}

private async updateRunningTasksStatus(): Promise<void> {
const tasks = await this.taskService.getActiveTasks();
private async _updateRunningTasksStatus(): Promise<void> {
const tasks = await this._taskService.getActiveTasks();
if (tasks.length === 0) {
if (this.runningTasksStatusItem) {
this.runningTasksStatusItem.dispose();
this.runningTasksStatusItem = undefined;
if (this._runningTasksStatusItem) {
this._runningTasksStatusItem.dispose();
this._runningTasksStatusItem = undefined;
}
} else {
const itemProps: IStatusbarEntry = {
Expand All @@ -138,16 +138,16 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench
command: 'workbench.action.tasks.showTasks',
};

if (!this.runningTasksStatusItem) {
this.runningTasksStatusItem = this.statusbarService.addEntry(itemProps, 'status.runningTasks', StatusbarAlignment.LEFT, 49 /* Medium Priority, next to Markers */);
if (!this._runningTasksStatusItem) {
this._runningTasksStatusItem = this._statusbarService.addEntry(itemProps, 'status.runningTasks', StatusbarAlignment.LEFT, 49 /* Medium Priority, next to Markers */);
} else {
this.runningTasksStatusItem.update(itemProps);
this._runningTasksStatusItem.update(itemProps);
}
}
}

private ignoreEventForUpdateRunningTasksCount(event: ITaskEvent): boolean {
if (!this.taskService.inTerminal()) {
private _ignoreEventForUpdateRunningTasksCount(event: ITaskEvent): boolean {
if (!this._taskService.inTerminal()) {
return false;
}

Expand Down