Skip to content

Commit e9cf1bb

Browse files
committed
Fixes microsoft#29564: Customize tasks action in quick open should be shown for all tasks
1 parent 549ed8f commit e9cf1bb

10 files changed

Lines changed: 167 additions & 82 deletions

File tree

src/vs/workbench/api/node/extHostTask.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ namespace Tasks {
329329
let source = {
330330
kind: TaskSystem.TaskSourceKind.Extension,
331331
label: typeof task.source === 'string' ? task.source : extension.name,
332-
detail: extension.id
332+
extension: extension.id
333333
};
334334
let label = nls.localize('task.label', '{0}: {1}', source.label, task.name);
335335
let key = (task as types.Task).definitionKey;

src/vs/workbench/parts/tasks/browser/quickOpen.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import QuickOpen = require('vs/base/parts/quickopen/common/quickOpen');
1515
import Model = require('vs/base/parts/quickopen/browser/quickOpenModel');
1616
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
1717

18-
import { Task, TaskSourceKind } from 'vs/workbench/parts/tasks/common/tasks';
18+
import { Task, CustomTask, ContributedTask } from 'vs/workbench/parts/tasks/common/tasks';
1919
import { ITaskService, RunOptions } from 'vs/workbench/parts/tasks/common/taskService';
2020
import { ActionBarContributor, ContributableActionProvider } from 'vs/workbench/browser/actions';
2121

2222
export class TaskEntry extends Model.QuickOpenEntry {
2323

24-
constructor(protected taskService: ITaskService, protected quickOpenService: IQuickOpenService, protected _task: Task, highlights: Model.IHighlight[] = []) {
24+
constructor(protected taskService: ITaskService, protected quickOpenService: IQuickOpenService, protected _task: CustomTask | ContributedTask, highlights: Model.IHighlight[] = []) {
2525
super(highlights);
2626
}
2727

@@ -33,11 +33,11 @@ export class TaskEntry extends Model.QuickOpenEntry {
3333
return nls.localize('entryAriaLabel', "{0}, tasks", this.getLabel());
3434
}
3535

36-
public get task(): Task {
36+
public get task(): CustomTask | ContributedTask {
3737
return this._task;
3838
}
3939

40-
protected doRun(task: Task, options?: RunOptions): boolean {
40+
protected doRun(task: CustomTask | ContributedTask, options?: RunOptions): boolean {
4141
this.taskService.run(task, options);
4242
if (task.command.presentation.focus) {
4343
this.quickOpenService.close();
@@ -55,7 +55,7 @@ export class TaskGroupEntry extends Model.QuickOpenEntryGroup {
5555

5656
export abstract class QuickOpenHandler extends Quickopen.QuickOpenHandler {
5757

58-
private tasks: TPromise<Task[]>;
58+
private tasks: TPromise<(CustomTask | ContributedTask)[]>;
5959

6060

6161
constructor(
@@ -83,10 +83,10 @@ export abstract class QuickOpenHandler extends Quickopen.QuickOpenHandler {
8383
return new Model.QuickOpenModel(entries);
8484
}
8585
let recentlyUsedTasks = this.taskService.getRecentlyUsedTasks();
86-
let recent: Task[] = [];
87-
let configured: Task[] = [];
88-
let detected: Task[] = [];
89-
let taskMap: IStringDictionary<Task> = Object.create(null);
86+
let recent: (CustomTask | ContributedTask)[] = [];
87+
let configured: CustomTask[] = [];
88+
let detected: ContributedTask[] = [];
89+
let taskMap: IStringDictionary<CustomTask | ContributedTask> = Object.create(null);
9090
tasks.forEach(task => taskMap[Task.getKey(task)] = task);
9191
recentlyUsedTasks.keys().forEach(key => {
9292
let task = taskMap[key];
@@ -96,7 +96,7 @@ export abstract class QuickOpenHandler extends Quickopen.QuickOpenHandler {
9696
});
9797
for (let task of tasks) {
9898
if (!recentlyUsedTasks.has(Task.getKey(task))) {
99-
if (task._source.kind === TaskSourceKind.Workspace) {
99+
if (CustomTask.is(task)) {
100100
configured.push(task);
101101
} else {
102102
detected.push(task);
@@ -114,7 +114,7 @@ export abstract class QuickOpenHandler extends Quickopen.QuickOpenHandler {
114114
});
115115
}
116116

117-
private fillEntries(entries: Model.QuickOpenEntry[], input: string, tasks: Task[], groupLabel: string, withBorder: boolean = false) {
117+
private fillEntries(entries: Model.QuickOpenEntry[], input: string, tasks: (CustomTask | ContributedTask)[], groupLabel: string, withBorder: boolean = false) {
118118
let first = true;
119119
for (let task of tasks) {
120120
let highlights = Filters.matchesFuzzy(input, task._label);
@@ -130,9 +130,9 @@ export abstract class QuickOpenHandler extends Quickopen.QuickOpenHandler {
130130
}
131131
}
132132

133-
protected abstract getTasks(): TPromise<Task[]>;
133+
protected abstract getTasks(): TPromise<(CustomTask | ContributedTask)[]>;
134134

135-
protected abstract createEntry(task: Task, highlights: Model.IHighlight[]): TaskEntry;
135+
protected abstract createEntry(task: CustomTask | ContributedTask, highlights: Model.IHighlight[]): TaskEntry;
136136

137137
public getAutoFocus(input: string): QuickOpen.IAutoFocus {
138138
return {
@@ -146,7 +146,7 @@ class CustomizeTaskAction extends Action {
146146
private static ID = 'workbench.action.tasks.customizeTask';
147147
private static LABEL = nls.localize('customizeTask', "Configure Task");
148148

149-
constructor(private taskService: ITaskService, private quickOpenService: IQuickOpenService, private task: Task) {
149+
constructor(private taskService: ITaskService, private quickOpenService: IQuickOpenService, private task: CustomTask | ContributedTask) {
150150
super(CustomizeTaskAction.ID, CustomizeTaskAction.LABEL);
151151
this.updateClass();
152152
}
@@ -156,9 +156,15 @@ class CustomizeTaskAction extends Action {
156156
}
157157

158158
public run(context: any): TPromise<any> {
159-
return this.taskService.customize(this.task, undefined, true).then(() => {
160-
this.quickOpenService.close();
161-
});
159+
if (ContributedTask.is(this.task)) {
160+
return this.taskService.customize(this.task, undefined, true).then(() => {
161+
this.quickOpenService.close();
162+
});
163+
} else {
164+
return this.taskService.openConfig(this.task).then(() => {
165+
this.quickOpenService.close();
166+
});
167+
}
162168
}
163169
}
164170

@@ -177,13 +183,13 @@ export class QuickOpenActionContributor extends ActionBarContributor {
177183
public getActions(context: any): IAction[] {
178184
let actions: Action[] = [];
179185
let task = this.getTask(context);
180-
if (task && task._source.kind === TaskSourceKind.Extension) {
186+
if (task && ContributedTask.is(task) || CustomTask.is(task)) {
181187
actions.push(new CustomizeTaskAction(this.taskService, this.quickOpenService, task));
182188
}
183189
return actions;
184190
}
185191

186-
private getTask(context: any): Task {
192+
private getTask(context: any): CustomTask | ContributedTask {
187193
if (!context) {
188194
return undefined;
189195
}

src/vs/workbench/parts/tasks/browser/taskQuickOpen.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import QuickOpen = require('vs/base/parts/quickopen/common/quickOpen');
1010
import Model = require('vs/base/parts/quickopen/browser/quickOpenModel');
1111
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
1212

13-
import { Task } from 'vs/workbench/parts/tasks/common/tasks';
13+
import { CustomTask, ContributedTask } from 'vs/workbench/parts/tasks/common/tasks';
1414
import { ITaskService } from 'vs/workbench/parts/tasks/common/taskService';
1515
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
1616

1717

1818
import * as base from './quickOpen';
1919

2020
class TaskEntry extends base.TaskEntry {
21-
constructor(taskService: ITaskService, quickOpenService: IQuickOpenService, task: Task, highlights: Model.IHighlight[] = []) {
21+
constructor(taskService: ITaskService, quickOpenService: IQuickOpenService, task: CustomTask | ContributedTask, highlights: Model.IHighlight[] = []) {
2222
super(taskService, quickOpenService, task, highlights);
2323
}
2424

@@ -47,13 +47,13 @@ export class QuickOpenHandler extends base.QuickOpenHandler {
4747
return nls.localize('tasksAriaLabel', "Type the name of a task to run");
4848
}
4949

50-
protected getTasks(): TPromise<Task[]> {
50+
protected getTasks(): TPromise<(CustomTask | ContributedTask)[]> {
5151
return this.activationPromise.then(() => {
52-
return this.taskService.tasks();
52+
return this.taskService.tasks().then(tasks => tasks.filter<CustomTask | ContributedTask>((task): task is CustomTask | ContributedTask => ContributedTask.is(task) || CustomTask.is(task)));
5353
});
5454
}
5555

56-
protected createEntry(task: Task, highlights: Model.IHighlight[]): base.TaskEntry {
56+
protected createEntry(task: CustomTask | ContributedTask, highlights: Model.IHighlight[]): base.TaskEntry {
5757
return new TaskEntry(this.taskService, this.quickOpenService, task, highlights);
5858
}
5959

src/vs/workbench/parts/tasks/common/taskService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Action } from 'vs/base/common/actions';
99
import { IEventEmitter } from 'vs/base/common/eventEmitter';
1010
import { LinkedMap } from 'vs/base/common/map';
1111
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
12-
import { Task, TaskSet } from 'vs/workbench/parts/tasks/common/tasks';
12+
import { Task, ContributedTask, CustomTask, TaskSet } from 'vs/workbench/parts/tasks/common/tasks';
1313
import { ITaskSummary, TaskEvent, TaskType, TaskTerminateResponse } from 'vs/workbench/parts/tasks/common/taskSystem';
1414

1515
export { ITaskSummary, Task, TaskEvent, TaskType, TaskTerminateResponse };
@@ -60,7 +60,8 @@ export interface ITaskService extends IEventEmitter {
6060
getRecentlyUsedTasks(): LinkedMap<string, string>;
6161

6262
canCustomize(): boolean;
63-
customize(task: Task, properties?: {}, openConfig?: boolean): TPromise<void>;
63+
customize(task: ContributedTask | CustomTask, properties?: {}, openConfig?: boolean): TPromise<void>;
64+
openConfig(task: CustomTask): TPromise<void>;
6465

6566
registerTaskProvider(handle: number, taskProvider: ITaskProvider): void;
6667
unregisterTaskProvider(handle: number): boolean;

src/vs/workbench/parts/tasks/common/tasks.ts

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,38 @@ export namespace TaskGroup {
214214

215215
export type TaskGroup = 'clean' | 'build' | 'rebuild' | 'test';
216216

217-
export enum TaskSourceKind {
218-
Workspace = 1,
219-
Extension = 2,
220-
Generic = 3
217+
218+
export namespace TaskSourceKind {
219+
export const Workspace: 'workspace' = 'workspace';
220+
export const Extension: 'extension' = 'extension';
221+
export const Composite: 'composite' = 'composite';
222+
}
223+
224+
export interface TaskSourceConfigElement {
225+
file: string;
226+
index: number;
227+
element: any;
228+
}
229+
230+
export interface WorkspaceTaskSource {
231+
kind: 'workspace';
232+
label: string;
233+
config: TaskSourceConfigElement;
221234
}
222235

223-
export interface TaskSource {
224-
kind: TaskSourceKind;
236+
export interface ExtensionTaskSource {
237+
kind: 'extension';
225238
label: string;
226-
detail?: string;
227-
config?: {
228-
index: number;
229-
element: any;
230-
};
239+
extension: string;
231240
}
232241

242+
export interface CompositeTaskSource {
243+
kind: 'composite';
244+
label: string;
245+
}
246+
247+
export type TaskSource = WorkspaceTaskSource | ExtensionTaskSource | CompositeTaskSource;
248+
233249
export interface TaskIdentifier {
234250
_key: string;
235251
type: string;
@@ -295,18 +311,18 @@ export interface CommonTask {
295311
*/
296312
_label: string;
297313

298-
/**
299-
* Indicated the source of the task (e.g tasks.json or extension)
300-
*/
301-
_source: TaskSource;
302-
303314
type: string;
304315
}
305316

306317
export interface CustomTask extends CommonTask, ConfigurationProperties {
307318

308319
type: 'custom';
309320

321+
/**
322+
* Indicated the source of the task (e.g tasks.json or extension)
323+
*/
324+
_source: WorkspaceTaskSource;
325+
310326
name: string;
311327

312328
identifier: string;
@@ -326,6 +342,11 @@ export namespace CustomTask {
326342

327343
export interface ConfiguringTask extends CommonTask, ConfigurationProperties {
328344

345+
/**
346+
* Indicated the source of the task (e.g tasks.json or extension)
347+
*/
348+
_source: WorkspaceTaskSource;
349+
329350
configures: TaskIdentifier;
330351
}
331352

@@ -338,6 +359,11 @@ export namespace ConfiguringTask {
338359

339360
export interface ContributedTask extends CommonTask, ConfigurationProperties {
340361

362+
/**
363+
* Indicated the source of the task (e.g tasks.json or extension)
364+
*/
365+
_source: ExtensionTaskSource;
366+
341367
defines: TaskIdentifier;
342368

343369
hasDefinedMatchers: boolean;
@@ -355,11 +381,29 @@ export namespace ContributedTask {
355381
}
356382
}
357383

358-
export type Task = CustomTask | ContributedTask;
384+
export interface CompositeTask extends CommonTask, ConfigurationProperties {
385+
/**
386+
* Indicated the source of the task (e.g tasks.json or extension)
387+
*/
388+
_source: CompositeTaskSource;
389+
390+
type: 'composite';
391+
392+
identifier: string;
393+
}
394+
395+
export namespace CompositeTask {
396+
export function is(value: any): value is CompositeTask {
397+
let candidate = value as CompositeTask;
398+
return candidate && candidate._source && candidate._source.kind === TaskSourceKind.Composite;
399+
}
400+
}
401+
402+
export type Task = CustomTask | ContributedTask | CompositeTask;
359403

360404
export namespace Task {
361405
export function getKey(task: Task): string {
362-
if (CustomTask.is(task)) {
406+
if (CustomTask.is(task) || CompositeTask.is(task)) {
363407
return task.identifier;
364408
} else {
365409
return task.defines._key;

0 commit comments

Comments
 (0)