From 003ff303def9c3ed77b0db1e07176d3da96fbdf7 Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 7 Mar 2019 12:18:22 +0100 Subject: [PATCH] strict null check: debug actions --- src/tsconfig.strictNullChecks.json | 1 + .../contrib/debug/browser/debugActions.ts | 55 +++++++++---------- .../contrib/debug/browser/debugStatus.ts | 4 +- .../workbench/contrib/debug/common/debug.ts | 10 ++-- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index aea73fb7d62..6add3c9f7a9 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -241,6 +241,7 @@ "./vs/workbench/contrib/debug/browser/exceptionWidget.ts", "./vs/workbench/contrib/debug/browser/linkDetector.ts", "./vs/workbench/contrib/debug/browser/baseDebugView.ts", + "./vs/workbench/contrib/debug/browser/debugActions.ts", "./vs/workbench/contrib/debug/browser/statusbarColorProvider.ts", "./vs/workbench/contrib/debug/electron-browser/rawDebugSession.ts", "./vs/workbench/contrib/debug/test/common/debugSource.test.ts", diff --git a/src/vs/workbench/contrib/debug/browser/debugActions.ts b/src/vs/workbench/contrib/debug/browser/debugActions.ts index 4333bd0e20c..85d9fba3f6f 100644 --- a/src/vs/workbench/contrib/debug/browser/debugActions.ts +++ b/src/vs/workbench/contrib/debug/browser/debugActions.ts @@ -7,9 +7,7 @@ import * as nls from 'vs/nls'; import { Action } from 'vs/base/common/actions'; import * as lifecycle from 'vs/base/common/lifecycle'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; -import { ICommandService } from 'vs/platform/commands/common/commands'; import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; -import { IFileService } from 'vs/platform/files/common/files'; import { IDebugService, State, IDebugSession, IThread, IEnablement, IBreakpoint, IStackFrame, REPL_ID } from 'vs/workbench/contrib/debug/common/debug'; import { Variable, Expression, Thread, Breakpoint } from 'vs/workbench/contrib/debug/common/debugModel'; @@ -113,7 +111,7 @@ export class ConfigureAction extends AbstractDebugAction { configurationManager.selectConfiguration(configurationManager.getLaunches()[0]); } - return configurationManager.selectedConfiguration.launch.openConfigFile(sideBySide, false); + return configurationManager.selectedConfiguration.launch!.openConfigFile(sideBySide, false); } } @@ -145,7 +143,7 @@ export class StartAction extends AbstractDebugAction { launch = configurationManager.getLaunch(rootUri); if (!launch || launch.getConfigurationNames().length === 0) { const launches = configurationManager.getLaunches(); - launch = first(launches, l => !!l.getConfigurationNames().length, launch); + launch = first(launches, l => !!(l && l.getConfigurationNames().length), launch); } configurationManager.selectConfiguration(launch); @@ -194,12 +192,9 @@ export class SelectAndStartAction extends AbstractDebugAction { constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService, - @ICommandService commandService: ICommandService, - @IWorkspaceContextService contextService: IWorkspaceContextService, - @IFileService fileService: IFileService, @IQuickOpenService private readonly quickOpenService: IQuickOpenService ) { - super(id, label, undefined, debugService, keybindingService); + super(id, label, '', debugService, keybindingService); } public run(): Promise { @@ -228,11 +223,13 @@ export class RestartAction extends AbstractDebugAction { return new StartAction(StartAction.ID, StartAction.LABEL, this.debugService, this.keybindingService, this.contextService, this.historyService); } - private setLabel(session: IDebugSession): void { - this.updateLabel(session && session.configuration.request === 'attach' ? RestartAction.RECONNECT_LABEL : RestartAction.LABEL); + private setLabel(session: IDebugSession | undefined): void { + if (session) { + this.updateLabel(session && session.configuration.request === 'attach' ? RestartAction.RECONNECT_LABEL : RestartAction.LABEL); + } } - public run(session: IDebugSession): Promise { + public run(session: IDebugSession | undefined): Promise { if (!session || !session.getId) { session = this.debugService.getViewModel().focusedSession; } @@ -262,7 +259,7 @@ export class StepOverAction extends AbstractDebugAction { super(id, label, 'debug-action step-over', debugService, keybindingService, 20); } - public run(thread: IThread): Promise { + public run(thread: IThread | undefined): Promise { if (!(thread instanceof Thread)) { thread = this.debugService.getViewModel().focusedThread; } @@ -283,7 +280,7 @@ export class StepIntoAction extends AbstractDebugAction { super(id, label, 'debug-action step-into', debugService, keybindingService, 30); } - public run(thread: IThread): Promise { + public run(thread: IThread | undefined): Promise { if (!(thread instanceof Thread)) { thread = this.debugService.getViewModel().focusedThread; } @@ -304,7 +301,7 @@ export class StepOutAction extends AbstractDebugAction { super(id, label, 'debug-action step-out', debugService, keybindingService, 40); } - public run(thread: IThread): Promise { + public run(thread: IThread | undefined): Promise { if (!(thread instanceof Thread)) { thread = this.debugService.getViewModel().focusedThread; } @@ -325,7 +322,7 @@ export class StopAction extends AbstractDebugAction { super(id, label, 'debug-action stop', debugService, keybindingService, 80); } - public run(session: IDebugSession): Promise { + public run(session: IDebugSession | undefined): Promise { if (!session || !session.getId) { session = this.debugService.getViewModel().focusedSession; } @@ -364,7 +361,7 @@ export class ContinueAction extends AbstractDebugAction { super(id, label, 'debug-action continue', debugService, keybindingService, 10); } - public run(thread: IThread): Promise { + public run(thread: IThread | undefined): Promise { if (!(thread instanceof Thread)) { thread = this.debugService.getViewModel().focusedThread; } @@ -385,7 +382,7 @@ export class PauseAction extends AbstractDebugAction { super(id, label, 'debug-action pause', debugService, keybindingService, 10); } - public run(thread: IThread): Promise { + public run(thread: IThread | undefined): Promise { if (!(thread instanceof Thread)) { thread = this.debugService.getViewModel().focusedThread; if (!thread) { @@ -408,10 +405,10 @@ export class TerminateThreadAction extends AbstractDebugAction { static LABEL = nls.localize('terminateThread', "Terminate Thread"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, undefined, debugService, keybindingService); + super(id, label, '', debugService, keybindingService); } - public run(thread: IThread): Promise { + public run(thread: IThread | undefined): Promise { if (!(thread instanceof Thread)) { thread = this.debugService.getViewModel().focusedThread; } @@ -429,15 +426,15 @@ export class RestartFrameAction extends AbstractDebugAction { static LABEL = nls.localize('restartFrame', "Restart Frame"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, undefined, debugService, keybindingService); + super(id, label, '', debugService, keybindingService); } - public run(frame: IStackFrame): Promise { + public run(frame: IStackFrame | undefined): Promise { if (!frame) { frame = this.debugService.getViewModel().focusedStackFrame; } - return frame.restart(); + return frame!.restart(); } } @@ -541,7 +538,7 @@ export class ReapplyBreakpointsAction extends AbstractDebugAction { static LABEL = nls.localize('reapplyAllBreakpoints', "Reapply All Breakpoints"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, null, debugService, keybindingService); + super(id, label, '', debugService, keybindingService); this.toDispose.push(this.debugService.getModel().onDidChangeBreakpoints(() => this.updateEnablement())); } @@ -581,7 +578,7 @@ export class SetValueAction extends AbstractDebugAction { static LABEL = nls.localize('setValue', "Set Value"); constructor(id: string, label: string, private variable: Variable, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, null, debugService, keybindingService); + super(id, label, '', debugService, keybindingService); } public run(): Promise { @@ -623,7 +620,7 @@ export class EditWatchExpressionAction extends AbstractDebugAction { static LABEL = nls.localize('editWatchExpression', "Edit Expression"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, undefined, debugService, keybindingService); + super(id, label, '', debugService, keybindingService); } public run(expression: Expression): Promise { @@ -656,7 +653,7 @@ export class RemoveWatchExpressionAction extends AbstractDebugAction { static LABEL = nls.localize('removeWatchExpression', "Remove Expression"); constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { - super(id, label, undefined, debugService, keybindingService); + super(id, label, '', debugService, keybindingService); } public run(expression: Expression): Promise { @@ -740,7 +737,7 @@ export class FocusSessionAction extends AbstractDebugAction { @IKeybindingService keybindingService: IKeybindingService, @IEditorService private readonly editorService: IEditorService ) { - super(id, label, null, debugService, keybindingService, 100); + super(id, label, '', debugService, keybindingService, 100); } public run(sessionName: string): Promise { @@ -764,7 +761,7 @@ export class StepBackAction extends AbstractDebugAction { super(id, label, 'debug-action step-back', debugService, keybindingService, 50); } - public run(thread: IThread): Promise { + public run(thread: IThread | undefined): Promise { if (!(thread instanceof Thread)) { thread = this.debugService.getViewModel().focusedThread; } @@ -787,7 +784,7 @@ export class ReverseContinueAction extends AbstractDebugAction { super(id, label, 'debug-action reverse-continue', debugService, keybindingService, 60); } - public run(thread: IThread): Promise { + public run(thread: IThread | undefined): Promise { if (!(thread instanceof Thread)) { thread = this.debugService.getViewModel().focusedThread; } diff --git a/src/vs/workbench/contrib/debug/browser/debugStatus.ts b/src/vs/workbench/contrib/debug/browser/debugStatus.ts index eb810bf137a..30ecab40456 100644 --- a/src/vs/workbench/contrib/debug/browser/debugStatus.ts +++ b/src/vs/workbench/contrib/debug/browser/debugStatus.ts @@ -89,11 +89,11 @@ export class DebugStatus extends Themable implements IStatusbarItem { private setLabel(): void { if (this.label && this.statusBarItem) { const manager = this.debugService.getConfigurationManager(); - const name = manager.selectedConfiguration.name; + const name = manager.selectedConfiguration.name || ''; const nameAndLaunchPresent = name && manager.selectedConfiguration.launch; dom.toggleClass(this.statusBarItem, 'hidden', this.showInStatusBar === 'never' || !nameAndLaunchPresent); if (nameAndLaunchPresent) { - this.label.textContent = manager.getLaunches().length > 1 ? `${name} (${manager.selectedConfiguration.launch.name})` : name; + this.label.textContent = manager.getLaunches().length > 1 ? `${name} (${manager.selectedConfiguration.launch!.name})` : name; } } } diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index c6e4b73f1f0..156851d8448 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -585,11 +585,11 @@ export interface IConfigurationManager { * Returns an object containing the selected launch configuration and the selected configuration name. Both these fields can be null (no folder workspace). */ readonly selectedConfiguration: { - launch: ILaunch; - name: string; + launch: ILaunch | undefined; + name: string | undefined; }; - selectConfiguration(launch: ILaunch, name?: string, debugStarted?: boolean): void; + selectConfiguration(launch: ILaunch | undefined, name?: string, debugStarted?: boolean): void; getLaunches(): ReadonlyArray; @@ -710,7 +710,7 @@ export interface IDebugService { /** * Sets the focused stack frame and evaluates all expressions against the newly focused stack frame, */ - focusStackFrame(focusedStackFrame: IStackFrame, thread?: IThread, session?: IDebugSession, explicit?: boolean): void; + focusStackFrame(focusedStackFrame: IStackFrame | undefined, thread?: IThread, session?: IDebugSession, explicit?: boolean): void; /** * Adds new breakpoints to the model for the file specified with the uri. Notifies debug adapter of breakpoint changes. @@ -801,7 +801,7 @@ export interface IDebugService { /** * Stops the session. If the session does not exist then stops all sessions. */ - stopSession(session: IDebugSession): Promise; + stopSession(session: IDebugSession | undefined): Promise; /** * Makes unavailable all sources with the passed uri. Source will appear as grayed out in callstack view. -- GitLab