提交 6afc0546 编写于 作者: I isidor

debug: get specific source name

fixes #30686
上级 30cf40c4
......@@ -219,6 +219,7 @@ export interface IStackFrame extends ITreeElement {
readonly source: Source;
getScopes(): TPromise<ReadonlyArray<IScope>>;
getMostSpecificScopes(range: IRange): TPromise<ReadonlyArray<IScope>>;
getSpecificSourceName(): string;
restart(): TPromise<any>;
toString(): string;
openInEditor(editorService: IWorkbenchEditorService, preserveFocus?: boolean, sideBySide?: boolean): TPromise<any>;
......
......@@ -25,6 +25,8 @@ import {
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { mixin } from 'vs/base/common/objects';
import { commonSuffixLength } from 'vs/base/common/strings';
import { sep } from 'vs/base/common/paths';
const MAX_REPL_LENGTH = 10000;
......@@ -360,6 +362,22 @@ export class StackFrame implements IStackFrame {
return this.scopes;
}
public getSpecificSourceName(): string {
const otherSources = this.thread.getCallStack().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(sep, this.source.uri.path.length - suffixLength - 1));
return (from > 0 ? '...' : '') + this.source.uri.path.substr(from);
}
public getMostSpecificScopes(range: IRange): TPromise<IScope[]> {
return this.getScopes().then(scopes => {
scopes = scopes.filter(s => !s.expensive);
......
......@@ -53,7 +53,7 @@ export class Source {
}
public get name() {
return this.raw.name;
return this.raw.name || resources.basenameOrAuthority(this.uri);
}
public get origin() {
......
......@@ -21,9 +21,6 @@ import { IAction, IActionItem } from 'vs/base/common/actions';
import { RestartAction, StopAction, ContinueAction, StepOverAction, StepIntoAction, StepOutAction, PauseAction, RestartFrameAction, TerminateThreadAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { CopyStackTraceAction } from 'vs/workbench/parts/debug/electron-browser/electronDebugActions';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
import { basenameOrAuthority } from 'vs/base/common/resources';
import { TreeResourceNavigator, WorkbenchTree } from 'vs/platform/list/browser/listService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
......@@ -383,7 +380,6 @@ class CallStackRenderer implements IRenderer {
constructor(
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
// noop
}
......@@ -508,7 +504,7 @@ class CallStackRenderer implements IRenderer {
}
data.label.textContent = stackFrame.name;
data.label.title = stackFrame.name;
data.fileName.textContent = getSourceName(stackFrame.source, this.contextService, this.environmentService);
data.fileName.textContent = stackFrame.getSpecificSourceName();
if (stackFrame.range.startLineNumber !== undefined) {
data.lineNumber.textContent = `${stackFrame.range.startLineNumber}`;
if (stackFrame.range.startColumn) {
......@@ -527,7 +523,7 @@ class CallStackRenderer implements IRenderer {
class CallstackAccessibilityProvider implements IAccessibilityProvider {
constructor(@IWorkspaceContextService private contextService: IWorkspaceContextService) {
constructor() {
// noop
}
......@@ -536,17 +532,9 @@ class CallstackAccessibilityProvider implements IAccessibilityProvider {
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", (<StackFrame>element).name, (<StackFrame>element).range.startLineNumber, getSourceName((<StackFrame>element).source, this.contextService));
return nls.localize('stackFrameAriaLabel', "Stack Frame {0} line {1} {2}, callstack, debug", element.name, element.range.startLineNumber, element.getSpecificSourceName());
}
return null;
}
}
function getSourceName(source: Source, contextService: IWorkspaceContextService, environmentService?: IEnvironmentService): string {
if (source.name) {
return source.name;
}
return basenameOrAuthority(source.uri);
}
......@@ -9,6 +9,7 @@ import severity from 'vs/base/common/severity';
import { SimpleReplElement, Model, Session, Expression, RawObjectReplElement, StackFrame, Thread } from 'vs/workbench/parts/debug/common/debugModel';
import * as sinon from 'sinon';
import { MockSession } from 'vs/workbench/parts/debug/test/common/mockDebug';
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
suite('Debug - Model', () => {
let model: Model;
......@@ -366,6 +367,33 @@ suite('Debug - Model', () => {
assert.equal(model.getReplElements().length, 0);
});
test('stack frame get specific source name', () => {
const session = new Session({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, rawSession);
let firstStackFrame: StackFrame;
let secondStackFrame: StackFrame;
const thread = new class extends Thread {
public getCallStack(): StackFrame[] {
return [firstStackFrame, secondStackFrame];
}
}(session, 'mockthread', 1);
const firstSource = new Source({
name: 'internalModule.js',
path: 'a/b/c/d/internalModule.js',
sourceReference: 10,
}, 'aDebugSessionId');
const secondSource = new Source({
name: 'internalModule.js',
path: 'z/x/c/d/internalModule.js',
sourceReference: 11,
}, 'aDebugSessionId');
firstStackFrame = new StackFrame(thread, 1, firstSource, 'app.js', 'normal', { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 10 }, 1);
secondStackFrame = new StackFrame(thread, 1, secondSource, 'app.js', 'normal', { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 10 }, 1);
assert.equal(firstStackFrame.getSpecificSourceName(), '.../b/c/d/internalModule.js');
assert.equal(secondStackFrame.getSpecificSourceName(), '.../x/c/d/internalModule.js');
});
// Repl output
test('repl output', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册