Incooperate API feedback

This commit is contained in:
Dirk Baeumer
2017-06-22 17:03:52 +02:00
parent 2ef8e48de4
commit 22fa494aee
17 changed files with 428 additions and 435 deletions

View File

@@ -429,7 +429,7 @@ export function createApiFactory(
getConfiguration: (section?: string): vscode.WorkspaceConfiguration => {
return extHostConfiguration.getConfiguration(section);
},
registerTaskProvider: proposedApiFunction(extension, (provider: vscode.TaskProvider) => {
registerTaskProvider: proposedApiFunction(extension, (type: string, provider: vscode.TaskProvider) => {
return extHostTask.registerTaskProvider(extension, provider);
})
};
@@ -518,8 +518,9 @@ export function createApiFactory(
TaskRevealKind: extHostTypes.TaskRevealKind,
TaskPanelKind: extHostTypes.TaskPanelKind,
TaskGroup: extHostTypes.TaskGroup,
ShellTask: extHostTypes.ShellTask,
ProcessTask: extHostTypes.ProcessTask
ProcessExecution: extHostTypes.ProcessExecution,
ShellExecution: extHostTypes.ShellExecution,
Task: extHostTypes.Task
};
};
}

View File

@@ -256,7 +256,7 @@ namespace CommandOptions {
function isShellConfiguration(value: any): value is { executable: string; shellArgs?: string[] } {
return value && typeof value.executable === 'string';
}
export function from(value: vscode.ShellTaskOptions | vscode.ProcessTaskOptions): TaskSystem.CommandOptions {
export function from(value: vscode.ShellExecutionOptions | vscode.ProcessExecutionOptions): TaskSystem.CommandOptions {
if (value === void 0 || value === null) {
return undefined;
}
@@ -321,37 +321,41 @@ namespace Tasks {
return undefined;
}
let command: TaskSystem.CommandConfiguration;
if (task instanceof types.ProcessTask) {
command = getProcessCommand(task);
} else if (task instanceof types.ShellTask) {
command = getShellCommand(task);
let execution = task.execution;
if (execution instanceof types.ProcessExecution) {
command = getProcessCommand(execution);
} else if (execution instanceof types.ShellExecution) {
command = getShellCommand(execution);
} else {
return undefined;
}
if (command === void 0) {
return undefined;
}
command.presentation = PresentationOptions.from(task.presentationOptions);
let source = {
kind: TaskSystem.TaskSourceKind.Extension,
label: typeof task.source === 'string' ? task.source : extension.name,
detail: extension.id
};
let label = nls.localize('task.label', '{0}: {1}', source.label, task.name);
let id = `${extension.id}.${task.identifierKey}`;
let identifier: TaskSystem.TaskIdentifier = {
_key: task.identifierKey,
type: task.identifier.type
let key = (task as types.Task).kindKey;
let kind = (task as types.Task).kind;
let id = `${extension.id}.${key}`;
let taskKind: TaskSystem.TaskIdentifier = {
_key: key,
type: kind.type
};
Objects.assign(identifier, task.identifier);
Objects.assign(taskKind, kind);
let result: TaskSystem.ContributedTask = {
_id: id, // uuidMap.getUUID(identifier),
_source: source,
_label: label,
type: task.identifier.type,
defines: identifier,
type: kind.type,
defines: taskKind,
name: task.name,
identifier: label,
group: types.TaskGroup.is(task.group) ? task.group : undefined,
group: task.group ? (task.group as types.TaskGroup).id : undefined,
command: command,
isBackground: !!task.isBackground,
problemMatchers: task.problemMatchers.slice()
@@ -359,7 +363,7 @@ namespace Tasks {
return result;
}
function getProcessCommand(value: vscode.ProcessTask): TaskSystem.CommandConfiguration {
function getProcessCommand(value: vscode.ProcessExecution): TaskSystem.CommandConfiguration {
if (typeof value.process !== 'string') {
return undefined;
}
@@ -368,7 +372,7 @@ namespace Tasks {
args: Strings.from(value.args),
runtime: TaskSystem.RuntimeType.Process,
suppressTaskName: true,
presentation: PresentationOptions.from(value.presentationOptions)
presentation: undefined
};
if (value.options) {
result.options = CommandOptions.from(value.options);
@@ -376,14 +380,14 @@ namespace Tasks {
return result;
}
function getShellCommand(value: vscode.ShellTask): TaskSystem.CommandConfiguration {
function getShellCommand(value: vscode.ShellExecution): TaskSystem.CommandConfiguration {
if (typeof value.commandLine !== 'string') {
return undefined;
}
let result: TaskSystem.CommandConfiguration = {
name: value.commandLine,
runtime: TaskSystem.RuntimeType.Shell,
presentation: PresentationOptions.from(value.presentationOptions)
presentation: undefined
};
if (value.options) {
result.options = CommandOptions.from(value.options);

View File

@@ -1015,22 +1015,6 @@ export class DocumentLink {
}
}
export enum FileLocationKind {
Auto = 1,
Relative = 2,
Absolute = 3
}
export enum ApplyToKind {
AllDocuments = 1,
OpenDocuments = 2,
ClosedDocuments = 3
}
export enum TaskRevealKind {
Always = 1,
@@ -1047,44 +1031,170 @@ export enum TaskPanelKind {
New = 3
}
export class BaseTask {
export class TaskGroup implements vscode.TaskGroup {
private _id: string;
private _label: string;
public static Clean: TaskGroup = new TaskGroup('clean', 'Clean');
public static Build: TaskGroup = new TaskGroup('build', 'Build');
public static RebuildAll: TaskGroup = new TaskGroup('rebuildAll', 'RebuildAll');
public static Test: TaskGroup = new TaskGroup('clean', 'Clean');
constructor(id: string, label: string) {
if (typeof id !== 'string') {
throw illegalArgument('name');
}
if (typeof label !== 'string') {
throw illegalArgument('name');
}
this._id = id;
this._label = label;
}
get id(): string {
return this._id;
}
}
export class ProcessExecution implements vscode.ProcessExecution {
private _process: string;
private _args: string[];
private _options: vscode.ProcessExecutionOptions;
constructor(process: string, options?: vscode.ProcessExecutionOptions);
constructor(process: string, args: string[], options?: vscode.ProcessExecutionOptions);
constructor(process: string, varg1?: string[] | vscode.ProcessExecutionOptions, varg2?: vscode.ProcessExecutionOptions) {
if (typeof process !== 'string') {
throw illegalArgument('process');
}
this._process = process;
if (varg1 !== void 0) {
if (Array.isArray(varg1)) {
this._args = varg1;
this._options = varg2;
} else {
this._options = varg1;
}
}
if (this._args === void 0) {
this._args = [];
}
}
get process(): string {
return this._process;
}
set process(value: string) {
if (typeof value !== 'string') {
throw illegalArgument('process');
}
this._process = value;
}
get args(): string[] {
return this._args;
}
set args(value: string[]) {
if (!Array.isArray(value)) {
value = [];
}
this._args = value;
}
get options(): vscode.ProcessExecutionOptions {
return this._options;
}
set options(value: vscode.ProcessExecutionOptions) {
this._options = value;
}
}
export class ShellExecution implements vscode.ShellExecution {
private _commandLine: string;
private _options: vscode.ShellExecutionOptions;
constructor(commandLine: string, options?: vscode.ShellExecutionOptions) {
if (typeof commandLine !== 'string') {
throw illegalArgument('commandLine');
}
this._commandLine = commandLine;
this._options = options;
}
get commandLine(): string {
return this._commandLine;
}
set commandLine(value: string) {
if (typeof value !== 'string') {
throw illegalArgument('commandLine');
}
this._commandLine = value;
}
get options(): vscode.ShellExecutionOptions {
return this._options;
}
set options(value: vscode.ShellExecutionOptions) {
this._options = value;
}
}
export class Task implements vscode.Task {
private _kind: vscode.TaskKind;
private _kindKey: string;
private _name: string;
private _execution: ProcessExecution | ShellExecution;
private _problemMatchers: string[];
private _identifier: vscode.TaskIdentifier;
private _identifierKey: string;
private _isBackground: boolean;
private _source: string;
private _group: string;
private _group: TaskGroup;
private _presentationOptions: vscode.TaskPresentationOptions;
constructor(identifier: vscode.TaskIdentifier, name: string, problemMatchers: string[]) {
this.identifier = identifier;
constructor(kind: vscode.TaskKind, name: string);
constructor(kind: vscode.TaskKind, name: string, execution: ProcessExecution | ShellExecution);
constructor(kind: vscode.TaskKind, name: string, execution: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(kind: vscode.TaskKind, name: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string[]) {
this.kind = kind;
this.name = name;
this.execution = execution;
this._problemMatchers = problemMatchers || [];
this._isBackground = false;
this._presentationOptions = Object.create(null);
}
get identifier(): vscode.TaskIdentifier {
return this._identifier;
get kind(): vscode.TaskKind {
return this._kind;
}
set identifier(value: vscode.TaskIdentifier) {
set kind(value: vscode.TaskKind) {
if (value === void 0 || value === null) {
throw illegalArgument('Identifier can\'t be undefined or null');
throw illegalArgument('Kind can\'t be undefined or null');
}
this._identifierKey = undefined;
this._identifier = value;
this._kindKey = undefined;
this._kind = value;
}
get identifierKey(): string {
if (!this._identifierKey) {
get kindKey(): string {
if (!this._kindKey) {
const hash = crypto.createHash('md5');
hash.update(JSON.stringify(this._identifier));
this._identifierKey = hash.digest('hex');
hash.update(JSON.stringify(this._kind));
this._kindKey = hash.digest('hex');
}
return this._identifierKey;
return this._kindKey;
}
get name(): string {
@@ -1098,6 +1208,28 @@ export class BaseTask {
this._name = value;
}
get execution(): ProcessExecution | ShellExecution {
return this._execution;
}
set execution(value: ProcessExecution | ShellExecution) {
if (value === null) {
value = undefined;
}
this._execution = value;
}
get problemMatchers(): string[] {
return this._problemMatchers;
}
set problemMatchers(value: string[]) {
if (!Array.isArray(value)) {
value = [];
}
this._problemMatchers = value;
}
get isBackground(): boolean {
return this._isBackground;
}
@@ -1124,18 +1256,15 @@ export class BaseTask {
this._source = value;
}
get group(): string {
get group(): TaskGroup {
return this._group;
}
set group(value: string) {
set group(value: TaskGroup) {
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;
}
@@ -1144,176 +1273,13 @@ export class BaseTask {
}
set presentationOptions(value: vscode.TaskPresentationOptions) {
if (value === void 0 || value === null) {
value = Object.create(null);
if (value === null) {
value = undefined;
}
this._presentationOptions = value;
}
get problemMatchers(): string[] {
return this._problemMatchers;
}
set problemMatchers(value: string[]) {
if (!Array.isArray(value)) {
value = [];
}
this._problemMatchers = value;
}
}
/*
namespace ProblemMatcher {
export function is(value: any): value is vscode.ProblemMatcher {
let candidate: vscode.ProblemMatcher = value;
return candidate && !!candidate.pattern;
}
}
*/
namespace ShellOptions {
export function is(value: any): value is vscode.ShellTaskOptions {
return value && ((typeof value.executable === 'string') || (typeof value.cwd === 'string') || !!value.env);
}
}
export namespace TaskGroup {
/**
* The clean task group
*/
export const Clean: 'clean' = 'clean';
/**
* The build task group
*/
export const Build: 'build' = 'build';
/**
* The rebuild all task group
*/
export const RebuildAll: 'rebuildAll' = 'rebuildAll';
/**
* The test task group
*/
export const Test: 'test' = 'test';
export function is(value: string): value is string {
return value === Clean || value === Build || value === RebuildAll || value === Test;
}
}
export class ProcessTask extends BaseTask {
private _process: string;
private _args: string[];
private _options: vscode.ProcessTaskOptions;
constructor(identifier: vscode.TaskIdentifier, name: string, process: string, args?: string[], problemMatchers?: string | string[]);
constructor(identifier: vscode.TaskIdentifier, name: string, process: string, args: string[] | undefined, options: vscode.ProcessTaskOptions, problemMatchers?: string | string[]);
constructor(identifier: vscode.TaskIdentifier, name: string, process: string, varg1?: string[], varg2?: vscode.ProcessTaskOptions | string | string[], varg3?: string | string[]) {
if (typeof process !== 'string') {
throw illegalArgument('process');
}
let args: string[];
let options: vscode.ProcessTaskOptions;
let problemMatchers: string | string[];
args = varg1 || [];
if (varg2) {
if (Array.isArray(varg2) || typeof varg2 === 'string') {
problemMatchers = varg2;
} else {
options = varg2;
}
}
if (varg3 && !problemMatchers) {
problemMatchers = varg3;
}
let pm: string[];
if (problemMatchers && (typeof problemMatchers === 'string')) {
pm = [problemMatchers];
} else if (Array.isArray(problemMatchers)) {
pm = problemMatchers;
}
pm = pm || [];
super(identifier, name, pm);
this._process = process;
this._args = args;
this._options = options || Object.create(null);
}
get process(): string {
return this._process;
}
get args(): string[] {
return this._args;
}
set args(value: string[]) {
if (!Array.isArray(value)) {
value = [];
}
this._args = value;
}
get options(): vscode.ProcessTaskOptions {
return this._options;
}
set options(value: vscode.ProcessTaskOptions) {
if (value === void 0 || value === null) {
value = Object.create(null);
}
this._options = value;
}
}
export class ShellTask extends BaseTask implements vscode.ShellTask {
private _commandLine: string;
private _options: vscode.ShellTaskOptions;
constructor(identifier: vscode.TaskIdentifier, name: string, commandLine: string, problemMatchers?: string | string[]);
constructor(identifier: vscode.TaskIdentifier, name: string, commandLine: string, options: vscode.ShellTaskOptions, problemMatchers?: string | string[]);
constructor(identifier: vscode.TaskIdentifier, name: string, commandLine: string, optionsOrProblemMatchers?: vscode.ShellTaskOptions | string | string[], problemMatchers?: string | string[]) {
if (typeof commandLine !== 'string') {
throw illegalArgument('commandLine');
}
let options: vscode.ShellTaskOptions = undefined;
let pm: string[];
if (ShellOptions.is(optionsOrProblemMatchers)) {
options = optionsOrProblemMatchers;
} else {
problemMatchers = optionsOrProblemMatchers;
}
if (problemMatchers && (typeof problemMatchers === 'string')) {
pm = [problemMatchers];
} else if (Array.isArray(problemMatchers)) {
pm = problemMatchers;
}
pm = pm || [];
super(identifier, name, pm);
this._commandLine = commandLine;
this._options = options || Object.create(null);
}
get commandLine(): string {
return this._commandLine;
}
get options(): vscode.ShellTaskOptions {
return this._options;
}
set options(value: vscode.ShellTaskOptions) {
if (value === void 0 || value === null) {
value = Object.create(null);
}
this._options = value;
}
}
export enum ProgressLocation {
SourceControl = 1,