From fdadd0ed5fd39deebe8fb9e0ac5bd6efb4dfb94e Mon Sep 17 00:00:00 2001 From: Dirk Baeumer Date: Mon, 29 May 2017 15:38:55 +0200 Subject: [PATCH] Make identifier computed to better support task customization --- src/vs/vscode.d.ts | 12 ++++++------ src/vs/workbench/api/node/extHostTask.ts | 2 +- src/vs/workbench/api/node/extHostTypes.ts | 9 ++++----- src/vs/workbench/parts/tasks/browser/quickOpen.ts | 8 ++------ src/vs/workbench/parts/tasks/common/tasks.ts | 9 +++++++++ .../parts/tasks/electron-browser/jsonSchema_v2.ts | 12 +++++++++--- .../tasks/electron-browser/task.contribution.ts | 6 ++++-- 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 979822a1f4d..a2de9d4811a 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -3626,10 +3626,10 @@ declare module 'vscode' { readonly name: string; /** - * The task's identifier. If omitted the name is - * used as an identifier. + * The task's identifier. If omitted the internal identifier will + * be `${extensionName}:${name}` */ - identifier: string; + identifier: string | undefined; /** * Whether the task is a background task or not. @@ -3759,10 +3759,10 @@ declare module 'vscode' { readonly name: string; /** - * The task's identifier. If omitted the name is - * used as an identifier. + * The task's identifier. If omitted the internal identifier will + * be `${extensionName}:${name}` */ - identifier: string; + identifier: string | undefined; /** * Whether the task is a background task or not. diff --git a/src/vs/workbench/api/node/extHostTask.ts b/src/vs/workbench/api/node/extHostTask.ts index 99f5368de6f..7508d947d45 100644 --- a/src/vs/workbench/api/node/extHostTask.ts +++ b/src/vs/workbench/api/node/extHostTask.ts @@ -316,7 +316,7 @@ namespace Tasks { detail: extension.id }, name: task.name, - identifier: task.identifier, + identifier: task.identifier ? task.identifier : `${extension.id}.${task.name}`, group: types.TaskGroup.is(task.group) ? task.group : undefined, command: command, isBackground: !!task.isBackground, diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index 87509da1649..2912a30ef42 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -1030,7 +1030,6 @@ export class BaseTask { throw illegalArgument('name'); } this._name = name; - this._identifier = name; this._problemMatchers = problemMatchers || []; this._isBackground = false; this._terminal = Object.create(null); @@ -1041,11 +1040,11 @@ export class BaseTask { } set identifier(value: string) { - if (typeof value !== 'string') { - throw illegalArgument('identifier'); + if (value === void 0 || value === null) { + this._identifier = undefined; } - if (value.indexOf(':') !== -1) { - throw illegalArgument('identifier must not contain \':\''); + if (typeof value !== 'string' || value.length === 0) { + throw illegalArgument('identifier must be a string of length > 0'); } this._identifier = value; } diff --git a/src/vs/workbench/parts/tasks/browser/quickOpen.ts b/src/vs/workbench/parts/tasks/browser/quickOpen.ts index 15432e9c647..6f82d048270 100644 --- a/src/vs/workbench/parts/tasks/browser/quickOpen.ts +++ b/src/vs/workbench/parts/tasks/browser/quickOpen.ts @@ -13,7 +13,7 @@ import QuickOpen = require('vs/base/parts/quickopen/common/quickOpen'); import Model = require('vs/base/parts/quickopen/browser/quickOpenModel'); import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; -import { Task, TaskSourceKind } from 'vs/workbench/parts/tasks/common/tasks'; +import { Task, TaskSourceKind, computeLabel } from 'vs/workbench/parts/tasks/common/tasks'; import { ITaskService } from 'vs/workbench/parts/tasks/common/taskService'; import { ActionBarContributor, ContributableActionProvider } from 'vs/workbench/browser/actionBarRegistry'; @@ -23,11 +23,7 @@ export class TaskEntry extends Model.QuickOpenEntry { constructor(protected taskService: ITaskService, protected _task: Task, highlights: Model.IHighlight[] = []) { super(highlights); - if (_task._source.kind === TaskSourceKind.Extension) { - this._label = nls.localize('taskEntry.label', '{0}: {1}', _task._source.label, _task.name); - } else { - this._label = _task.name; - } + this._label = computeLabel(_task); } public getLabel(): string { diff --git a/src/vs/workbench/parts/tasks/common/tasks.ts b/src/vs/workbench/parts/tasks/common/tasks.ts index e7d54343b07..b798e6314e5 100644 --- a/src/vs/workbench/parts/tasks/common/tasks.ts +++ b/src/vs/workbench/parts/tasks/common/tasks.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; +import nls = require('vs/nls'); import * as Types from 'vs/base/common/types'; import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; @@ -248,4 +249,12 @@ export enum ExecutionEngine { export interface TaskSet { tasks: Task[]; extension?: IExtensionDescription; +} + +export function computeLabel(task: Task): string { + if (task._source.kind === TaskSourceKind.Extension) { + return nls.localize('taskEntry.label', '{0}: {1}', task._source.label, task.name); + } else { + return task.name; + } } \ No newline at end of file diff --git a/src/vs/workbench/parts/tasks/electron-browser/jsonSchema_v2.ts b/src/vs/workbench/parts/tasks/electron-browser/jsonSchema_v2.ts index b184d7ee3ff..e12e519fc02 100644 --- a/src/vs/workbench/parts/tasks/electron-browser/jsonSchema_v2.ts +++ b/src/vs/workbench/parts/tasks/electron-browser/jsonSchema_v2.ts @@ -67,20 +67,25 @@ const group: IJSONSchema = { type: 'string', enum: ['none', 'clean', 'build', 'rebuildAll', 'test'], default: 'none', - description: nls.localize('JsonSchema.tasks.group', 'Defines to which execution group this task belongs to. If omitted the task belongs to no group') + description: nls.localize('JsonSchema.tasks.group', 'Defines to which execution group this task belongs to. If omitted the task belongs to no group.') }; const taskType: IJSONSchema = { type: 'string', enum: ['shell', 'process'], default: 'process', - 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') + 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.') }; const version: IJSONSchema = { type: 'string', enum: ['2.0.0'], - description: nls.localize('JsonSchema.version', 'The config\'s version number') + description: nls.localize('JsonSchema.version', 'The config\'s version number.') +}; + +const identifier: IJSONSchema = { + type: 'string', + description: nls.localize('JsonSchema.tasks.identifier', 'A unique identifier of the task.') }; const schema: IJSONSchema = { @@ -123,6 +128,7 @@ definitions.showOutputType.deprecationMessage = nls.localize('JsonSchema.tasks.s definitions.taskDescription.properties.echoCommand.deprecationMessage = nls.localize('JsonSchema.tasks.echoCommand.deprecated', 'The property echoCommand is deprecated. Use the terminal property instead.'); definitions.taskDescription.properties.isBuildCommand.deprecationMessage = nls.localize('JsonSchema.tasks.isBuildCommand.deprecated', 'The property isBuildCommand is deprecated. Use the group property instead.'); definitions.taskDescription.properties.isTestCommand.deprecationMessage = nls.localize('JsonSchema.tasks.isTestCommand.deprecated', 'The property isTestCommand is deprecated. Use the group property instead.'); +definitions.taskDescription.properties.identifier = identifier; definitions.taskDescription.properties.type = Objects.deepClone(taskType); definitions.taskDescription.properties.terminal = terminal; definitions.taskDescription.properties.group = group; diff --git a/src/vs/workbench/parts/tasks/electron-browser/task.contribution.ts b/src/vs/workbench/parts/tasks/electron-browser/task.contribution.ts index d94812a35bb..411e04c6df5 100644 --- a/src/vs/workbench/parts/tasks/electron-browser/task.contribution.ts +++ b/src/vs/workbench/parts/tasks/electron-browser/task.contribution.ts @@ -71,7 +71,7 @@ import { Scope, IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs import { ITerminalService } from 'vs/workbench/parts/terminal/common/terminal'; import { ITaskSystem, ITaskResolver, ITaskSummary, ITaskExecuteResult, TaskExecuteKind, TaskError, TaskErrors, TaskSystemEvents } from 'vs/workbench/parts/tasks/common/taskSystem'; -import { Task, TaskSet, TaskGroup, ExecutionEngine, TaskSourceKind } from 'vs/workbench/parts/tasks/common/tasks'; +import { Task, TaskSet, TaskGroup, ExecutionEngine, TaskSourceKind, computeLabel as computeTaskLabel } from 'vs/workbench/parts/tasks/common/tasks'; import { ITaskService, TaskServiceEvents, ITaskProvider } from 'vs/workbench/parts/tasks/common/taskService'; import { templates as taskTemplates } from 'vs/workbench/parts/tasks/common/taskTemplates'; @@ -709,7 +709,7 @@ class TaskService extends EventEmitter implements ITaskService { return TPromise.as(undefined); } let fileConfig = configuration.config; - let customize = { taskName: task.name }; + let customize = { taskName: computeTaskLabel(task), identifier: task.identifier }; if (!fileConfig) { fileConfig = { version: '2.0.0', @@ -931,6 +931,7 @@ class TaskService extends EventEmitter implements ITaskService { let annotatingTask = annotatingTasks.byIdentifier[task.identifier] || annotatingTasks.byName[task.name]; if (annotatingTask) { TaskConfig.mergeTasks(task, annotatingTask); + task.name = annotatingTask.name; task._source.kind = TaskSourceKind.Workspace; continue; } @@ -940,6 +941,7 @@ class TaskService extends EventEmitter implements ITaskService { if (legacyAnnotatingTask) { TaskConfig.mergeTasks(task, legacyAnnotatingTask); task._source.kind = TaskSourceKind.Workspace; + task.name = legacyAnnotatingTask.name; workspaceTasksToDelete.push(legacyAnnotatingTask); continue; }