提交 e58c2abb 编写于 作者: D Dirk Baeumer

Implements #27399: Separate the task provider name from the task name in the task API

上级 7c3f873b
...@@ -139,8 +139,8 @@ async function getGruntTasks(): Promise<vscode.Task[]> { ...@@ -139,8 +139,8 @@ async function getGruntTasks(): Promise<vscode.Task[]> {
if (matches && matches.length === 2) { if (matches && matches.length === 2) {
let taskName = matches[1]; let taskName = matches[1];
let task = taskName.indexOf(' ') === -1 let task = taskName.indexOf(' ') === -1
? new vscode.ShellTask(`grunt: ${taskName}`, `${command} ${taskName}`) ? new vscode.ShellTask(taskName, `${command} ${taskName}`)
: new vscode.ShellTask(`grunt: ${taskName}`, `${command} "${taskName}"`); : new vscode.ShellTask(taskName, `${command} "${taskName}"`);
task.identifier = `grunt.${taskName}`; task.identifier = `grunt.${taskName}`;
result.push(task); result.push(task);
let lowerCaseTaskName = taskName.toLowerCase(); let lowerCaseTaskName = taskName.toLowerCase();
......
...@@ -114,7 +114,7 @@ async function getGulpTasks(): Promise<vscode.Task[]> { ...@@ -114,7 +114,7 @@ async function getGulpTasks(): Promise<vscode.Task[]> {
if (line.length === 0) { if (line.length === 0) {
continue; continue;
} }
let task = new vscode.ShellTask(`gulp: ${line}`, `${gulpCommand} ${line}`); let task = new vscode.ShellTask(line, `${gulpCommand} ${line}`);
task.identifier = `gulp.${line}`; task.identifier = `gulp.${line}`;
result.push(task); result.push(task);
let lowerCaseLine = line.toLowerCase(); let lowerCaseLine = line.toLowerCase();
......
...@@ -118,7 +118,7 @@ async function getJakeTasks(): Promise<vscode.Task[]> { ...@@ -118,7 +118,7 @@ async function getJakeTasks(): Promise<vscode.Task[]> {
let matches = regExp.exec(line); let matches = regExp.exec(line);
if (matches && matches.length === 2) { if (matches && matches.length === 2) {
let taskName = matches[1]; let taskName = matches[1];
let task = new vscode.ShellTask(`jake: ${taskName}`, `${jakeCommand} ${taskName}`); let task = new vscode.ShellTask(taskName, `${jakeCommand} ${taskName}`);
task.identifier = `jake.${taskName}`; task.identifier = `jake.${taskName}`;
result.push(task); result.push(task);
let lowerCaseLine = line.toLowerCase(); let lowerCaseLine = line.toLowerCase();
......
...@@ -81,7 +81,7 @@ async function getNpmScriptsAsTasks(): Promise<vscode.Task[]> { ...@@ -81,7 +81,7 @@ async function getNpmScriptsAsTasks(): Promise<vscode.Task[]> {
const result: vscode.Task[] = []; const result: vscode.Task[] = [];
Object.keys(json.scripts).forEach(each => { Object.keys(json.scripts).forEach(each => {
const task = new vscode.ShellTask(`npm: run ${each}`, `npm run ${each}`); const task = new vscode.ShellTask(`run ${each}`, `npm run ${each}`);
const lowerCaseTaskName = each.toLowerCase(); const lowerCaseTaskName = each.toLowerCase();
if (lowerCaseTaskName === 'build') { if (lowerCaseTaskName === 'build') {
task.group = vscode.TaskGroup.Build; task.group = vscode.TaskGroup.Build;
...@@ -91,7 +91,7 @@ async function getNpmScriptsAsTasks(): Promise<vscode.Task[]> { ...@@ -91,7 +91,7 @@ async function getNpmScriptsAsTasks(): Promise<vscode.Task[]> {
result.push(task); result.push(task);
}); });
// add some 'well known' npm tasks // add some 'well known' npm tasks
result.push(new vscode.ShellTask(`npm: install`, `npm install`)); result.push(new vscode.ShellTask(`install`, `npm install`));
return Promise.resolve(result); return Promise.resolve(result);
} catch (e) { } catch (e) {
return Promise.resolve(emptyTasks); return Promise.resolve(emptyTasks);
......
...@@ -48,7 +48,8 @@ class TscTaskProvider implements vscode.TaskProvider { ...@@ -48,7 +48,8 @@ class TscTaskProvider implements vscode.TaskProvider {
return projects.map(configFile => { return projects.map(configFile => {
const configFileName = path.relative(rootPath, configFile); const configFileName = path.relative(rootPath, configFile);
const buildTask = new vscode.ShellTask(`tsc: build ${configFileName}`, `${command} -p "${configFile}"`, '$tsc'); const buildTask = new vscode.ShellTask(`build ${configFileName}`, `${command} -p "${configFile}"`, '$tsc');
buildTask.source = 'tsc';
buildTask.group = vscode.TaskGroup.Build; buildTask.group = vscode.TaskGroup.Build;
return buildTask; return buildTask;
}); });
......
...@@ -3580,11 +3580,6 @@ declare module 'vscode' { ...@@ -3580,11 +3580,6 @@ declare module 'vscode' {
export const Test: 'test'; export const Test: 'test';
} }
/**
* The supported task groups.
*/
export type TaskGroup = 'clean' | 'build' | 'rebuildAll' | 'test';
/** /**
* The ProblemMatchers type definition. * The ProblemMatchers type definition.
*/ */
...@@ -3652,10 +3647,18 @@ declare module 'vscode' { ...@@ -3652,10 +3647,18 @@ declare module 'vscode' {
args: string[]; args: string[];
/** /**
* The task group this tasks belongs to. Defaults to undefined meaning * A human-readable string describing the source of this
* that the task doesn't belong to any special group. * shell task, e.g. 'gulp' or 'npm'.
*/ */
group?: TaskGroup; source: string | undefined;
/**
* The task group this tasks belongs to. See TaskGroup
* for a predefined set of available groups.
* Defaults to undefined meaning that the task doesn't
* belong to any special group.
*/
group: string | undefined;
/** /**
* The process options used when the process is executed. * The process options used when the process is executed.
...@@ -3772,10 +3775,18 @@ declare module 'vscode' { ...@@ -3772,10 +3775,18 @@ declare module 'vscode' {
readonly commandLine: string; readonly commandLine: string;
/** /**
* The task group this tasks belongs to. Defaults to undefined meaning * A human-readable string describing the source of this
* that the task doesn't belong to any special group. * shell task, e.g. 'gulp' or 'npm'.
*/
source: string | undefined;
/**
* The task group this tasks belongs to. See TaskGroup
* for a predefined set of available groups.
* Defaults to undefined meaning that the task doesn't
* belong to any special group.
*/ */
group?: TaskGroup; group: string | undefined;
/** /**
* The shell options used when the shell is executed. Defaults to an * The shell options used when the shell is executed. Defaults to an
......
...@@ -310,7 +310,11 @@ namespace Tasks { ...@@ -310,7 +310,11 @@ namespace Tasks {
} }
let result: TaskSystem.Task = { let result: TaskSystem.Task = {
_id: uuidMap.getUUID(task.identifier), _id: uuidMap.getUUID(task.identifier),
_source: { kind: TaskSystem.TaskSourceKind.Extension, detail: extension.id }, _source: {
kind: TaskSystem.TaskSourceKind.Extension,
label: typeof task.source === 'string' ? task.source : extension.name,
detail: extension.id
},
name: task.name, name: task.name,
identifier: task.identifier, identifier: task.identifier,
group: types.TaskGroup.is(task.group) ? task.group : undefined, group: types.TaskGroup.is(task.group) ? task.group : undefined,
......
...@@ -1021,6 +1021,8 @@ export class BaseTask { ...@@ -1021,6 +1021,8 @@ export class BaseTask {
private _problemMatchers: string[]; private _problemMatchers: string[];
private _identifier: string; private _identifier: string;
private _isBackground: boolean; private _isBackground: boolean;
private _source: string;
private _group: string;
private _terminal: vscode.TerminalBehaviour; private _terminal: vscode.TerminalBehaviour;
constructor(name: string, problemMatchers: string[]) { constructor(name: string, problemMatchers: string[]) {
...@@ -1063,6 +1065,36 @@ export class BaseTask { ...@@ -1063,6 +1065,36 @@ export class BaseTask {
this._isBackground = value; this._isBackground = value;
} }
get source(): string {
return this._source;
}
set source(value: string) {
if (value === void 0 || value === null) {
this._source = undefined;
return;
}
if (typeof value !== 'string' || value.length === 0) {
throw illegalArgument('source must be a string of length > 0');
}
this._source = value;
}
get group(): string {
return this._group;
}
set group(value: string) {
if (value === void 0 || value === null) {
this._group = undefined;
return;
}
if (typeof value !== 'string' || value.length === 0) {
throw illegalArgument('group must be a string of length > 0');
}
this._group = value;
}
get terminal(): vscode.TerminalBehaviour { get terminal(): vscode.TerminalBehaviour {
return this._terminal; return this._terminal;
} }
...@@ -1122,7 +1154,7 @@ export namespace TaskGroup { ...@@ -1122,7 +1154,7 @@ export namespace TaskGroup {
*/ */
export const Test: 'test' = 'test'; export const Test: 'test' = 'test';
export function is(value: string): value is vscode.TaskGroup { export function is(value: string): value is string {
return value === Clean || value === Build || value === RebuildAll || value === Test; return value === Clean || value === Build || value === RebuildAll || value === Test;
} }
} }
...@@ -1131,7 +1163,6 @@ export class ProcessTask extends BaseTask { ...@@ -1131,7 +1163,6 @@ export class ProcessTask extends BaseTask {
private _process: string; private _process: string;
private _args: string[]; private _args: string[];
private _group: vscode.TaskGroup;
private _options: vscode.ProcessOptions; private _options: vscode.ProcessOptions;
constructor(name: string, process: string, args?: string[], problemMatchers?: vscode.ProblemMatchers); constructor(name: string, process: string, args?: string[], problemMatchers?: vscode.ProblemMatchers);
...@@ -1183,17 +1214,6 @@ export class ProcessTask extends BaseTask { ...@@ -1183,17 +1214,6 @@ export class ProcessTask extends BaseTask {
this._args = value; this._args = value;
} }
get group(): vscode.TaskGroup {
return this._group;
}
set group(value: vscode.TaskGroup) {
if (!TaskGroup.is(value)) {
throw illegalArgument('group');
}
this._group = value;
}
get options(): vscode.ProcessOptions { get options(): vscode.ProcessOptions {
return this._options; return this._options;
} }
...@@ -1209,7 +1229,6 @@ export class ProcessTask extends BaseTask { ...@@ -1209,7 +1229,6 @@ export class ProcessTask extends BaseTask {
export class ShellTask extends BaseTask implements vscode.ShellTask { export class ShellTask extends BaseTask implements vscode.ShellTask {
private _commandLine: string; private _commandLine: string;
private _group: vscode.TaskGroup;
private _options: vscode.ShellOptions; private _options: vscode.ShellOptions;
constructor(name: string, commandLine: string, problemMatchers?: vscode.ProblemMatchers); constructor(name: string, commandLine: string, problemMatchers?: vscode.ProblemMatchers);
...@@ -1240,17 +1259,6 @@ export class ShellTask extends BaseTask implements vscode.ShellTask { ...@@ -1240,17 +1259,6 @@ export class ShellTask extends BaseTask implements vscode.ShellTask {
return this._commandLine; return this._commandLine;
} }
get group(): vscode.TaskGroup {
return this._group;
}
set group(value: vscode.TaskGroup) {
if (!TaskGroup.is(value)) {
throw illegalArgument('group');
}
this._group = value;
}
get options(): vscode.ShellOptions { get options(): vscode.ShellOptions {
return this._options; return this._options;
} }
......
...@@ -19,13 +19,19 @@ import { ActionBarContributor, ContributableActionProvider } from 'vs/workbench/ ...@@ -19,13 +19,19 @@ import { ActionBarContributor, ContributableActionProvider } from 'vs/workbench/
export class TaskEntry extends Model.QuickOpenEntry { export class TaskEntry extends Model.QuickOpenEntry {
private _label: string;
constructor(protected taskService: ITaskService, protected _task: Task, highlights: Model.IHighlight[] = []) { constructor(protected taskService: ITaskService, protected _task: Task, highlights: Model.IHighlight[] = []) {
super(highlights); super(highlights);
this._task = _task; if (_task._source.kind === TaskSourceKind.Extension) {
this._label = nls.localize('taskEntry.label', '{0}: {1}', _task._source.label, _task.name);
} else {
this._label = _task.name;
}
} }
public getLabel(): string { public getLabel(): string {
return this._task.name; return this._label;
} }
public getAriaLabel(): string { public getAriaLabel(): string {
...@@ -76,6 +82,12 @@ export abstract class QuickOpenHandler extends Quickopen.QuickOpenHandler { ...@@ -76,6 +82,12 @@ export abstract class QuickOpenHandler extends Quickopen.QuickOpenHandler {
let aKind = a._source.kind; let aKind = a._source.kind;
let bKind = b._source.kind; let bKind = b._source.kind;
if (aKind === bKind) { if (aKind === bKind) {
if (aKind === TaskSourceKind.Extension) {
let compare = a._source.label.localeCompare(b._source.label);
if (compare !== 0) {
return compare;
}
}
return a.name.localeCompare(b.name); return a.name.localeCompare(b.name);
} }
if (aKind === TaskSourceKind.Workspace) { if (aKind === TaskSourceKind.Workspace) {
......
...@@ -764,6 +764,7 @@ namespace TaskDescription { ...@@ -764,6 +764,7 @@ namespace TaskDescription {
export let source: Tasks.TaskSource = { export let source: Tasks.TaskSource = {
kind: Tasks.TaskSourceKind.Workspace, kind: Tasks.TaskSourceKind.Workspace,
label: 'Workspace',
detail: '.settins\tasks.json' detail: '.settins\tasks.json'
}; };
......
...@@ -153,7 +153,7 @@ export namespace TaskGroup { ...@@ -153,7 +153,7 @@ export namespace TaskGroup {
export const Test: 'test' = 'test'; export const Test: 'test' = 'test';
export function is(value: string): value is TaskGroup { export function is(value: string): value is string {
return value === Clean || value === Build || value === RebuildAll || value === Test; return value === Clean || value === Build || value === RebuildAll || value === Test;
} }
} }
...@@ -168,6 +168,7 @@ export enum TaskSourceKind { ...@@ -168,6 +168,7 @@ export enum TaskSourceKind {
export interface TaskSource { export interface TaskSource {
kind: TaskSourceKind; kind: TaskSourceKind;
label: string;
detail?: string; detail?: string;
} }
...@@ -199,7 +200,7 @@ export interface Task { ...@@ -199,7 +200,7 @@ export interface Task {
/** /**
* the task's group; * the task's group;
*/ */
group?: TaskGroup; group?: string;
/** /**
* The command configuration * The command configuration
......
...@@ -780,7 +780,7 @@ class TaskService extends EventEmitter implements ITaskService { ...@@ -780,7 +780,7 @@ class TaskService extends EventEmitter implements ITaskService {
let id: string = UUID.generateUuid(); let id: string = UUID.generateUuid();
let task: Task = { let task: Task = {
_id: id, _id: id,
_source: { kind: TaskSourceKind.Generic }, _source: { kind: TaskSourceKind.Generic, label: 'generic' },
name: id, name: id,
identifier: id, identifier: id,
dependsOn: extensionTasks.map(task => task._id), dependsOn: extensionTasks.map(task => task._id),
......
...@@ -144,7 +144,7 @@ class TaskBuilder { ...@@ -144,7 +144,7 @@ class TaskBuilder {
this.commandBuilder = new CommandConfigurationBuilder(this, command); this.commandBuilder = new CommandConfigurationBuilder(this, command);
this.result = { this.result = {
_id: name, _id: name,
_source: { kind: Tasks.TaskSourceKind.Workspace }, _source: { kind: Tasks.TaskSourceKind.Workspace, label: 'workspace' },
identifier: name, identifier: name,
name: name, name: name,
command: this.commandBuilder.result, command: this.commandBuilder.result,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册