Make identifier computed to better support task customization

This commit is contained in:
Dirk Baeumer
2017-05-29 15:38:55 +02:00
parent bf5bb9de5c
commit fdadd0ed5f
7 changed files with 35 additions and 23 deletions

12
src/vs/vscode.d.ts vendored
View File

@@ -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.

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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 {

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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<void>(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;
}