Skip to content

Commit

Permalink
Debug hover should use scope information
Browse files Browse the repository at this point in the history
fixes #15172
  • Loading branch information
isidorn committed Nov 11, 2016
1 parent 75fce8b commit 8eed0c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/vs/workbench/parts/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import Event from 'vs/base/common/event';
import severity from 'vs/base/common/severity';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IModel as EditorIModel, IEditorContribution } from 'vs/editor/common/editorCommon';
import { IModel as EditorIModel, IEditorContribution, IRange } from 'vs/editor/common/editorCommon';
import { Position } from 'vs/editor/common/core/position';
import { ISuggestion } from 'vs/editor/common/modes';
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
Expand Down Expand Up @@ -157,6 +157,7 @@ export interface IThread extends ITreeElement {
export interface IScope extends IExpressionContainer {
name: string;
expensive: boolean;
range?: IRange;
}

export interface IStackFrame extends ITreeElement {
Expand Down
8 changes: 6 additions & 2 deletions src/vs/workbench/parts/debug/common/debugModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { clone } from 'vs/base/common/objects';
import severity from 'vs/base/common/severity';
import { isObject, isString } from 'vs/base/common/types';
import { distinct } from 'vs/base/common/arrays';
import { IRange } from 'vs/editor/common/editorCommon';
import { Range } from 'vs/editor/common/core/range';
import { ISuggestion } from 'vs/editor/common/modes';
import { Position } from 'vs/editor/common/core/position';
import * as debug from 'vs/workbench/parts/debug/common/debug';
Expand Down Expand Up @@ -305,7 +307,8 @@ export class Scope extends ExpressionContainer implements debug.IScope {
reference: number,
public expensive: boolean,
namedVariables: number,
indexedVariables: number
indexedVariables: number,
public range?: IRange
) {
super(stackFrame, reference, `scope:${stackFrame.getId()}:${name}:${reference}`, namedVariables, indexedVariables);
}
Expand Down Expand Up @@ -334,7 +337,8 @@ export class StackFrame implements debug.IStackFrame {
if (!this.scopes) {
this.scopes = this.thread.process.session.scopes({ frameId: this.frameId }).then(response => {
return response && response.body && response.body.scopes ?
response.body.scopes.map(rs => new Scope(this, rs.name, rs.variablesReference, rs.expensive, rs.namedVariables, rs.indexedVariables)) : [];
response.body.scopes.map(rs => new Scope(this, rs.name, rs.variablesReference, rs.expensive, rs.namedVariables, rs.indexedVariables,
rs.line && rs.column && rs.endLine && rs.endColumn ? new Range(rs.line, rs.column, rs.endLine, rs.endColumn) : null)) : [];
}, err => []);
}

Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/parts/debug/electron-browser/debugHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class DebugHoverWidget implements IContentWidget {
const result = new Expression(matchingExpression);
promise = result.evaluate(process, focusedStackFrame, 'hover').then(() => result);
} else {
promise = this.findExpressionInStackFrame(matchingExpression.split('.').map(word => word.trim()).filter(word => !!word));
promise = this.findExpressionInStackFrame(matchingExpression.split('.').map(word => word.trim()).filter(word => !!word), expressionRange);
}

return promise.then(expression => {
Expand Down Expand Up @@ -206,10 +206,10 @@ export class DebugHoverWidget implements IContentWidget {
});
}

private findExpressionInStackFrame(namesToFind: string[]): TPromise<IExpression> {
private findExpressionInStackFrame(namesToFind: string[], expressionRange: Range): TPromise<IExpression> {
return this.debugService.getViewModel().focusedStackFrame.getScopes()
// no expensive scopes
.then(scopes => scopes.filter(scope => !scope.expensive))
// no expensive scopes and if a range of scope is defined it needs to contain the variable
.then(scopes => scopes.filter(scope => !scope.expensive && (!scope.range || Range.containsRange(scope.range, expressionRange))))
.then(scopes => TPromise.join(scopes.map(scope => this.doFindExpression(scope, namesToFind))))
.then(expressions => expressions.filter(exp => !!exp))
// only show if all expressions found have the same value
Expand Down

0 comments on commit 8eed0c7

Please sign in to comment.