Skip to content

Commit ff39ebf

Browse files
committed
debug: move getSpecificSourceName to a helper method
1 parent af3c79e commit ff39ebf

4 files changed

Lines changed: 27 additions & 28 deletions

File tree

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
4141
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4242
import { attachStylerCallback } from 'vs/platform/theme/common/styler';
4343
import { INotificationService } from 'vs/platform/notification/common/notification';
44+
import { commonSuffixLength } from 'vs/base/common/strings';
45+
import { posix } from 'vs/base/common/path';
4446

4547
const $ = dom.$;
4648

@@ -78,6 +80,26 @@ export function getContextForContributedActions(element: CallStackItem | null):
7880
return '';
7981
}
8082

83+
export function getSpecificSourceName(stackFrame: IStackFrame): string {
84+
// To reduce flashing of the path name and the way we fetch stack frames
85+
// We need to compute the source name based on the other frames in the stale call stack
86+
let callStack = (<Thread>stackFrame.thread).getStaleCallStack();
87+
callStack = callStack.length > 0 ? callStack : stackFrame.thread.getCallStack();
88+
const otherSources = callStack.map(sf => sf.source).filter(s => s !== stackFrame.source);
89+
let suffixLength = 0;
90+
otherSources.forEach(s => {
91+
if (s.name === stackFrame.source.name) {
92+
suffixLength = Math.max(suffixLength, commonSuffixLength(stackFrame.source.uri.path, s.uri.path));
93+
}
94+
});
95+
if (suffixLength === 0) {
96+
return stackFrame.source.name;
97+
}
98+
99+
const from = Math.max(0, stackFrame.source.uri.path.lastIndexOf(posix.sep, stackFrame.source.uri.path.length - suffixLength - 1));
100+
return (from > 0 ? '...' : '') + stackFrame.source.uri.path.substr(from);
101+
}
102+
81103
export class CallStackView extends ViewPane {
82104
private pauseMessage!: HTMLSpanElement;
83105
private pauseMessageLabel!: HTMLSpanElement;
@@ -582,7 +604,7 @@ class StackFramesRenderer implements ITreeRenderer<IStackFrame, FuzzyScore, ISta
582604
data.file.title += `\n${stackFrame.source.raw.origin}`;
583605
}
584606
data.label.set(stackFrame.name, createMatches(element.filterData), stackFrame.name);
585-
data.fileName.textContent = stackFrame.getSpecificSourceName();
607+
data.fileName.textContent = getSpecificSourceName(stackFrame);
586608
if (stackFrame.range.startLineNumber !== undefined) {
587609
data.lineNumber.textContent = `${stackFrame.range.startLineNumber}`;
588610
if (stackFrame.range.startColumn) {
@@ -855,7 +877,7 @@ class CallStackAccessibilityProvider implements IListAccessibilityProvider<CallS
855877
return nls.localize('threadAriaLabel', "Thread {0}, callstack, debug", (<Thread>element).name);
856878
}
857879
if (element instanceof StackFrame) {
858-
return nls.localize('stackFrameAriaLabel', "Stack Frame {0}, line {1}, {2}, callstack, debug", element.name, element.range.startLineNumber, element.getSpecificSourceName());
880+
return nls.localize('stackFrameAriaLabel', "Stack Frame {0}, line {1}, {2}, callstack, debug", element.name, element.range.startLineNumber, getSpecificSourceName(element));
859881
}
860882
if (isDebugSession(element)) {
861883
return nls.localize('sessionLabel', "Debug Session {0}", element.getLabel());

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ export interface IStackFrame extends ITreeElement {
318318
readonly source: Source;
319319
getScopes(): Promise<IScope[]>;
320320
getMostSpecificScopes(range: IRange): Promise<ReadonlyArray<IScope>>;
321-
getSpecificSourceName(): string;
322321
forgetScopes(): void;
323322
restart(): Promise<any>;
324323
toString(): string;

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import {
1717
IThread, IRawModelUpdate, IScope, IRawStoppedDetails, IEnablement, IBreakpointData, IExceptionInfo, IBreakpointsChangeEvent, IBreakpointUpdateData, IBaseBreakpoint, State, IDataBreakpoint
1818
} from 'vs/workbench/contrib/debug/common/debug';
1919
import { Source, UNKNOWN_SOURCE_LABEL, getUriFromSource } from 'vs/workbench/contrib/debug/common/debugSource';
20-
import { commonSuffixLength } from 'vs/base/common/strings';
21-
import { posix } from 'vs/base/common/path';
2220
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2321
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
2422
import { ITextEditorPane } from 'vs/workbench/common/editor';
@@ -325,26 +323,6 @@ export class StackFrame implements IStackFrame {
325323
return this.scopes;
326324
}
327325

328-
getSpecificSourceName(): string {
329-
// To reduce flashing of the path name and the way we fetch stack frames
330-
// We need to compute the source name based on the other frames in the stale call stack
331-
let callStack = (<Thread>this.thread).getStaleCallStack();
332-
callStack = callStack.length > 0 ? callStack : this.thread.getCallStack();
333-
const otherSources = callStack.map(sf => sf.source).filter(s => s !== this.source);
334-
let suffixLength = 0;
335-
otherSources.forEach(s => {
336-
if (s.name === this.source.name) {
337-
suffixLength = Math.max(suffixLength, commonSuffixLength(this.source.uri.path, s.uri.path));
338-
}
339-
});
340-
if (suffixLength === 0) {
341-
return this.source.name;
342-
}
343-
344-
const from = Math.max(0, this.source.uri.path.lastIndexOf(posix.sep, this.source.uri.path.length - suffixLength - 1));
345-
return (from > 0 ? '...' : '') + this.source.uri.path.substr(from);
346-
}
347-
348326
async getMostSpecificScopes(range: IRange): Promise<IScope[]> {
349327
const scopes = await this.getScopes();
350328
const nonExpensiveScopes = scopes.filter(s => !s.expensive);

src/vs/workbench/contrib/debug/test/browser/callStack.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IDebugSessionOptions, State } from 'vs/workbench/contrib/debug/common/d
1414
import { NullOpenerService } from 'vs/platform/opener/common/opener';
1515
import { createDecorationsForStackFrame } from 'vs/workbench/contrib/debug/browser/callStackEditorContribution';
1616
import { Constants } from 'vs/base/common/uint';
17-
import { getContext, getContextForContributedActions } from 'vs/workbench/contrib/debug/browser/callStackView';
17+
import { getContext, getContextForContributedActions, getSpecificSourceName } from 'vs/workbench/contrib/debug/browser/callStackView';
1818
import { getStackFrameThreadAndSessionToFocus } from 'vs/workbench/contrib/debug/browser/debugService';
1919
import { generateUuid } from 'vs/base/common/uuid';
2020

@@ -250,8 +250,8 @@ suite('Debug - CallStack', () => {
250250
model.addSession(session);
251251
const { firstStackFrame, secondStackFrame } = createTwoStackFrames(session);
252252

253-
assert.equal(firstStackFrame.getSpecificSourceName(), '.../b/c/d/internalModule.js');
254-
assert.equal(secondStackFrame.getSpecificSourceName(), '.../x/c/d/internalModule.js');
253+
assert.equal(getSpecificSourceName(firstStackFrame), '.../b/c/d/internalModule.js');
254+
assert.equal(getSpecificSourceName(secondStackFrame), '.../x/c/d/internalModule.js');
255255
});
256256

257257
test('stack frame toString()', () => {

0 commit comments

Comments
 (0)