Skip to content

Commit

Permalink
debug: smarter scope id computation so expansion state is more preser…
Browse files Browse the repository at this point in the history
…ved. Also if all collapsed, expand first non expensive scope

fixes #93230
  • Loading branch information
isidorn committed Mar 24, 2020
1 parent 48d4a6b commit c033cea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/vs/workbench/contrib/debug/browser/variablesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ export class VariablesView extends ViewPane {
if (stackFrame) {
const scopes = await stackFrame.getScopes();
// Expand the first scope if it is not expensive and if there is no expansion state (all are collapsed)
if (scopes.every(s => this.tree.getNode(s).collapsed) && scopes.length > 0 && !scopes[0].expensive) {
this.tree.expand(scopes[0]);
if (scopes.every(s => this.tree.getNode(s).collapsed) && scopes.length > 0) {
const toExpand = scopes.filter(s => !s.expensive).shift();
if (toExpand) {
this.tree.expand(toExpand);
}
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/vs/workbench/contrib/debug/common/debugModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,19 @@ export class StackFrame implements IStackFrame {
getScopes(): Promise<IScope[]> {
if (!this.scopes) {
this.scopes = this.thread.session.scopes(this.frameId, this.thread.threadId).then(response => {
return response && response.body && response.body.scopes ?
response.body.scopes.map((rs, index) => new Scope(this, index, 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) : undefined)) : [];
if (!response || !response.body || !response.body.scopes) {
return [];
}

const scopeNameIndexes = new Map<string, number>();
return response.body.scopes.map(rs => {
const previousIndex = scopeNameIndexes.get(rs.name);
const index = typeof previousIndex === 'number' ? previousIndex + 1 : 0;
scopeNameIndexes.set(rs.name, index);
return new Scope(this, index, 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) : undefined);

});
}, err => [new ErrorScope(this, 0, err.message)]);
}

Expand Down

0 comments on commit c033cea

Please sign in to comment.