Skip to content

Commit b590547

Browse files
committed
debug: more async and polish
1 parent 98d4114 commit b590547

5 files changed

Lines changed: 72 additions & 73 deletions

File tree

src/vs/workbench/contrib/debug/browser/debugHover.ts

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class DebugHoverWidget implements IContentWidget {
137137
return this.domNode;
138138
}
139139

140-
showAt(range: Range, focus: boolean): Promise<void> {
140+
async showAt(range: Range, focus: boolean): Promise<void> {
141141
const pos = range.getStartPosition();
142142

143143
const session = this.debugService.getViewModel().focusedSession;
@@ -153,63 +153,64 @@ export class DebugHoverWidget implements IContentWidget {
153153
return Promise.resolve(this.hide());
154154
}
155155

156-
let promise: Promise<IExpression | undefined>;
156+
let expression;
157157
if (session.capabilities.supportsEvaluateForHovers) {
158-
const result = new Expression(matchingExpression);
159-
promise = result.evaluate(session, this.debugService.getViewModel().focusedStackFrame, 'hover').then(() => result);
158+
expression = new Expression(matchingExpression);
159+
await expression.evaluate(session, this.debugService.getViewModel().focusedStackFrame, 'hover');
160160
} else {
161-
promise = this.findExpressionInStackFrame(coalesce(matchingExpression.split('.').map(word => word.trim())));
161+
expression = await this.findExpressionInStackFrame(coalesce(matchingExpression.split('.').map(word => word.trim())));
162162
}
163163

164-
return promise.then(expression => {
165-
if (!expression || (expression instanceof Expression && !expression.available)) {
166-
this.hide();
167-
return undefined;
168-
}
164+
if (!expression || (expression instanceof Expression && !expression.available)) {
165+
this.hide();
166+
return undefined;
167+
}
169168

170-
this.highlightDecorations = this.editor.deltaDecorations(this.highlightDecorations, [{
171-
range: new Range(pos.lineNumber, start, pos.lineNumber, start + matchingExpression.length),
172-
options: DebugHoverWidget._HOVER_HIGHLIGHT_DECORATION_OPTIONS
173-
}]);
169+
this.highlightDecorations = this.editor.deltaDecorations(this.highlightDecorations, [{
170+
range: new Range(pos.lineNumber, start, pos.lineNumber, start + matchingExpression.length),
171+
options: DebugHoverWidget._HOVER_HIGHLIGHT_DECORATION_OPTIONS
172+
}]);
174173

175-
return this.doShow(pos, expression, focus);
176-
});
174+
return this.doShow(pos, expression, focus);
177175
}
178176

179177
private static _HOVER_HIGHLIGHT_DECORATION_OPTIONS = ModelDecorationOptions.register({
180178
className: 'hoverHighlight'
181179
});
182180

183-
private doFindExpression(container: IExpressionContainer, namesToFind: string[]): Promise<IExpression | null> {
181+
private async doFindExpression(container: IExpressionContainer, namesToFind: string[]): Promise<IExpression | null> {
184182
if (!container) {
185183
return Promise.resolve(null);
186184
}
187185

188-
return container.getChildren().then(children => {
189-
// look for our variable in the list. First find the parents of the hovered variable if there are any.
190-
const filtered = children.filter(v => namesToFind[0] === v.name);
191-
if (filtered.length !== 1) {
192-
return null;
193-
}
186+
const children = await container.getChildren();
187+
// look for our variable in the list. First find the parents of the hovered variable if there are any.
188+
const filtered = children.filter(v => namesToFind[0] === v.name);
189+
if (filtered.length !== 1) {
190+
return null;
191+
}
194192

195-
if (namesToFind.length === 1) {
196-
return filtered[0];
197-
} else {
198-
return this.doFindExpression(filtered[0], namesToFind.slice(1));
199-
}
200-
});
193+
if (namesToFind.length === 1) {
194+
return filtered[0];
195+
} else {
196+
return this.doFindExpression(filtered[0], namesToFind.slice(1));
197+
}
201198
}
202199

203-
private findExpressionInStackFrame(namesToFind: string[]): Promise<IExpression | undefined> {
204-
return this.debugService.getViewModel().focusedStackFrame!.getScopes()
205-
.then(scopes => scopes.filter(s => !s.expensive))
206-
.then(scopes => Promise.all(scopes.map(scope => this.doFindExpression(scope, namesToFind))))
207-
.then(coalesce)
208-
// only show if all expressions found have the same value
209-
.then(expressions => (expressions.length > 0 && expressions.every(e => e.value === expressions[0].value)) ? expressions[0] : undefined);
200+
private async findExpressionInStackFrame(namesToFind: string[]): Promise<IExpression | undefined> {
201+
const focusedStackFrame = this.debugService.getViewModel().focusedStackFrame;
202+
if (!focusedStackFrame) {
203+
return undefined;
204+
}
205+
206+
const scopes = await focusedStackFrame.getScopes();
207+
const nonExpensive = scopes.filter(s => !s.expensive);
208+
const expressions = coalesce(await Promise.all(nonExpensive.map(scope => this.doFindExpression(scope, namesToFind))));
209+
// only show if all expressions found have the same value
210+
return expressions.length > 0 && expressions.every(e => e.value === expressions[0].value) ? expressions[0] : undefined;
210211
}
211212

212-
private doShow(position: Position, expression: IExpression, focus: boolean, forceValueHover = false): Promise<void> {
213+
private async doShow(position: Position, expression: IExpression, focus: boolean, forceValueHover = false): Promise<void> {
213214
if (!this.domNode) {
214215
this.create();
215216
}
@@ -239,20 +240,19 @@ export class DebugHoverWidget implements IContentWidget {
239240
this.valueContainer.hidden = true;
240241
this.complexValueContainer.hidden = false;
241242

242-
return this.tree.setInput(expression).then(() => {
243-
this.complexValueTitle.textContent = replaceWhitespace(expression.value);
244-
this.complexValueTitle.title = expression.value;
245-
this.layoutTreeAndContainer();
246-
this.editor.layoutContentWidget(this);
247-
this.scrollbar.scanDomNode();
248-
this.tree.scrollTop = 0;
249-
this.tree.scrollLeft = 0;
243+
await this.tree.setInput(expression);
244+
this.complexValueTitle.textContent = replaceWhitespace(expression.value);
245+
this.complexValueTitle.title = expression.value;
246+
this.layoutTreeAndContainer();
247+
this.editor.layoutContentWidget(this);
248+
this.scrollbar.scanDomNode();
249+
this.tree.scrollTop = 0;
250+
this.tree.scrollLeft = 0;
250251

251-
if (focus) {
252-
this.editor.render();
253-
this.tree.domFocus();
254-
}
255-
});
252+
if (focus) {
253+
this.editor.render();
254+
this.tree.domFocus();
255+
}
256256
}
257257

258258
private layoutTreeAndContainer(): void {

src/vs/workbench/contrib/debug/browser/debugQuickOpen.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ class AddConfigEntry extends QuickOpenEntry {
2121
super(highlights);
2222
}
2323

24-
public getLabel(): string {
24+
getLabel(): string {
2525
return this.label;
2626
}
2727

28-
public getDescription(): string {
28+
getDescription(): string {
2929
return this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ? this.launch.name : '';
3030
}
3131

32-
public getAriaLabel(): string {
32+
getAriaLabel(): string {
3333
return nls.localize('entryAriaLabel', "{0}, debug", this.getLabel());
3434
}
3535

36-
public run(mode: Mode): boolean {
36+
run(mode: Mode): boolean {
3737
if (mode === Mode.PREVIEW) {
3838
return false;
3939
}
@@ -49,19 +49,19 @@ class StartDebugEntry extends QuickOpenEntry {
4949
super(highlights);
5050
}
5151

52-
public getLabel(): string {
52+
getLabel(): string {
5353
return this.configurationName;
5454
}
5555

56-
public getDescription(): string {
56+
getDescription(): string {
5757
return this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ? this.launch.name : '';
5858
}
5959

60-
public getAriaLabel(): string {
60+
getAriaLabel(): string {
6161
return nls.localize('entryAriaLabel', "{0}, debug", this.getLabel());
6262
}
6363

64-
public run(mode: Mode): boolean {
64+
run(mode: Mode): boolean {
6565
if (mode === Mode.PREVIEW || !StartAction.isEnabled(this.debugService)) {
6666
return false;
6767
}
@@ -75,7 +75,7 @@ class StartDebugEntry extends QuickOpenEntry {
7575

7676
export class DebugQuickOpenHandler extends QuickOpenHandler {
7777

78-
public static readonly ID = 'workbench.picker.launch';
78+
static readonly ID = 'workbench.picker.launch';
7979

8080
private autoFocusIndex: number | undefined;
8181

@@ -88,11 +88,11 @@ export class DebugQuickOpenHandler extends QuickOpenHandler {
8888
super();
8989
}
9090

91-
public getAriaLabel(): string {
91+
getAriaLabel(): string {
9292
return nls.localize('debugAriaLabel', "Type a name of a launch configuration to run.");
9393
}
9494

95-
public getResults(input: string, token: CancellationToken): Promise<QuickOpenModel> {
95+
getResults(input: string, token: CancellationToken): Promise<QuickOpenModel> {
9696
const configurations: QuickOpenEntry[] = [];
9797

9898
const configManager = this.debugService.getConfigurationManager();
@@ -122,14 +122,14 @@ export class DebugQuickOpenHandler extends QuickOpenHandler {
122122
return Promise.resolve(new QuickOpenModel(configurations));
123123
}
124124

125-
public getAutoFocus(input: string): IAutoFocus {
125+
getAutoFocus(input: string): IAutoFocus {
126126
return {
127127
autoFocusFirstEntry: !!input,
128128
autoFocusIndex: this.autoFocusIndex
129129
};
130130
}
131131

132-
public getEmptyLabel(searchString: string): string {
132+
getEmptyLabel(searchString: string): string {
133133
if (searchString.length > 0) {
134134
return nls.localize('noConfigurationsMatching', "No debug configurations matching");
135135
}

src/vs/workbench/contrib/debug/common/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export interface IStackFrame extends ITreeElement {
319319
forgetScopes(): void;
320320
restart(): Promise<any>;
321321
toString(): string;
322-
openInEditor(editorService: IEditorService, preserveFocus?: boolean, sideBySide?: boolean): Promise<ITextEditor | null>;
322+
openInEditor(editorService: IEditorService, preserveFocus?: boolean, sideBySide?: boolean): Promise<ITextEditor | undefined>;
323323
equals(other: IStackFrame): boolean;
324324
}
325325

src/vs/workbench/contrib/debug/common/debugModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ export class StackFrame implements IStackFrame {
337337
return sourceToString === UNKNOWN_SOURCE_LABEL ? this.name : `${this.name} (${sourceToString})`;
338338
}
339339

340-
openInEditor(editorService: IEditorService, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Promise<ITextEditor | null> {
341-
return !this.source.available ? Promise.resolve(null) :
340+
openInEditor(editorService: IEditorService, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Promise<ITextEditor | undefined> {
341+
return !this.source.available ? Promise.resolve(undefined) :
342342
this.source.openInEditor(editorService, this.range, preserveFocus, sideBySide, pinned);
343343
}
344344

src/vs/workbench/contrib/debug/common/debugSource.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/
1313
import { Schemas } from 'vs/base/common/network';
1414
import { isUri } from 'vs/workbench/contrib/debug/common/debugUtils';
1515
import { ITextEditor } from 'vs/workbench/common/editor';
16-
import { withUndefinedAsNull } from 'vs/base/common/types';
1716

1817
export const UNKNOWN_SOURCE_LABEL = nls.localize('unknownSource', "Unknown Source");
1918

@@ -32,9 +31,9 @@ export const UNKNOWN_SOURCE_LABEL = nls.localize('unknownSource', "Unknown Sourc
3231

3332
export class Source {
3433

35-
public readonly uri: uri;
36-
public available: boolean;
37-
public raw: DebugProtocol.Source;
34+
readonly uri: uri;
35+
available: boolean;
36+
raw: DebugProtocol.Source;
3837

3938
constructor(raw_: DebugProtocol.Source | undefined, sessionId: string) {
4039
let path: string;
@@ -94,8 +93,8 @@ export class Source {
9493
return this.uri.scheme === DEBUG_SCHEME;
9594
}
9695

97-
openInEditor(editorService: IEditorService, selection: IRange, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Promise<ITextEditor | null> {
98-
return !this.available ? Promise.resolve(null) : editorService.openEditor({
96+
openInEditor(editorService: IEditorService, selection: IRange, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Promise<ITextEditor | undefined> {
97+
return !this.available ? Promise.resolve(undefined) : editorService.openEditor({
9998
resource: this.uri,
10099
description: this.origin,
101100
options: {
@@ -105,7 +104,7 @@ export class Source {
105104
revealInCenterIfOutsideViewport: true,
106105
pinned: pinned || (!preserveFocus && !this.inMemory)
107106
}
108-
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(withUndefinedAsNull);
107+
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP);
109108
}
110109

111110
static getEncodedDebugData(modelUri: uri): { name: string, path: string, sessionId?: string, sourceReference?: number } {

0 commit comments

Comments
 (0)