From c80a7601c79b9421e345caf332ece0ce984a2133 Mon Sep 17 00:00:00 2001 From: isidor Date: Fri, 8 Mar 2019 15:49:05 +0100 Subject: [PATCH] strict null checks: electronDebugActions and variablesView --- src/tsconfig.strictNullChecks.json | 2 ++ .../workbench/contrib/debug/common/debugModel.ts | 2 +- .../electron-browser/electronDebugActions.ts | 11 ++++++----- .../debug/electron-browser/variablesView.ts | 16 +++++++--------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 278f45d075d..b75bed4176a 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -252,7 +252,9 @@ "./vs/workbench/contrib/debug/browser/exceptionWidget.ts", "./vs/workbench/contrib/debug/browser/linkDetector.ts", "./vs/workbench/contrib/debug/browser/statusbarColorProvider.ts", + "./vs/workbench/contrib/debug/electron-browser/electronDebugActions.ts", "./vs/workbench/contrib/debug/electron-browser/rawDebugSession.ts", + "./vs/workbench/contrib/debug/electron-browser/variablesView.ts", "./vs/workbench/contrib/debug/test/common/debugSource.test.ts", "./vs/workbench/contrib/debug/test/common/debugUtils.test.ts", "./vs/workbench/contrib/debug/test/common/mockDebug.ts", diff --git a/src/vs/workbench/contrib/debug/common/debugModel.ts b/src/vs/workbench/contrib/debug/common/debugModel.ts index 0f833db72af..039d7200591 100644 --- a/src/vs/workbench/contrib/debug/common/debugModel.ts +++ b/src/vs/workbench/contrib/debug/common/debugModel.ts @@ -247,7 +247,7 @@ export class Expression extends ExpressionContainer implements IExpression { export class Variable extends ExpressionContainer implements IExpression { // Used to show the error message coming from the adapter when setting the value #7807 - public errorMessage: string; + public errorMessage: string | undefined; constructor( session: IDebugSession | undefined, diff --git a/src/vs/workbench/contrib/debug/electron-browser/electronDebugActions.ts b/src/vs/workbench/contrib/debug/electron-browser/electronDebugActions.ts index a89c54d9a0c..6b504bb0733 100644 --- a/src/vs/workbench/contrib/debug/electron-browser/electronDebugActions.ts +++ b/src/vs/workbench/contrib/debug/electron-browser/electronDebugActions.ts @@ -20,10 +20,11 @@ export class CopyValueAction extends Action { } public run(): Promise { - if (this.value instanceof Variable) { - const frameId = this.debugService.getViewModel().focusedStackFrame.frameId; - const session = this.debugService.getViewModel().focusedSession; - return session.evaluate(this.value.evaluateName, frameId, this.context).then(result => { + const stackFrame = this.debugService.getViewModel().focusedStackFrame; + const session = this.debugService.getViewModel().focusedSession; + + if (this.value instanceof Variable && stackFrame && session && this.value.evaluateName) { + return session.evaluate(this.value.evaluateName, stackFrame.frameId, this.context).then(result => { clipboard.writeText(result.body.result); }, err => clipboard.writeText(this.value.value)); } @@ -43,7 +44,7 @@ export class CopyEvaluatePathAction extends Action { } public run(): Promise { - clipboard.writeText(this.value.evaluateName); + clipboard.writeText(this.value.evaluateName!); return Promise.resolve(undefined); } } diff --git a/src/vs/workbench/contrib/debug/electron-browser/variablesView.ts b/src/vs/workbench/contrib/debug/electron-browser/variablesView.ts index c99a320ece3..01e30d67e58 100644 --- a/src/vs/workbench/contrib/debug/electron-browser/variablesView.ts +++ b/src/vs/workbench/contrib/debug/electron-browser/variablesView.ts @@ -129,14 +129,15 @@ export class VariablesView extends ViewletPanel { private onMouseDblClick(e: ITreeMouseEvent): void { const session = this.debugService.getViewModel().focusedSession; - if (e.element instanceof Variable && session.capabilities.supportsSetVariable) { + if (session && e.element instanceof Variable && session.capabilities.supportsSetVariable) { this.debugService.getViewModel().setSelectedExpression(e.element); } } private onContextMenu(e: ITreeContextMenuEvent): void { const element = e.element; - if (element instanceof Variable && !!element.value) { + const anchor = e.anchor; + if (element instanceof Variable && !!element.value && anchor) { const actions: IAction[] = []; const variable = element as Variable; actions.push(new SetValueAction(SetValueAction.ID, SetValueAction.LABEL, variable, this.debugService, this.keybindingService)); @@ -146,7 +147,7 @@ export class VariablesView extends ViewletPanel { actions.push(new AddToWatchExpressionsAction(AddToWatchExpressionsAction.ID, AddToWatchExpressionsAction.LABEL, variable, this.debugService, this.keybindingService)); this.contextMenuService.showContextMenu({ - getAnchor: () => e.anchor, + getAnchor: () => anchor, getActions: () => actions, getActionsContext: () => element }); @@ -193,11 +194,8 @@ class VariablesDelegate implements IListVirtualDelegate { if (element instanceof Scope) { return ScopesRenderer.ID; } - if (element instanceof Variable) { - return VariablesRenderer.ID; - } - return null; + return VariablesRenderer.ID; } } @@ -246,7 +244,7 @@ export class VariablesRenderer extends AbstractExpressionsRenderer { validation: () => variable.errorMessage ? ({ content: variable.errorMessage }) : null }, onFinish: (value: string, success: boolean) => { - variable.errorMessage = null; + variable.errorMessage = undefined; if (success && variable.value !== value) { variable.setVariable(value) // Need to force watch expressions and variables to update since a variable change can have an effect on both @@ -258,7 +256,7 @@ export class VariablesRenderer extends AbstractExpressionsRenderer { } class VariablesAccessibilityProvider implements IAccessibilityProvider { - getAriaLabel(element: IExpression | IScope): string { + getAriaLabel(element: IExpression | IScope): string | null { if (element instanceof Scope) { return nls.localize('variableScopeAriaLabel', "Scope {0}, variables, debug", element.name); } -- GitLab