55
66import uri from 'vs/base/common/uri' ;
77import paths = require( 'vs/base/common/paths' ) ;
8+ import { IModel } from 'vs/workbench/parts/debug/common/debug' ;
89
910export 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}
0 commit comments