提交 ff39ebfa 编写于 作者: I isidor

debug: move getSpecificSourceName to a helper method

上级 af3c79ed
......@@ -41,6 +41,8 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { attachStylerCallback } from 'vs/platform/theme/common/styler';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { commonSuffixLength } from 'vs/base/common/strings';
import { posix } from 'vs/base/common/path';
const $ = dom.$;
......@@ -78,6 +80,26 @@ export function getContextForContributedActions(element: CallStackItem | null):
return '';
}
export function getSpecificSourceName(stackFrame: IStackFrame): string {
// To reduce flashing of the path name and the way we fetch stack frames
// We need to compute the source name based on the other frames in the stale call stack
let callStack = (<Thread>stackFrame.thread).getStaleCallStack();
callStack = callStack.length > 0 ? callStack : stackFrame.thread.getCallStack();
const otherSources = callStack.map(sf => sf.source).filter(s => s !== stackFrame.source);
let suffixLength = 0;
otherSources.forEach(s => {
if (s.name === stackFrame.source.name) {
suffixLength = Math.max(suffixLength, commonSuffixLength(stackFrame.source.uri.path, s.uri.path));
}
});
if (suffixLength === 0) {
return stackFrame.source.name;
}
const from = Math.max(0, stackFrame.source.uri.path.lastIndexOf(posix.sep, stackFrame.source.uri.path.length - suffixLength - 1));
return (from > 0 ? '...' : '') + stackFrame.source.uri.path.substr(from);
}
export class CallStackView extends ViewPane {
private pauseMessage!: HTMLSpanElement;
private pauseMessageLabel!: HTMLSpanElement;
......@@ -582,7 +604,7 @@ class StackFramesRenderer implements ITreeRenderer<IStackFrame, FuzzyScore, ISta
data.file.title += `\n${stackFrame.source.raw.origin}`;
}
data.label.set(stackFrame.name, createMatches(element.filterData), stackFrame.name);
data.fileName.textContent = stackFrame.getSpecificSourceName();
data.fileName.textContent = getSpecificSourceName(stackFrame);
if (stackFrame.range.startLineNumber !== undefined) {
data.lineNumber.textContent = `${stackFrame.range.startLineNumber}`;
if (stackFrame.range.startColumn) {
......@@ -855,7 +877,7 @@ class CallStackAccessibilityProvider implements IListAccessibilityProvider<CallS
return nls.localize('threadAriaLabel', "Thread {0}, callstack, debug", (<Thread>element).name);
}
if (element instanceof StackFrame) {
return nls.localize('stackFrameAriaLabel', "Stack Frame {0}, line {1}, {2}, callstack, debug", element.name, element.range.startLineNumber, element.getSpecificSourceName());
return nls.localize('stackFrameAriaLabel', "Stack Frame {0}, line {1}, {2}, callstack, debug", element.name, element.range.startLineNumber, getSpecificSourceName(element));
}
if (isDebugSession(element)) {
return nls.localize('sessionLabel', "Debug Session {0}", element.getLabel());
......
......@@ -318,7 +318,6 @@ export interface IStackFrame extends ITreeElement {
readonly source: Source;
getScopes(): Promise<IScope[]>;
getMostSpecificScopes(range: IRange): Promise<ReadonlyArray<IScope>>;
getSpecificSourceName(): string;
forgetScopes(): void;
restart(): Promise<any>;
toString(): string;
......
......@@ -17,8 +17,6 @@ import {
IThread, IRawModelUpdate, IScope, IRawStoppedDetails, IEnablement, IBreakpointData, IExceptionInfo, IBreakpointsChangeEvent, IBreakpointUpdateData, IBaseBreakpoint, State, IDataBreakpoint
} from 'vs/workbench/contrib/debug/common/debug';
import { Source, UNKNOWN_SOURCE_LABEL, getUriFromSource } from 'vs/workbench/contrib/debug/common/debugSource';
import { commonSuffixLength } from 'vs/base/common/strings';
import { posix } from 'vs/base/common/path';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { ITextEditorPane } from 'vs/workbench/common/editor';
......@@ -325,26 +323,6 @@ export class StackFrame implements IStackFrame {
return this.scopes;
}
getSpecificSourceName(): string {
// To reduce flashing of the path name and the way we fetch stack frames
// We need to compute the source name based on the other frames in the stale call stack
let callStack = (<Thread>this.thread).getStaleCallStack();
callStack = callStack.length > 0 ? callStack : this.thread.getCallStack();
const otherSources = callStack.map(sf => sf.source).filter(s => s !== this.source);
let suffixLength = 0;
otherSources.forEach(s => {
if (s.name === this.source.name) {
suffixLength = Math.max(suffixLength, commonSuffixLength(this.source.uri.path, s.uri.path));
}
});
if (suffixLength === 0) {
return this.source.name;
}
const from = Math.max(0, this.source.uri.path.lastIndexOf(posix.sep, this.source.uri.path.length - suffixLength - 1));
return (from > 0 ? '...' : '') + this.source.uri.path.substr(from);
}
async getMostSpecificScopes(range: IRange): Promise<IScope[]> {
const scopes = await this.getScopes();
const nonExpensiveScopes = scopes.filter(s => !s.expensive);
......
......@@ -14,7 +14,7 @@ import { IDebugSessionOptions, State } from 'vs/workbench/contrib/debug/common/d
import { NullOpenerService } from 'vs/platform/opener/common/opener';
import { createDecorationsForStackFrame } from 'vs/workbench/contrib/debug/browser/callStackEditorContribution';
import { Constants } from 'vs/base/common/uint';
import { getContext, getContextForContributedActions } from 'vs/workbench/contrib/debug/browser/callStackView';
import { getContext, getContextForContributedActions, getSpecificSourceName } from 'vs/workbench/contrib/debug/browser/callStackView';
import { getStackFrameThreadAndSessionToFocus } from 'vs/workbench/contrib/debug/browser/debugService';
import { generateUuid } from 'vs/base/common/uuid';
......@@ -250,8 +250,8 @@ suite('Debug - CallStack', () => {
model.addSession(session);
const { firstStackFrame, secondStackFrame } = createTwoStackFrames(session);
assert.equal(firstStackFrame.getSpecificSourceName(), '.../b/c/d/internalModule.js');
assert.equal(secondStackFrame.getSpecificSourceName(), '.../x/c/d/internalModule.js');
assert.equal(getSpecificSourceName(firstStackFrame), '.../b/c/d/internalModule.js');
assert.equal(getSpecificSourceName(secondStackFrame), '.../x/c/d/internalModule.js');
});
test('stack frame toString()', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册