Skip to content

Commit fdadd0e

Browse files
committed
Make identifier computed to better support task customization
1 parent bf5bb9d commit fdadd0e

7 files changed

Lines changed: 35 additions & 23 deletions

File tree

src/vs/vscode.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,10 +3626,10 @@ declare module 'vscode' {
36263626
readonly name: string;
36273627

36283628
/**
3629-
* The task's identifier. If omitted the name is
3630-
* used as an identifier.
3629+
* The task's identifier. If omitted the internal identifier will
3630+
* be `${extensionName}:${name}`
36313631
*/
3632-
identifier: string;
3632+
identifier: string | undefined;
36333633

36343634
/**
36353635
* Whether the task is a background task or not.
@@ -3759,10 +3759,10 @@ declare module 'vscode' {
37593759
readonly name: string;
37603760

37613761
/**
3762-
* The task's identifier. If omitted the name is
3763-
* used as an identifier.
3762+
* The task's identifier. If omitted the internal identifier will
3763+
* be `${extensionName}:${name}`
37643764
*/
3765-
identifier: string;
3765+
identifier: string | undefined;
37663766

37673767
/**
37683768
* Whether the task is a background task or not.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ namespace Tasks {
316316
detail: extension.id
317317
},
318318
name: task.name,
319-
identifier: task.identifier,
319+
identifier: task.identifier ? task.identifier : `${extension.id}.${task.name}`,
320320
group: types.TaskGroup.is(task.group) ? task.group : undefined,
321321
command: command,
322322
isBackground: !!task.isBackground,

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,6 @@ export class BaseTask {
10301030
throw illegalArgument('name');
10311031
}
10321032
this._name = name;
1033-
this._identifier = name;
10341033
this._problemMatchers = problemMatchers || [];
10351034
this._isBackground = false;
10361035
this._terminal = Object.create(null);
@@ -1041,11 +1040,11 @@ export class BaseTask {
10411040
}
10421041

10431042
set identifier(value: string) {
1044-
if (typeof value !== 'string') {
1045-
throw illegalArgument('identifier');
1043+
if (value === void 0 || value === null) {
1044+
this._identifier = undefined;
10461045
}
1047-
if (value.indexOf(':') !== -1) {
1048-
throw illegalArgument('identifier must not contain \':\'');
1046+
if (typeof value !== 'string' || value.length === 0) {
1047+
throw illegalArgument('identifier must be a string of length > 0');
10491048
}
10501049
this._identifier = value;
10511050
}

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

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

16-
import { Task, TaskSourceKind } from 'vs/workbench/parts/tasks/common/tasks';
16+
import { Task, TaskSourceKind, computeLabel } from 'vs/workbench/parts/tasks/common/tasks';
1717
import { ITaskService } from 'vs/workbench/parts/tasks/common/taskService';
1818
import { ActionBarContributor, ContributableActionProvider } from 'vs/workbench/browser/actionBarRegistry';
1919

@@ -23,11 +23,7 @@ export class TaskEntry extends Model.QuickOpenEntry {
2323

2424
constructor(protected taskService: ITaskService, protected _task: Task, highlights: Model.IHighlight[] = []) {
2525
super(highlights);
26-
if (_task._source.kind === TaskSourceKind.Extension) {
27-
this._label = nls.localize('taskEntry.label', '{0}: {1}', _task._source.label, _task.name);
28-
} else {
29-
this._label = _task.name;
30-
}
26+
this._label = computeLabel(_task);
3127
}
3228

3329
public getLabel(): string {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7+
import nls = require('vs/nls');
78
import * as Types from 'vs/base/common/types';
89

910
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
@@ -248,4 +249,12 @@ export enum ExecutionEngine {
248249
export interface TaskSet {
249250
tasks: Task[];
250251
extension?: IExtensionDescription;
252+
}
253+
254+
export function computeLabel(task: Task): string {
255+
if (task._source.kind === TaskSourceKind.Extension) {
256+
return nls.localize('taskEntry.label', '{0}: {1}', task._source.label, task.name);
257+
} else {
258+
return task.name;
259+
}
251260
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,25 @@ const group: IJSONSchema = {
6767
type: 'string',
6868
enum: ['none', 'clean', 'build', 'rebuildAll', 'test'],
6969
default: 'none',
70-
description: nls.localize('JsonSchema.tasks.group', 'Defines to which execution group this task belongs to. If omitted the task belongs to no group')
70+
description: nls.localize('JsonSchema.tasks.group', 'Defines to which execution group this task belongs to. If omitted the task belongs to no group.')
7171
};
7272

7373
const taskType: IJSONSchema = {
7474
type: 'string',
7575
enum: ['shell', 'process'],
7676
default: 'process',
77-
description: nls.localize('JsonSchema.tasks.type', 'Defines whether the task is run as a process or as a command inside a shell. Default is process')
77+
description: nls.localize('JsonSchema.tasks.type', 'Defines whether the task is run as a process or as a command inside a shell. Default is process.')
7878
};
7979

8080
const version: IJSONSchema = {
8181
type: 'string',
8282
enum: ['2.0.0'],
83-
description: nls.localize('JsonSchema.version', 'The config\'s version number')
83+
description: nls.localize('JsonSchema.version', 'The config\'s version number.')
84+
};
85+
86+
const identifier: IJSONSchema = {
87+
type: 'string',
88+
description: nls.localize('JsonSchema.tasks.identifier', 'A unique identifier of the task.')
8489
};
8590

8691
const schema: IJSONSchema = {
@@ -123,6 +128,7 @@ definitions.showOutputType.deprecationMessage = nls.localize('JsonSchema.tasks.s
123128
definitions.taskDescription.properties.echoCommand.deprecationMessage = nls.localize('JsonSchema.tasks.echoCommand.deprecated', 'The property echoCommand is deprecated. Use the terminal property instead.');
124129
definitions.taskDescription.properties.isBuildCommand.deprecationMessage = nls.localize('JsonSchema.tasks.isBuildCommand.deprecated', 'The property isBuildCommand is deprecated. Use the group property instead.');
125130
definitions.taskDescription.properties.isTestCommand.deprecationMessage = nls.localize('JsonSchema.tasks.isTestCommand.deprecated', 'The property isTestCommand is deprecated. Use the group property instead.');
131+
definitions.taskDescription.properties.identifier = identifier;
126132
definitions.taskDescription.properties.type = Objects.deepClone(taskType);
127133
definitions.taskDescription.properties.terminal = terminal;
128134
definitions.taskDescription.properties.group = group;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import { Scope, IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs
7171
import { ITerminalService } from 'vs/workbench/parts/terminal/common/terminal';
7272

7373
import { ITaskSystem, ITaskResolver, ITaskSummary, ITaskExecuteResult, TaskExecuteKind, TaskError, TaskErrors, TaskSystemEvents } from 'vs/workbench/parts/tasks/common/taskSystem';
74-
import { Task, TaskSet, TaskGroup, ExecutionEngine, TaskSourceKind } from 'vs/workbench/parts/tasks/common/tasks';
74+
import { Task, TaskSet, TaskGroup, ExecutionEngine, TaskSourceKind, computeLabel as computeTaskLabel } from 'vs/workbench/parts/tasks/common/tasks';
7575
import { ITaskService, TaskServiceEvents, ITaskProvider } from 'vs/workbench/parts/tasks/common/taskService';
7676
import { templates as taskTemplates } from 'vs/workbench/parts/tasks/common/taskTemplates';
7777

@@ -709,7 +709,7 @@ class TaskService extends EventEmitter implements ITaskService {
709709
return TPromise.as<void>(undefined);
710710
}
711711
let fileConfig = configuration.config;
712-
let customize = { taskName: task.name };
712+
let customize = { taskName: computeTaskLabel(task), identifier: task.identifier };
713713
if (!fileConfig) {
714714
fileConfig = {
715715
version: '2.0.0',
@@ -931,6 +931,7 @@ class TaskService extends EventEmitter implements ITaskService {
931931
let annotatingTask = annotatingTasks.byIdentifier[task.identifier] || annotatingTasks.byName[task.name];
932932
if (annotatingTask) {
933933
TaskConfig.mergeTasks(task, annotatingTask);
934+
task.name = annotatingTask.name;
934935
task._source.kind = TaskSourceKind.Workspace;
935936
continue;
936937
}
@@ -940,6 +941,7 @@ class TaskService extends EventEmitter implements ITaskService {
940941
if (legacyAnnotatingTask) {
941942
TaskConfig.mergeTasks(task, legacyAnnotatingTask);
942943
task._source.kind = TaskSourceKind.Workspace;
944+
task.name = legacyAnnotatingTask.name;
943945
workspaceTasksToDelete.push(legacyAnnotatingTask);
944946
continue;
945947
}

0 commit comments

Comments
 (0)