@@ -985,13 +985,23 @@ module FourSlash {
985985 return item . parameters [ currentParam ] ;
986986 }
987987
988- public getBreakpointStatementLocation ( pos : number ) {
988+ private alignmentForExtraInfo = 50 ;
989+
990+ public getBreakpointStatementLocation ( pos : number , prefixString : string ) {
989991 this . taoInvalidReason = 'getBreakpointStatementLocation NYI' ;
990992
991993 var spanInfo = this . languageService . getBreakpointStatementAtPosition ( this . activeFile . fileName , pos ) ;
992- var resultString = "\n**Pos: " + pos + " SpanInfo: " + JSON . stringify ( spanInfo ) + "\n** Statement: " ;
993- if ( spanInfo !== null ) {
994- resultString = resultString + this . activeFile . content . substr ( spanInfo . start ( ) , spanInfo . length ( ) ) ;
994+ var resultString = "SpanInfo: " + JSON . stringify ( spanInfo ) ;
995+ if ( spanInfo ) {
996+ var spanString = this . activeFile . content . substr ( spanInfo . start ( ) , spanInfo . length ( ) ) ;
997+ var spanLineMap = ts . getLineStarts ( spanString ) ;
998+ for ( var i = 0 ; i < spanLineMap . length ; i ++ ) {
999+ if ( ! i ) {
1000+ resultString += "\n" ;
1001+ }
1002+ resultString += prefixString + spanString . substring ( spanLineMap [ i ] , spanLineMap [ i + 1 ] ) ;
1003+ }
1004+ resultString += "\n" + prefixString + ":=> (" + this . getLineColStringAtPosition ( spanInfo . start ( ) ) + ") to (" + this . getLineColStringAtPosition ( spanInfo . end ( ) ) + ")" ;
9951005 }
9961006 return resultString ;
9971007 }
@@ -1003,12 +1013,60 @@ module FourSlash {
10031013 "Breakpoint Locations for " + this . activeFile . fileName ,
10041014 this . testData . globalOptions [ testOptMetadataNames . baselineFile ] ,
10051015 ( ) => {
1006- var fileLength = this . languageServiceShimHost . getScriptSnapshot ( this . activeFile . fileName ) . getLength ( ) ;
1016+ var fileLineMap = ts . getLineStarts ( this . activeFile . content ) ;
1017+ var nextLine = 0 ;
10071018 var resultString = "" ;
1008- for ( var pos = 0 ; pos < fileLength ; pos ++ ) {
1009- resultString = resultString + this . getBreakpointStatementLocation ( pos ) ;
1019+ var currentLine : string ;
1020+ var previousSpanInfo : string ;
1021+ var startColumn : number ;
1022+ var length : number ;
1023+ var prefixString = " >" ;
1024+
1025+ var addSpanInfoString = ( ) => {
1026+ if ( previousSpanInfo ) {
1027+ resultString += currentLine ;
1028+ var thisLineMarker = repeatString ( startColumn , " " ) + repeatString ( length , "~" ) ;
1029+ thisLineMarker += repeatString ( this . alignmentForExtraInfo - thisLineMarker . length - prefixString . length + 1 , " " ) ;
1030+ resultString += thisLineMarker ;
1031+ resultString += "=> Pos: (" + ( pos - length ) + " to " + ( pos - 1 ) + ") " ;
1032+ resultString += " " + previousSpanInfo ;
1033+ previousSpanInfo = undefined ;
1034+ }
1035+ } ;
1036+
1037+ for ( var pos = 0 ; pos < this . activeFile . content . length ; pos ++ ) {
1038+ if ( pos === 0 || pos === fileLineMap [ nextLine ] ) {
1039+ nextLine ++ ;
1040+ addSpanInfoString ( ) ;
1041+ if ( resultString . length ) {
1042+ resultString += "\n--------------------------------" ;
1043+ }
1044+ currentLine = "\n" + nextLine . toString ( ) + repeatString ( 3 - nextLine . toString ( ) . length , " " ) + ">" + this . activeFile . content . substring ( pos , fileLineMap [ nextLine ] ) + "\n " ;
1045+ startColumn = 0 ;
1046+ length = 0 ;
1047+ }
1048+ var spanInfo = this . getBreakpointStatementLocation ( pos , prefixString ) ;
1049+ if ( previousSpanInfo && previousSpanInfo !== spanInfo ) {
1050+ addSpanInfoString ( ) ;
1051+ previousSpanInfo = spanInfo ;
1052+ startColumn = startColumn + length ;
1053+ length = 1 ;
1054+ }
1055+ else {
1056+ previousSpanInfo = spanInfo ;
1057+ length ++ ;
1058+ }
10101059 }
1060+ addSpanInfoString ( ) ;
10111061 return resultString ;
1062+
1063+ function repeatString ( count : number , char : string ) {
1064+ var result = "" ;
1065+ for ( var i = 0 ; i < count ; i ++ ) {
1066+ result += char ;
1067+ }
1068+ return result ;
1069+ }
10121070 } ,
10131071 true /* run immediately */ ) ;
10141072 }
@@ -1056,7 +1114,7 @@ module FourSlash {
10561114 }
10571115
10581116 public printBreakpointLocation ( pos : number ) {
1059- Harness . IO . log ( this . getBreakpointStatementLocation ( pos ) ) ;
1117+ Harness . IO . log ( "\n**Pos: " + pos + " " + this . getBreakpointStatementLocation ( pos , " " ) ) ;
10601118 }
10611119
10621120 public printBreakpointAtCurrentLocation ( ) {
@@ -1502,7 +1560,7 @@ module FourSlash {
15021560 throw new Error ( 'verifyCaretAtMarker failed - expected to be in file "' + pos . fileName + '", but was in file "' + this . activeFile . fileName + '"' ) ;
15031561 }
15041562 if ( pos . position !== this . currentCaretPosition ) {
1505- throw new Error ( 'verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this . currentCaretPosition + '(' + this . getLineColStringAtCaret ( ) + ')' ) ;
1563+ throw new Error ( 'verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this . currentCaretPosition + '(' + this . getLineColStringAtPosition ( this . currentCaretPosition ) + ')' ) ;
15061564 }
15071565 }
15081566
@@ -2102,8 +2160,8 @@ module FourSlash {
21022160 return this . languageServiceShimHost . positionToZeroBasedLineCol ( this . activeFile . fileName , this . currentCaretPosition ) . line + 1 ;
21032161 }
21042162
2105- private getLineColStringAtCaret ( ) {
2106- var pos = this . languageServiceShimHost . positionToZeroBasedLineCol ( this . activeFile . fileName , this . currentCaretPosition ) ;
2163+ private getLineColStringAtPosition ( position : number ) {
2164+ var pos = this . languageServiceShimHost . positionToZeroBasedLineCol ( this . activeFile . fileName , position ) ;
21072165 return 'line ' + ( pos . line + 1 ) + ', col ' + pos . character ;
21082166 }
21092167
0 commit comments