Skip to content

Commit b5ae943

Browse files
committed
Fixes microsoft#29013: Tasks 2.0 integration with launch.json
1 parent a5248f3 commit b5ae943

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/vs/workbench/parts/debug/electron-browser/debugService.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,8 @@ export class DebugService implements debug.IDebugService {
855855
}
856856

857857
// run a task before starting a debug session
858-
return this.taskService.tasks().then(descriptions => {
859-
const filteredTasks = descriptions.filter(task => task.name === taskName);
860-
if (filteredTasks.length !== 1) {
858+
return this.taskService.getTask(taskName).then(task => {
859+
if (!task) {
861860
return TPromise.wrapError(errors.create(nls.localize('DebugTaskNotFound', "Could not find the preLaunchTask \'{0}\'.", taskName)));
862861
}
863862

@@ -872,14 +871,14 @@ export class DebugService implements debug.IDebugService {
872871
}
873872

874873
// no task running, execute the preLaunchTask.
875-
const taskPromise = this.taskService.run(filteredTasks[0]).then(result => {
874+
const taskPromise = this.taskService.run(task).then(result => {
876875
this.lastTaskEvent = null;
877876
return result;
878877
}, err => {
879878
this.lastTaskEvent = null;
880879
});
881880

882-
if (filteredTasks[0].isBackground) {
881+
if (task.isBackground) {
883882
return new TPromise((c, e) => this.taskService.addOneTimeListener(TaskServiceEvents.Inactive, () => c(null)));
884883
}
885884

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export interface ITaskService extends IEventEmitter {
4242
terminate(task: string | Task): TPromise<TaskTerminateResponse>;
4343
terminateAll(): TPromise<TaskTerminateResponse[]>;
4444
tasks(): TPromise<Task[]>;
45+
/**
46+
* @param identifier The task's name, label or defined identifier.
47+
*/
48+
getTask(identifier: string): TPromise<Task>;
4549
getTasksForGroup(group: string): TPromise<Task[]>;
4650
getRecentlyUsedTasks(): LinkedMap<string, string>;
4751

src/vs/workbench/parts/tasks/electron-browser/jsonSchema_v2.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ const version: IJSONSchema = {
139139
description: nls.localize('JsonSchema.version', 'The config\'s version number.')
140140
};
141141

142+
const identifier: IJSONSchema = {
143+
type: 'string',
144+
description: nls.localize('JsonSchema.tasks.identifier', 'A user defined identifier to reference the task in launch.json or a dependsOn clause.')
145+
};
146+
142147
let taskConfiguration: IJSONSchema = {
143148
type: 'object',
144149
additionalProperties: false,
@@ -152,6 +157,7 @@ let taskConfiguration: IJSONSchema = {
152157
description: nls.localize('JsonSchema.tasks.taskName', 'The task\'s name'),
153158
deprecationMessage: nls.localize('JsonSchema.tasks.taskName.deprecated', 'The task\'s name property is deprecated. Use the label property instead.')
154159
},
160+
identifier: Objects.deepClone(identifier),
155161
group: Objects.deepClone(group),
156162
isBackground: {
157163
type: 'boolean',
@@ -204,6 +210,7 @@ let definitions = Objects.deepClone(commonSchema.definitions);
204210
let taskDescription: IJSONSchema = definitions.taskDescription;
205211
taskDescription.properties.isShellCommand = Objects.deepClone(shellCommand);
206212
taskDescription.properties.dependsOn = dependsOn;
213+
taskDescription.properties.identifier = Objects.deepClone(identifier);
207214
definitions.showOutputType.deprecationMessage = nls.localize(
208215
'JsonSchema.tasks.showOputput.deprecated',
209216
'The property showOutput is deprecated. Use the reveal property inside the presentation property instead. See also the 1.14 release notes.'

src/vs/workbench/parts/tasks/electron-browser/task.contribution.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,13 @@ class TaskService extends EventEmitter implements ITaskService {
681681
return this._providers.delete(handle);
682682
}
683683

684+
public getTask(identifier: string): TPromise<Task> {
685+
return this.getTaskSets().then((sets) => {
686+
let resolver = this.createResolver(sets);
687+
return resolver.resolve(identifier);
688+
});
689+
}
690+
684691
public tasks(): TPromise<Task[]> {
685692
return this.getTaskSets().then((sets) => {
686693
let result: Task[] = [];
@@ -1697,7 +1704,7 @@ schema.definitions = {
16971704
...schemaVersion1.definitions,
16981705
...schemaVersion2.definitions,
16991706
};
1700-
schema.oneOf = [...schemaVersion1.oneOf, ...schemaVersion2.oneOf];
1707+
schema.oneOf = [...schemaVersion2.oneOf, ...schemaVersion1.oneOf];
17011708

17021709

17031710
let jsonRegistry = <jsonContributionRegistry.IJSONContributionRegistry>Registry.as(jsonContributionRegistry.Extensions.JSONContribution);

0 commit comments

Comments
 (0)