@@ -985,13 +985,23 @@ module FourSlash {
985
985
return item . parameters [ currentParam ] ;
986
986
}
987
987
988
- public getBreakpointStatementLocation ( pos : number ) {
988
+ private alignmentForExtraInfo = 50 ;
989
+
990
+ public getBreakpointStatementLocation ( pos : number , prefixString : string ) {
989
991
this . taoInvalidReason = 'getBreakpointStatementLocation NYI' ;
990
992
991
993
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 ( ) ) + ")" ;
995
1005
}
996
1006
return resultString ;
997
1007
}
@@ -1003,12 +1013,60 @@ module FourSlash {
1003
1013
"Breakpoint Locations for " + this . activeFile . fileName ,
1004
1014
this . testData . globalOptions [ testOptMetadataNames . baselineFile ] ,
1005
1015
( ) => {
1006
- var fileLength = this . languageServiceShimHost . getScriptSnapshot ( this . activeFile . fileName ) . getLength ( ) ;
1016
+ var fileLineMap = ts . getLineStarts ( this . activeFile . content ) ;
1017
+ var nextLine = 0 ;
1007
1018
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
+ }
1010
1059
}
1060
+ addSpanInfoString ( ) ;
1011
1061
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
+ }
1012
1070
} ,
1013
1071
true /* run immediately */ ) ;
1014
1072
}
@@ -1056,7 +1114,7 @@ module FourSlash {
1056
1114
}
1057
1115
1058
1116
public printBreakpointLocation ( pos : number ) {
1059
- Harness . IO . log ( this . getBreakpointStatementLocation ( pos ) ) ;
1117
+ Harness . IO . log ( "\n**Pos: " + pos + " " + this . getBreakpointStatementLocation ( pos , " " ) ) ;
1060
1118
}
1061
1119
1062
1120
public printBreakpointAtCurrentLocation ( ) {
@@ -1502,7 +1560,7 @@ module FourSlash {
1502
1560
throw new Error ( 'verifyCaretAtMarker failed - expected to be in file "' + pos . fileName + '", but was in file "' + this . activeFile . fileName + '"' ) ;
1503
1561
}
1504
1562
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 ) + ')' ) ;
1506
1564
}
1507
1565
}
1508
1566
@@ -2102,8 +2160,8 @@ module FourSlash {
2102
2160
return this . languageServiceShimHost . positionToZeroBasedLineCol ( this . activeFile . fileName , this . currentCaretPosition ) . line + 1 ;
2103
2161
}
2104
2162
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 ) ;
2107
2165
return 'line ' + ( pos . line + 1 ) + ', col ' + pos . character ;
2108
2166
}
2109
2167
0 commit comments