Add task detail property and adopt in npm extension

Fixes #69785
This commit is contained in:
Alex Ross 2019-10-22 15:56:21 +02:00
parent ea47d6b95b
commit 87998af618
13 changed files with 1139 additions and 12 deletions

View file

@ -5,7 +5,7 @@
import * as path from 'path';
import {
Event, EventEmitter, ExtensionContext, Task,
Event, EventEmitter, ExtensionContext, Task2 as Task,
TextDocument, ThemeIcon, TreeDataProvider, TreeItem, TreeItemCollapsibleState, Uri,
WorkspaceFolder, commands, window, workspace, tasks, Selection, TaskGroup
} from 'vscode';
@ -108,6 +108,9 @@ class NpmScript extends TreeItem {
dark: context.asAbsolutePath(path.join('resources', 'dark', 'script.svg'))
};
}
if (task.detail) {
this.tooltip = task.detail;
}
}
getFolder(): WorkspaceFolder {
@ -206,7 +209,7 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
if (!uri) {
return;
}
let task = createTask('install', 'install', selection.folder.workspaceFolder, uri, []);
let task = createTask('install', 'install', selection.folder.workspaceFolder, uri, undefined, []);
tasks.executeTask(task);
}

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import {
TaskDefinition, Task, TaskGroup, WorkspaceFolder, RelativePattern, ShellExecution, Uri, workspace,
TaskDefinition, Task2 as Task, TaskGroup, WorkspaceFolder, RelativePattern, ShellExecution, Uri, workspace,
DebugConfiguration, debug, TaskProvider, TextDocument, tasks, TaskScope, QuickPickItem
} from 'vscode';
import * as path from 'path';
@ -237,7 +237,7 @@ async function provideNpmScriptsForFolder(packageJsonUri: Uri): Promise<Task[]>
const prePostScripts = getPrePostScripts(scripts);
Object.keys(scripts).forEach(each => {
const task = createTask(each, `run ${each}`, folder!, packageJsonUri);
const task = createTask(each, `run ${each}`, folder!, packageJsonUri, scripts![each]);
const lowerCaseTaskName = each.toLowerCase();
if (isBuildTask(lowerCaseTaskName)) {
task.group = TaskGroup.Build;
@ -253,7 +253,7 @@ async function provideNpmScriptsForFolder(packageJsonUri: Uri): Promise<Task[]>
result.push(task);
});
// always add npm install (without a problem matcher)
result.push(createTask('install', 'install', folder, packageJsonUri, []));
result.push(createTask('install', 'install', folder, packageJsonUri, undefined, []));
return result;
}
@ -264,7 +264,7 @@ export function getTaskName(script: string, relativePath: string | undefined) {
return script;
}
export function createTask(script: NpmTaskDefinition | string, cmd: string, folder: WorkspaceFolder, packageJsonUri: Uri, matcher?: any): Task {
export function createTask(script: NpmTaskDefinition | string, cmd: string, folder: WorkspaceFolder, packageJsonUri: Uri, detail?: string, matcher?: any): Task {
let kind: NpmTaskDefinition;
if (typeof script === 'string') {
kind = { type: 'npm', script: script };
@ -292,7 +292,9 @@ export function createTask(script: NpmTaskDefinition | string, cmd: string, fold
}
let taskName = getTaskName(kind.script, relativePackageJson);
let cwd = path.dirname(packageJsonUri.fsPath);
return new Task(kind, folder, taskName, 'npm', new ShellExecution(getCommandLine(folder, cmd), { cwd: cwd }), matcher);
const task = new Task(kind, folder, taskName, 'npm', new ShellExecution(getCommandLine(folder, cmd), { cwd: cwd }), matcher);
task.detail = detail;
return task;
}

1068
extensions/npm/src/vscode.proposed.d.ts vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -933,10 +933,10 @@ declare module 'vscode' {
* The task's execution engine
*/
execution2?: ProcessExecution | ShellExecution | CustomExecution;
}
//#endregion
//#region Tasks
detail?: string;
}
export interface TaskPresentationOptions {
/**
* Controls whether the task is executed in a specific terminal group using split panes.

View file

@ -323,6 +323,9 @@ namespace TaskDTO {
if (task.configurationProperties.group) {
result.group = task.configurationProperties.group;
}
if (task.configurationProperties.detail) {
result.detail = task.configurationProperties.detail;
}
if (!ConfiguringTask.is(task) && task.command) {
if (task.command.runtime === RuntimeType.Process) {
result.execution = ProcessExecutionDTO.from(task.command);
@ -380,6 +383,7 @@ namespace TaskDTO {
group: task.group,
isBackground: !!task.isBackground,
problemMatchers: task.problemMatchers.slice(),
detail: task.detail
}
);
return result;

View file

@ -261,6 +261,7 @@ export namespace TaskDTO {
problemMatchers: value.problemMatchers,
hasDefinedMatchers: (value as types.Task).hasDefinedMatchers,
runOptions: (<vscode.Task>value).runOptions ? (<vscode.Task>value).runOptions : { reevaluateOnRerun: true },
detail: (<vscode.Task2>value).detail
};
return result;
}
@ -303,6 +304,9 @@ export namespace TaskDTO {
if (value._id) {
result._id = value._id;
}
if (value.detail) {
result.detail = value.detail;
}
return result;
}
}

View file

@ -1815,6 +1815,7 @@ export class Task implements vscode.Task2 {
private _group: TaskGroup | undefined;
private _presentationOptions: vscode.TaskPresentationOptions;
private _runOptions: vscode.RunOptions;
private _detail: string | undefined;
constructor(definition: vscode.TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution, problemMatchers?: string | string[]);
constructor(definition: vscode.TaskDefinition, scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution, problemMatchers?: string | string[]);
@ -2009,6 +2010,17 @@ export class Task implements vscode.Task2 {
this._group = value;
}
get detail(): string | undefined {
return this._detail;
}
set detail(value: string | undefined) {
if (value === null) {
value = undefined;
}
this._detail = value;
}
get presentationOptions(): vscode.TaskPresentationOptions {
return this._presentationOptions;
}

View file

@ -89,6 +89,7 @@ export interface TaskDTO {
isBackground?: boolean;
source: TaskSourceDTO;
group?: string;
detail?: string;
presentationOptions?: TaskPresentationOptionsDTO;
problemMatchers: string[];
hasDefinedMatchers: boolean;

View file

@ -81,6 +81,7 @@ import { find } from 'vs/base/common/arrays';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
const QUICKOPEN_HISTORY_LIMIT_CONFIG = 'task.quickOpen.history';
const QUICKOPEN_DETAIL_CONFIG = 'task.quickOpen.detail';
export namespace ConfigureTaskAction {
export const ID = 'workbench.action.tasks.configureTaskRunner';
@ -1876,6 +1877,10 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
return true;
}
private showDetail(): boolean {
return this.configurationService.getValue<boolean>(QUICKOPEN_DETAIL_CONFIG);
}
private createTaskQuickPickEntries(tasks: Task[], group: boolean = false, sort: boolean = false, selectedEntry?: TaskQuickPickEntry): TaskQuickPickEntry[] {
if (tasks === undefined || tasks === null || tasks.length === 0) {
return [];
@ -1892,7 +1897,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
description = workspaceFolder.name;
}
}
return { label: task._label, description, task };
return { label: task._label, description, task, detail: this.showDetail() ? task.configurationProperties.detail : undefined };
};
function fillEntries(entries: QuickPickInput<TaskQuickPickEntry>[], tasks: Task[], groupLabel: string): void {
if (tasks.length) {

View file

@ -358,5 +358,10 @@ configurationRegistry.registerConfiguration({
type: 'number',
default: 30, minimum: 0, maximum: 30
},
'task.quickOpen.detail': {
markdownDescription: nls.localize('task.quickOpen.detail', "Controls whether to show the task detail for task that have a detail in the Run Task quick pick."),
type: 'boolean',
default: true
}
}
});

View file

@ -89,6 +89,11 @@ const dependsOrder: IJSONSchema = {
description: nls.localize('JsonSchema.tasks.dependsOrder', 'Determines the order of the dependsOn tasks for this task. Note that this property is not recursive.')
};
const detail: IJSONSchema = {
type: 'string',
description: nls.localize('JsonSchema.tasks.detail', 'An optional description of a task that shows in the Run Task quick pick as a detail.')
};
const presentation: IJSONSchema = {
type: 'object',
default: {
@ -365,7 +370,8 @@ let taskConfiguration: IJSONSchema = {
},
runOptions: Objects.deepClone(runOptions),
dependsOn: Objects.deepClone(dependsOn),
dependsOrder: Objects.deepClone(dependsOrder)
dependsOrder: Objects.deepClone(dependsOrder),
detail: Objects.deepClone(detail),
}
};
@ -425,6 +431,7 @@ taskDescriptionProperties.presentation = Objects.deepClone(presentation);
taskDescriptionProperties.terminal = terminal;
taskDescriptionProperties.group = Objects.deepClone(group);
taskDescriptionProperties.runOptions = Objects.deepClone(runOptions);
taskDescriptionProperties.detail = detail;
taskDescriptionProperties.taskName.deprecationMessage = nls.localize(
'JsonSchema.tasks.taskName.deprecated',
'The task\'s name property is deprecated. Use the label property instead.'

View file

@ -309,6 +309,11 @@ export interface ConfigurationProperties {
*/
group?: string | GroupKind;
/**
* A description of the task.
*/
detail?: string;
/**
* The other tasks the task depend on
*/
@ -1326,6 +1331,9 @@ namespace ConfigurationProperties {
if (configProblemMatcher !== undefined) {
result.problemMatchers = configProblemMatcher;
}
if (external.detail) {
result.detail = external.detail;
}
return isEmpty(result) ? undefined : result;
}
@ -1587,6 +1595,7 @@ namespace CustomTask {
assignProperty(resultConfigProps, configuredProps.configurationProperties, 'dependsOn');
assignProperty(resultConfigProps, configuredProps.configurationProperties, 'problemMatchers');
assignProperty(resultConfigProps, configuredProps.configurationProperties, 'promptOnClose');
assignProperty(resultConfigProps, configuredProps.configurationProperties, 'detail');
result.command.presentation = CommandConfiguration.PresentationOptions.assignProperties(
result.command.presentation!, configuredProps.configurationProperties.presentation)!;
result.command.options = CommandOptions.assignProperties(result.command.options, configuredProps.configurationProperties.options);
@ -1598,6 +1607,7 @@ namespace CustomTask {
fillProperty(resultConfigProps, contributedConfigProps, 'dependsOn');
fillProperty(resultConfigProps, contributedConfigProps, 'problemMatchers');
fillProperty(resultConfigProps, contributedConfigProps, 'promptOnClose');
fillProperty(resultConfigProps, contributedConfigProps, 'detail');
result.command.presentation = CommandConfiguration.PresentationOptions.fillProperties(
result.command.presentation!, contributedConfigProps.presentation)!;
result.command.options = CommandOptions.fillProperties(result.command.options, contributedConfigProps.options);

View file

@ -504,6 +504,11 @@ export interface ConfigurationProperties {
*/
dependsOrder?: DependsOrder;
/**
* A description of the task.
*/
detail?: string;
/**
* The problem watchers to use for this task
*/