diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 3b090e0b718..e14e51c576e 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -404,6 +404,7 @@ "./vs/workbench/api/electron-browser/mainThreadCommands.ts", "./vs/workbench/api/electron-browser/mainThreadConfiguration.ts", "./vs/workbench/api/electron-browser/mainThreadConsole.ts", + "./vs/workbench/api/electron-browser/mainThreadDebugService.ts", "./vs/workbench/api/electron-browser/mainThreadDiagnostics.ts", "./vs/workbench/api/electron-browser/mainThreadDialogs.ts", "./vs/workbench/api/electron-browser/mainThreadDocumentContentProviders.ts", @@ -414,6 +415,7 @@ "./vs/workbench/api/electron-browser/mainThreadLanguages.ts", "./vs/workbench/api/electron-browser/mainThreadLogService.ts", "./vs/workbench/api/electron-browser/mainThreadMessageService.ts", + "./vs/workbench/api/electron-browser/mainThreadOutputService.ts", "./vs/workbench/api/electron-browser/mainThreadProgress.ts", "./vs/workbench/api/electron-browser/mainThreadQuickOpen.ts", "./vs/workbench/api/electron-browser/mainThreadSCM.ts", diff --git a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts index 287c7320573..80b8a12bc42 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts @@ -141,13 +141,13 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb this.debugService.addFunctionBreakpoint(dto.functionName, dto.id); } } - return undefined; + return Promise.resolve(); } public $unregisterBreakpoints(breakpointIds: string[], functionBreakpointIds: string[]): Promise { breakpointIds.forEach(id => this.debugService.removeBreakpoints(id)); functionBreakpointIds.forEach(id => this.debugService.removeFunctionBreakpoints(id)); - return undefined; + return Promise.resolve(); } @@ -259,20 +259,32 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb } public $acceptDAMessage(handle: number, message: DebugProtocol.ProtocolMessage) { - this._debugAdapters.get(handle).acceptMessage(convertToVSCPaths(message, false)); + this.getDebugAdapter(handle).acceptMessage(convertToVSCPaths(message, false)); } + public $acceptDAError(handle: number, name: string, message: string, stack: string) { - this._debugAdapters.get(handle).fireError(handle, new Error(`${name}: ${message}\n${stack}`)); + this.getDebugAdapter(handle).fireError(handle, new Error(`${name}: ${message}\n${stack}`)); } public $acceptDAExit(handle: number, code: number, signal: string) { - this._debugAdapters.get(handle).fireExit(handle, code, signal); + this.getDebugAdapter(handle).fireExit(handle, code, signal); + } + + private getDebugAdapter(handle: number): ExtensionHostDebugAdapter { + const adapter = this._debugAdapters.get(handle); + if (!adapter) { + throw new Error('Invalid debug adapter'); + } + return adapter; } // dto helpers - getSessionDto(session: IDebugSession): IDebugSessionDto { + getSessionDto(session: undefined): undefined; + getSessionDto(session: IDebugSession): IDebugSessionDto; + getSessionDto(session: IDebugSession | undefined): IDebugSessionDto | undefined; + getSessionDto(session: IDebugSession | undefined): IDebugSessionDto | undefined { if (session) { const sessionID = session.getId(); if (this._sessions.has(sessionID)) { diff --git a/src/vs/workbench/api/electron-browser/mainThreadOutputService.ts b/src/vs/workbench/api/electron-browser/mainThreadOutputService.ts index 6318bbd9559..7f9f642dafd 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadOutputService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadOutputService.ts @@ -38,7 +38,7 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut const setVisibleChannel = () => { const panel = this._panelService.getActivePanel(); - const visibleChannel: IOutputChannel = panel && panel.getId() === OUTPUT_PANEL_ID ? this._outputService.getActiveChannel() : null; + const visibleChannel: IOutputChannel | null = panel && panel.getId() === OUTPUT_PANEL_ID ? this._outputService.getActiveChannel() : null; this._proxy.$setVisibleChannel(visibleChannel ? visibleChannel.id : null); }; this._register(Event.any(this._outputService.onActiveOutputChannel, this._panelService.onDidPanelOpen, this._panelService.onDidPanelClose)(() => setVisibleChannel())); @@ -47,12 +47,12 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut public $register(label: string, log: boolean, file?: UriComponents): Promise { const id = 'extension-output-#' + (MainThreadOutputService._idPool++); - Registry.as(Extensions.OutputChannels).registerChannel({ id, label, file: file ? URI.revive(file) : null, log }); + Registry.as(Extensions.OutputChannels).registerChannel({ id, label, file: file ? URI.revive(file) : undefined, log }); this._register(toDisposable(() => this.$dispose(id))); return Promise.resolve(id); } - public $append(channelId: string, value: string): Promise { + public $append(channelId: string, value: string): Promise | undefined { const channel = this._getChannel(channelId); if (channel) { channel.append(value); @@ -60,7 +60,7 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut return undefined; } - public $update(channelId: string): Promise { + public $update(channelId: string): Promise | undefined { const channel = this._getChannel(channelId); if (channel) { channel.update(); @@ -68,7 +68,7 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut return undefined; } - public $clear(channelId: string, till: number): Promise { + public $clear(channelId: string, till: number): Promise | undefined { const channel = this._getChannel(channelId); if (channel) { channel.clear(till); @@ -76,7 +76,7 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut return undefined; } - public $reveal(channelId: string, preserveFocus: boolean): Promise { + public $reveal(channelId: string, preserveFocus: boolean): Promise | undefined { const channel = this._getChannel(channelId); if (channel) { this._outputService.showChannel(channel.id, preserveFocus); @@ -84,7 +84,7 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut return undefined; } - public $close(channelId: string): Promise { + public $close(channelId: string): Promise | undefined { const panel = this._panelService.getActivePanel(); if (panel && panel.getId() === OUTPUT_PANEL_ID && channelId === this._outputService.getActiveChannel().id) { this._partService.setPanelHidden(true); @@ -93,7 +93,7 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut return undefined; } - public $dispose(channelId: string): Promise { + public $dispose(channelId: string): Promise | undefined { const channel = this._getChannel(channelId); if (channel) { channel.dispose(); diff --git a/src/vs/workbench/api/electron-browser/mainThreadTask.ts b/src/vs/workbench/api/electron-browser/mainThreadTask.ts index 37231f85b42..8637ce0dcad 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadTask.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadTask.ts @@ -74,7 +74,7 @@ namespace TaskDefinitionDTO { delete result._key; return result; } - export function to(value: TaskDefinitionDTO, executeOnly: boolean): KeyedTaskIdentifier { + export function to(value: TaskDefinitionDTO, executeOnly: boolean): KeyedTaskIdentifier | undefined { let result = TaskDefinition.createTaskIdentifier(value, console); if (result === undefined && executeOnly) { result = { @@ -87,13 +87,13 @@ namespace TaskDefinitionDTO { } namespace TaskPresentationOptionsDTO { - export function from(value: PresentationOptions): TaskPresentationOptionsDTO { + export function from(value: PresentationOptions | undefined): TaskPresentationOptionsDTO | undefined { if (value === undefined || value === null) { return undefined; } return Objects.assign(Object.create(null), value); } - export function to(value: TaskPresentationOptionsDTO): PresentationOptions { + export function to(value: TaskPresentationOptionsDTO | undefined): PresentationOptions { if (value === undefined || value === null) { return PresentationOptions.defaults; } @@ -102,13 +102,13 @@ namespace TaskPresentationOptionsDTO { } namespace RunOptionsDTO { - export function from(value: RunOptions): RunOptionsDTO { + export function from(value: RunOptions): RunOptionsDTO | undefined { if (value === undefined || value === null) { return undefined; } return Objects.assign(Object.create(null), value); } - export function to(value: RunOptionsDTO): RunOptions { + export function to(value: RunOptionsDTO | undefined): RunOptions { if (value === undefined || value === null) { return RunOptions.defaults; } @@ -117,7 +117,7 @@ namespace RunOptionsDTO { } namespace ProcessExecutionOptionsDTO { - export function from(value: CommandOptions): ProcessExecutionOptionsDTO { + export function from(value: CommandOptions): ProcessExecutionOptionsDTO | undefined { if (value === undefined || value === null) { return undefined; } @@ -126,7 +126,7 @@ namespace ProcessExecutionOptionsDTO { env: value.env }; } - export function to(value: ProcessExecutionOptionsDTO): CommandOptions { + export function to(value: ProcessExecutionOptionsDTO | undefined): CommandOptions { if (value === undefined || value === null) { return CommandOptions.defaults; } @@ -167,7 +167,7 @@ namespace ProcessExecutionDTO { } namespace ShellExecutionOptionsDTO { - export function from(value: CommandOptions): ShellExecutionOptionsDTO { + export function from(value: CommandOptions): ShellExecutionOptionsDTO | undefined { if (value === undefined || value === null) { return undefined; } @@ -182,7 +182,7 @@ namespace ShellExecutionOptionsDTO { } return result; } - export function to(value: ShellExecutionOptionsDTO): CommandOptions { + export function to(value: ShellExecutionOptionsDTO): CommandOptions | undefined { if (value === undefined || value === null) { return undefined; } @@ -257,7 +257,7 @@ namespace TaskSourceDTO { } export function to(value: TaskSourceDTO, workspace: IWorkspaceContextService): ExtensionTaskSource { let scope: TaskScope; - let workspaceFolder: IWorkspaceFolder; + let workspaceFolder: IWorkspaceFolder | undefined; if ((value.scope === undefined) || ((typeof value.scope === 'number') && (value.scope !== TaskScope.Global))) { if (workspace.getWorkspace().folders.length === 0) { scope = TaskScope.Global; @@ -270,9 +270,9 @@ namespace TaskSourceDTO { scope = value.scope; } else { scope = TaskScope.Folder; - workspaceFolder = workspace.getWorkspaceFolder(URI.revive(value.scope)); + workspaceFolder = workspace.getWorkspaceFolder(URI.revive(value.scope)) || undefined; } - let result: ExtensionTaskSource = { + const result: ExtensionTaskSource = { kind: TaskSourceKind.Extension, label: value.label, extension: value.extensionId, @@ -291,7 +291,7 @@ namespace TaskHandleDTO { } namespace TaskDTO { - export function from(task: Task): TaskDTO { + export function from(task: Task): TaskDTO | undefined { if (task === undefined || task === null || (!CustomTask.is(task) && !ContributedTask.is(task))) { return undefined; } @@ -327,16 +327,19 @@ namespace TaskDTO { return result; } - export function to(task: TaskDTO, workspace: IWorkspaceContextService, executeOnly: boolean): ContributedTask { + export function to(task: TaskDTO, workspace: IWorkspaceContextService, executeOnly: boolean): ContributedTask | undefined { if (typeof task.name !== 'string') { return undefined; } - let command: CommandConfiguration; - if (ShellExecutionDTO.is(task.execution)) { - command = ShellExecutionDTO.to(task.execution); - } else if (ProcessExecutionDTO.is(task.execution)) { - command = ProcessExecutionDTO.to(task.execution); + let command: CommandConfiguration | undefined; + if (task.execution) { + if (ShellExecutionDTO.is(task.execution)) { + command = ShellExecutionDTO.to(task.execution); + } else if (ProcessExecutionDTO.is(task.execution)) { + command = ProcessExecutionDTO.to(task.execution); + } } + if (!command) { return undefined; } @@ -371,7 +374,7 @@ namespace TaskFilterDTO { export function from(value: TaskFilter): TaskFilterDTO { return value; } - export function to(value: TaskFilterDTO): TaskFilter { + export function to(value: TaskFilterDTO | undefined): TaskFilter | undefined { return value; } } @@ -392,13 +395,13 @@ export class MainThreadTask implements MainThreadTaskShape { this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTask); this._providers = new Map(); this._taskService.onDidStateChange((event: TaskEvent) => { - let task = event.__task; + const task = event.__task!; if (event.kind === TaskEventKind.Start) { this._proxy.$onDidStartTask(TaskExecutionDTO.from(task.getTaskExecution())); } else if (event.kind === TaskEventKind.ProcessStarted) { - this._proxy.$onDidStartTaskProcess(TaskProcessStartedDTO.from(task.getTaskExecution(), event.processId)); + this._proxy.$onDidStartTaskProcess(TaskProcessStartedDTO.from(task.getTaskExecution(), event.processId!)); } else if (event.kind === TaskEventKind.ProcessEnded) { - this._proxy.$onDidEndTaskProcess(TaskProcessEndedDTO.from(task.getTaskExecution(), event.exitCode)); + this._proxy.$onDidEndTaskProcess(TaskProcessEndedDTO.from(task.getTaskExecution(), event.exitCode!)); } else if (event.kind === TaskEventKind.End) { this._proxy.$OnDidEndTask(TaskExecutionDTO.from(task.getTaskExecution())); } @@ -534,8 +537,8 @@ export class MainThreadTask implements MainThreadTaskShape { }); return new Promise((resolve, reject) => { this._configurationResolverService.resolveWithInteraction(workspaceFolder, partiallyResolvedVars, 'tasks').then(resolvedVars => { - let result = { - process: undefined as string, + let result: ResolvedVariables = { + process: undefined, variables: new Map() }; for (let i = 0; i < partiallyResolvedVars.length; i++) { diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 3dc5bb08a89..3664541f73f 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -335,12 +335,12 @@ export interface MainThreadMessageServiceShape extends IDisposable { export interface MainThreadOutputServiceShape extends IDisposable { $register(label: string, log: boolean, file?: UriComponents): Promise; - $append(channelId: string, value: string): Promise; - $update(channelId: string): Promise; - $clear(channelId: string, till: number): Promise; - $reveal(channelId: string, preserveFocus: boolean): Promise; - $close(channelId: string): Promise; - $dispose(channelId: string): Promise; + $append(channelId: string, value: string): Promise | undefined; + $update(channelId: string): Promise | undefined; + $clear(channelId: string, till: number): Promise | undefined; + $reveal(channelId: string, preserveFocus: boolean): Promise | undefined; + $close(channelId: string): Promise | undefined; + $dispose(channelId: string): Promise | undefined; } export interface MainThreadProgressShape extends IDisposable { @@ -1036,7 +1036,7 @@ export interface ExtHostDebugServiceShape { $provideDebugAdapter(handle: number, session: IDebugSessionDto): Promise; $acceptDebugSessionStarted(session: IDebugSessionDto): void; $acceptDebugSessionTerminated(session: IDebugSessionDto): void; - $acceptDebugSessionActiveChanged(session: IDebugSessionDto): void; + $acceptDebugSessionActiveChanged(session: IDebugSessionDto | undefined): void; $acceptDebugSessionCustomEvent(session: IDebugSessionDto, event: any): void; $acceptBreakpointsDelta(delta: IBreakpointsDeltaDto): void; } diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index 31a45f7dd27..c8b50085a15 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -601,7 +601,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { } } - public $acceptDebugSessionActiveChanged(sessionDto: IDebugSessionDto): void { + public $acceptDebugSessionActiveChanged(sessionDto: IDebugSessionDto | undefined): void { this._activeDebugSession = sessionDto ? this.getSession(sessionDto) : undefined; this._onDidChangeActiveDebugSession.fire(this._activeDebugSession); diff --git a/src/vs/workbench/api/shared/tasks.ts b/src/vs/workbench/api/shared/tasks.ts index 0a1d3b6535b..e260f14f1f5 100644 --- a/src/vs/workbench/api/shared/tasks.ts +++ b/src/vs/workbench/api/shared/tasks.ts @@ -79,16 +79,16 @@ export interface TaskHandleDTO { export interface TaskDTO { _id: string; - name: string; - execution: ProcessExecutionDTO | ShellExecutionDTO; + name?: string; + execution?: ProcessExecutionDTO | ShellExecutionDTO; definition: TaskDefinitionDTO; - isBackground: boolean; + isBackground?: boolean; source: TaskSourceDTO; group?: string; - presentationOptions: TaskPresentationOptionsDTO; + presentationOptions?: TaskPresentationOptionsDTO; problemMatchers: string[]; hasDefinedMatchers: boolean; - runOptions: RunOptionsDTO; + runOptions?: RunOptionsDTO; } export interface TaskSetDTO { diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index 7a34a6e28f2..5b88039697f 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -586,7 +586,7 @@ export interface IConfigurationManager { getLaunches(): ReadonlyArray; - getLaunch(workspaceUri: uri): ILaunch | undefined; + getLaunch(workspaceUri: uri | undefined): ILaunch | undefined; /** * Allows to register on change of selected debug configuration. @@ -784,7 +784,7 @@ export interface IDebugService { * Returns true if the start debugging was successfull. For compound launches, all configurations have to start successfuly for it to return success. * On errors the startDebugging will throw an error, however some error and cancelations are handled and in that case will simply return false. */ - startDebugging(launch: ILaunch, configOrName?: IConfig | string, noDebug?: boolean): Promise; + startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, noDebug?: boolean): Promise; /** * Restarts a session or creates a new one if there is no active session. diff --git a/src/vs/workbench/contrib/debug/electron-browser/debugConfigurationManager.ts b/src/vs/workbench/contrib/debug/electron-browser/debugConfigurationManager.ts index 4fda9f76074..2503788ccb6 100644 --- a/src/vs/workbench/contrib/debug/electron-browser/debugConfigurationManager.ts +++ b/src/vs/workbench/contrib/debug/electron-browser/debugConfigurationManager.ts @@ -337,7 +337,7 @@ export class ConfigurationManager implements IConfigurationManager { return this.launches; } - public getLaunch(workspaceUri: uri): ILaunch { + public getLaunch(workspaceUri: uri | undefined): ILaunch { if (!uri.isUri(workspaceUri)) { return undefined; } diff --git a/src/vs/workbench/contrib/debug/electron-browser/debugService.ts b/src/vs/workbench/contrib/debug/electron-browser/debugService.ts index 4828acaa6eb..d8ce6c42a77 100644 --- a/src/vs/workbench/contrib/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/electron-browser/debugService.ts @@ -255,7 +255,7 @@ export class DebugService implements IDebugService { * main entry point * properly manages compounds, checks for errors and handles the initializing state. */ - startDebugging(launch: ILaunch, configOrName?: IConfig | string, noDebug = false, unresolvedConfig?: IConfig, ): Promise { + startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, noDebug = false, unresolvedConfig?: IConfig, ): Promise { this.startInitializingState(); // make sure to save all files and that the configuration is up to date diff --git a/src/vs/workbench/contrib/tasks/common/taskService.ts b/src/vs/workbench/contrib/tasks/common/taskService.ts index 48cc70b770c..8e24623e7eb 100644 --- a/src/vs/workbench/contrib/tasks/common/taskService.ts +++ b/src/vs/workbench/contrib/tasks/common/taskService.ts @@ -57,7 +57,7 @@ export interface ITaskService { configureAction(): Action; build(): Promise; runTest(): Promise; - run(task: Task, options?: ProblemMatcherRunOptions): Promise; + run(task: Task | undefined, options?: ProblemMatcherRunOptions): Promise; inTerminal(): boolean; isActive(): Promise; getActiveTasks(): Promise; diff --git a/src/vs/workbench/contrib/tasks/common/tasks.ts b/src/vs/workbench/contrib/tasks/common/tasks.ts index 1b6177ee838..46612113bb6 100644 --- a/src/vs/workbench/contrib/tasks/common/tasks.ts +++ b/src/vs/workbench/contrib/tasks/common/tasks.ts @@ -350,7 +350,7 @@ export interface WorkspaceTaskSource extends BaseTaskSource { export interface ExtensionTaskSource extends BaseTaskSource { readonly kind: 'extension'; - readonly extension: string; + readonly extension?: string; readonly scope: TaskScope; readonly workspaceFolder: IWorkspaceFolder | undefined; } diff --git a/src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts b/src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts index 641dccb3fdb..1260acdd106 100644 --- a/src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts +++ b/src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts @@ -852,7 +852,7 @@ class TaskService extends Disposable implements ITaskService { }); } - public run(task: Task, options?: ProblemMatcherRunOptions): Promise { + public run(task: Task | undefined, options?: ProblemMatcherRunOptions): Promise { return this.getGroupedTasks().then((grouped) => { if (!task) { throw new TaskError(Severity.Info, nls.localize('TaskServer.noTask', 'Requested task {0} to execute not found.', task.configurationProperties.name), TaskErrors.TaskNotFound);