Skip to content

Commit f802678

Browse files
committed
debug: try to send source reference when possible to adapter.
fixes microsoft#1514
1 parent ba04fe4 commit f802678

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

src/vs/workbench/parts/debug/common/debugSource.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,44 @@
55

66
import uri from 'vs/base/common/uri';
77
import paths = require('vs/base/common/paths');
8+
import { IModel } from 'vs/workbench/parts/debug/common/debug';
89

910
export class Source {
1011

1112
public uri: uri;
12-
public inMemory: boolean;
1313
public available: boolean;
1414

1515
private static INTERNAL_URI_PREFIX = 'debug://internal/';
1616

1717
constructor(public name: string, uriStr: string, public reference = 0) {
1818
this.uri = uri.parse(uriStr);
19-
this.inMemory = uriStr.indexOf(Source.INTERNAL_URI_PREFIX) === 0;
2019
this.available = true;
2120
}
2221

23-
public toRawSource(): DebugProtocol.Source {
24-
return this.inMemory ? { name: this.name } :
25-
{ path: paths.normalize(this.uri.fsPath, true) };
22+
public get inMemory() {
23+
return Source.isInMemory(this.uri);
24+
}
25+
26+
public static toRawSource(uri: uri, model: IModel): DebugProtocol.Source {
27+
// First try to find the raw source amongst the stack frames - since that represenation has more data (source reference),
28+
const threads = model.getThreads();
29+
for (var threadId in threads) {
30+
if (threads.hasOwnProperty(threadId) && threads[threadId].callStack) {
31+
const found = threads[threadId].callStack.filter(sf => sf.source.uri.toString() === uri.toString()).pop();
32+
33+
if (found) {
34+
return {
35+
name: found.source.name,
36+
path: found.source.uri.fsPath,
37+
sourceReference: found.source.reference
38+
}
39+
}
40+
}
41+
}
42+
43+
// Did not find the raw source amongst the stack frames, construct the raw stack frame from the limited data you have.
44+
return Source.isInMemory(uri) ? { name: Source.getName(uri) } :
45+
{ path: paths.normalize(uri.fsPath, true) };
2646
}
2747

2848
public static fromRawSource(rawSource: DebugProtocol.Source): Source {
@@ -31,7 +51,15 @@ export class Source {
3151
}
3252

3353
public static fromUri(uri: uri): Source {
54+
return new Source(Source.getName(uri), uri.toString());
55+
}
56+
57+
private static getName(uri: uri): string {
3458
var uriStr = uri.toString();
35-
return new Source(uriStr.substr(uriStr.lastIndexOf('/') + 1), uriStr);
59+
return uriStr.substr(uriStr.lastIndexOf('/') + 1);
60+
}
61+
62+
private static isInMemory(uri: uri): boolean {
63+
return uri.toString().indexOf(Source.INTERNAL_URI_PREFIX) === 0;
3664
}
3765
}

src/vs/workbench/parts/debug/electron-browser/debugService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,8 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
776776
bp => `${ bp.desiredLineNumber }`
777777
);
778778

779-
return this.session.setBreakpoints({ source: Source.fromUri(modelUri).toRawSource(), lines: breakpointsToSend.map(bp => bp.desiredLineNumber) }).then(response => {
779+
780+
return this.session.setBreakpoints({ source: Source.toRawSource(modelUri, this.model), lines: breakpointsToSend.map(bp => bp.desiredLineNumber) }).then(response => {
780781
const data: {[id: string]: { line: number, verified: boolean } } = { };
781782
for (let i = 0; i < breakpointsToSend.length; i++) {
782783
data[breakpointsToSend[i].getId()] = response.body.breakpoints[i];

0 commit comments

Comments
 (0)