提交 63f9e09b 编写于 作者: D Dirk Bäumer

Strict null checks for Task in extHostTypes

上级 f6f4f80c
......@@ -549,6 +549,7 @@
"./vs/vscode.d.ts",
"./vs/vscode.proposed.d.ts",
"./vs/workbench/api/node/extHostExtensionActivator.ts",
"./vs/workbench/api/node/extHostTypes.ts",
"./vs/workbench/api/shared/tasks.ts",
"./vs/workbench/browser/actions/toggleActivityBarVisibility.ts",
"./vs/workbench/browser/actions/toggleCenteredLayout.ts",
......
......@@ -5017,7 +5017,7 @@ declare module 'vscode' {
* Creates a new task.
*
* @param definition The task definition as defined in the taskDefinitions extension point.
* @param target Specifies the task's target. It is either a global or a workspace task or a task for a specific workspace folder.
* @param scope Specifies the task's scope. It is either a global or a workspace task or a task for a specific workspace folder.
* @param name The task's name. Is presented in the user interface.
* @param source The task's source (e.g. 'gulp', 'npm', ...). Is presented in the user interface.
* @param execution The process or shell execution.
......@@ -5025,12 +5025,12 @@ declare module 'vscode' {
* or '$eslint'. Problem matchers can be contributed by an extension using
* the `problemMatchers` extension point.
*/
constructor(taskDefinition: TaskDefinition, target: WorkspaceFolder | TaskScope.Global | TaskScope.Workspace, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(taskDefinition: TaskDefinition, scope: WorkspaceFolder | TaskScope.Global | TaskScope.Workspace, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
/**
* ~~Creates a new task.~~
*
* @deprecated Use the new constructors that allow specifying a target for the task.
* @deprecated Use the new constructors that allow specifying a scope for the task.
*
* @param definition The task definition as defined in the taskDefinitions extension point.
* @param name The task's name. Is presented in the user interface.
......@@ -5050,7 +5050,7 @@ declare module 'vscode' {
/**
* The task's scope.
*/
scope?: TaskScope.Global | TaskScope.Workspace | WorkspaceFolder;
readonly scope?: TaskScope.Global | TaskScope.Workspace | WorkspaceFolder;
/**
* The task's name
......@@ -5060,7 +5060,7 @@ declare module 'vscode' {
/**
* The task's execution engine
*/
execution: ProcessExecution | ShellExecution;
execution?: ProcessExecution | ShellExecution;
/**
* Whether the task is a background task or not.
......
......@@ -1264,7 +1264,7 @@ declare module 'vscode' {
*/
export class Task2 extends Task {
/**
* Run options for the task
* Run options for the task. Defaults to an empty literal.
*/
runOptions: RunOptions;
}
......
......@@ -1427,7 +1427,7 @@ export class ProcessExecution implements vscode.ProcessExecution {
private _process: string;
private _args: string[];
private _options: vscode.ProcessExecutionOptions;
private _options: vscode.ProcessExecutionOptions | undefined;
constructor(process: string, options?: vscode.ProcessExecutionOptions);
constructor(process: string, args: string[], options?: vscode.ProcessExecutionOptions);
......@@ -1472,11 +1472,11 @@ export class ProcessExecution implements vscode.ProcessExecution {
this._args = value;
}
get options(): vscode.ProcessExecutionOptions {
get options(): vscode.ProcessExecutionOptions | undefined {
return this._options;
}
set options(value: vscode.ProcessExecutionOptions) {
set options(value: vscode.ProcessExecutionOptions | undefined) {
this._options = value;
}
......@@ -1500,7 +1500,7 @@ export class ShellExecution implements vscode.ShellExecution {
private _commandLine: string;
private _command: string | vscode.ShellQuotedString;
private _args: (string | vscode.ShellQuotedString)[];
private _options: vscode.ShellExecutionOptions;
private _options: vscode.ShellExecutionOptions | undefined;
constructor(commandLine: string, options?: vscode.ShellExecutionOptions);
constructor(command: string | vscode.ShellQuotedString, args: (string | vscode.ShellQuotedString)[], options?: vscode.ShellExecutionOptions);
......@@ -1554,11 +1554,11 @@ export class ShellExecution implements vscode.ShellExecution {
this._args = value || [];
}
get options(): vscode.ShellExecutionOptions {
get options(): vscode.ShellExecutionOptions | undefined {
return this._options;
}
set options(value: vscode.ShellExecutionOptions) {
set options(value: vscode.ShellExecutionOptions | undefined) {
this._options = value;
}
......@@ -1598,17 +1598,21 @@ export enum RerunBehavior {
export class Task implements vscode.Task2 {
private __id: string;
private static ProcessType: string = 'process';
private static ShellType: string = 'shell';
private static EmptyType: string = '$empty';
private __id: string | undefined;
private _definition: vscode.TaskDefinition;
private _scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder;
private _scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined;
private _name: string;
private _execution: ProcessExecution | ShellExecution;
private _execution: ProcessExecution | ShellExecution | undefined;
private _problemMatchers: string[];
private _hasDefinedMatchers: boolean;
private _isBackground: boolean;
private _source: string;
private _group: TaskGroup;
private _group: TaskGroup | undefined;
private _presentationOptions: vscode.TaskPresentationOptions;
private _runOptions: vscode.RunOptions;
......@@ -1646,13 +1650,15 @@ export class Task implements vscode.Task2 {
this._hasDefinedMatchers = false;
}
this._isBackground = false;
this._presentationOptions = Object.create(null);
this._runOptions = Object.create(null);
}
get _id(): string {
get _id(): string | undefined {
return this.__id;
}
set _id(value: string) {
set _id(value: string | undefined) {
this.__id = value;
}
......@@ -1662,17 +1668,25 @@ export class Task implements vscode.Task2 {
}
this.__id = undefined;
this._scope = undefined;
this._definition = undefined;
this.computeDefinitionBasedOnExecution();
}
private computeDefinitionBasedOnExecution(): void {
if (this._execution instanceof ProcessExecution) {
this._definition = {
type: 'process',
type: Task.ProcessType,
id: this._execution.computeId()
};
} else if (this._execution instanceof ShellExecution) {
this._definition = {
type: 'shell',
type: Task.ShellType,
id: this._execution.computeId()
};
} else {
this._definition = {
type: Task.EmptyType,
id: generateUuid()
};
}
}
......@@ -1688,7 +1702,7 @@ export class Task implements vscode.Task2 {
this._definition = value;
}
get scope(): vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder {
get scope(): vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined {
return this._scope;
}
......@@ -1709,16 +1723,20 @@ export class Task implements vscode.Task2 {
this._name = value;
}
get execution(): ProcessExecution | ShellExecution {
get execution(): ProcessExecution | ShellExecution | undefined {
return this._execution;
}
set execution(value: ProcessExecution | ShellExecution) {
set execution(value: ProcessExecution | ShellExecution | undefined) {
if (value === null) {
value = undefined;
}
this.clear();
this._execution = value;
let type = this._definition.type;
if (Task.EmptyType === type || Task.ProcessType === type || Task.ShellType === type) {
this.computeDefinitionBasedOnExecution();
}
}
get problemMatchers(): string[] {
......@@ -1727,13 +1745,15 @@ export class Task implements vscode.Task2 {
set problemMatchers(value: string[]) {
if (!Array.isArray(value)) {
this.clear();
this._problemMatchers = [];
this._hasDefinedMatchers = false;
return;
} else {
this.clear();
this._problemMatchers = value;
this._hasDefinedMatchers = true;
}
this.clear();
this._problemMatchers = value;
this._hasDefinedMatchers = true;
}
get hasDefinedMatchers(): boolean {
......@@ -1764,14 +1784,13 @@ export class Task implements vscode.Task2 {
this._source = value;
}
get group(): TaskGroup {
get group(): TaskGroup | undefined {
return this._group;
}
set group(value: TaskGroup) {
if (value === void 0 || value === null) {
this._group = undefined;
return;
set group(value: TaskGroup | undefined) {
if (value === null) {
value = undefined;
}
this.clear();
this._group = value;
......@@ -1782,8 +1801,8 @@ export class Task implements vscode.Task2 {
}
set presentationOptions(value: vscode.TaskPresentationOptions) {
if (value === null) {
value = undefined;
if (value === null || value === undefined) {
value = Object.create(null);
}
this.clear();
this._presentationOptions = value;
......@@ -1794,8 +1813,8 @@ export class Task implements vscode.Task2 {
}
set runOptions(value: vscode.RunOptions) {
if (value === null) {
value = undefined;
if (value === null || value === undefined) {
value = Object.create(null);
}
this.clear();
this._runOptions = value;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册