@@ -985,15 +985,85 @@ module FourSlash {
985
985
return item . parameters [ currentParam ] ;
986
986
}
987
987
988
- public getBreakpointStatementLocation ( pos : number ) {
989
- this . taoInvalidReason = 'getBreakpointStatementLocation NYI' ;
988
+ private alignmentForExtraInfo = 50 ;
989
+
990
+ private spanInfoToString ( pos : number , spanInfo : TypeScript . TextSpan , prefixString : string ) {
991
+ var resultString = "SpanInfo: " + JSON . stringify ( spanInfo ) ;
992
+ if ( spanInfo ) {
993
+ var spanString = this . activeFile . content . substr ( spanInfo . start ( ) , spanInfo . length ( ) ) ;
994
+ var spanLineMap = ts . getLineStarts ( spanString ) ;
995
+ for ( var i = 0 ; i < spanLineMap . length ; i ++ ) {
996
+ if ( ! i ) {
997
+ resultString += "\n" ;
998
+ }
999
+ resultString += prefixString + spanString . substring ( spanLineMap [ i ] , spanLineMap [ i + 1 ] ) ;
1000
+ }
1001
+ resultString += "\n" + prefixString + ":=> (" + this . getLineColStringAtPosition ( spanInfo . start ( ) ) + ") to (" + this . getLineColStringAtPosition ( spanInfo . end ( ) ) + ")" ;
1002
+ }
1003
+
1004
+ return resultString ;
1005
+ }
1006
+
1007
+ private baselineCurrentFileLocations ( getSpanAtPos : ( pos : number ) => TypeScript . TextSpan ) : string {
1008
+ var fileLineMap = ts . getLineStarts ( this . activeFile . content ) ;
1009
+ var nextLine = 0 ;
1010
+ var resultString = "" ;
1011
+ var currentLine : string ;
1012
+ var previousSpanInfo : string ;
1013
+ var startColumn : number ;
1014
+ var length : number ;
1015
+ var prefixString = " >" ;
1016
+
1017
+ var addSpanInfoString = ( ) => {
1018
+ if ( previousSpanInfo ) {
1019
+ resultString += currentLine ;
1020
+ var thisLineMarker = repeatString ( startColumn , " " ) + repeatString ( length , "~" ) ;
1021
+ thisLineMarker += repeatString ( this . alignmentForExtraInfo - thisLineMarker . length - prefixString . length + 1 , " " ) ;
1022
+ resultString += thisLineMarker ;
1023
+ resultString += "=> Pos: (" + ( pos - length ) + " to " + ( pos - 1 ) + ") " ;
1024
+ resultString += " " + previousSpanInfo ;
1025
+ previousSpanInfo = undefined ;
1026
+ }
1027
+ } ;
990
1028
991
- 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 ( ) ) ;
1029
+ for ( var pos = 0 ; pos < this . activeFile . content . length ; pos ++ ) {
1030
+ if ( pos === 0 || pos === fileLineMap [ nextLine ] ) {
1031
+ nextLine ++ ;
1032
+ addSpanInfoString ( ) ;
1033
+ if ( resultString . length ) {
1034
+ resultString += "\n--------------------------------" ;
1035
+ }
1036
+ currentLine = "\n" + nextLine . toString ( ) + repeatString ( 3 - nextLine . toString ( ) . length , " " ) + ">" + this . activeFile . content . substring ( pos , fileLineMap [ nextLine ] ) + "\n " ;
1037
+ startColumn = 0 ;
1038
+ length = 0 ;
1039
+ }
1040
+ var spanInfo = this . spanInfoToString ( pos , getSpanAtPos ( pos ) , prefixString ) ;
1041
+ if ( previousSpanInfo && previousSpanInfo !== spanInfo ) {
1042
+ addSpanInfoString ( ) ;
1043
+ previousSpanInfo = spanInfo ;
1044
+ startColumn = startColumn + length ;
1045
+ length = 1 ;
1046
+ }
1047
+ else {
1048
+ previousSpanInfo = spanInfo ;
1049
+ length ++ ;
1050
+ }
995
1051
}
1052
+ addSpanInfoString ( ) ;
996
1053
return resultString ;
1054
+
1055
+ function repeatString ( count : number , char : string ) {
1056
+ var result = "" ;
1057
+ for ( var i = 0 ; i < count ; i ++ ) {
1058
+ result += char ;
1059
+ }
1060
+ return result ;
1061
+ }
1062
+ }
1063
+
1064
+ public getBreakpointStatementLocation ( pos : number ) {
1065
+ this . taoInvalidReason = 'getBreakpointStatementLocation NYI' ;
1066
+ return this . languageService . getBreakpointStatementAtPosition ( this . activeFile . fileName , pos ) ;
997
1067
}
998
1068
999
1069
public baselineCurrentFileBreakpointLocations ( ) {
@@ -1003,12 +1073,7 @@ module FourSlash {
1003
1073
"Breakpoint Locations for " + this . activeFile . fileName ,
1004
1074
this . testData . globalOptions [ testOptMetadataNames . baselineFile ] ,
1005
1075
( ) => {
1006
- var fileLength = this . languageServiceShimHost . getScriptSnapshot ( this . activeFile . fileName ) . getLength ( ) ;
1007
- var resultString = "" ;
1008
- for ( var pos = 0 ; pos < fileLength ; pos ++ ) {
1009
- resultString = resultString + this . getBreakpointStatementLocation ( pos ) ;
1010
- }
1011
- return resultString ;
1076
+ return this . baselineCurrentFileLocations ( pos => this . getBreakpointStatementLocation ( pos ) ) ;
1012
1077
} ,
1013
1078
true /* run immediately */ ) ;
1014
1079
}
@@ -1056,7 +1121,7 @@ module FourSlash {
1056
1121
}
1057
1122
1058
1123
public printBreakpointLocation ( pos : number ) {
1059
- Harness . IO . log ( this . getBreakpointStatementLocation ( pos ) ) ;
1124
+ Harness . IO . log ( "\n**Pos: " + pos + " " + this . spanInfoToString ( pos , this . getBreakpointStatementLocation ( pos ) , " " ) ) ;
1060
1125
}
1061
1126
1062
1127
public printBreakpointAtCurrentLocation ( ) {
@@ -1502,7 +1567,7 @@ module FourSlash {
1502
1567
throw new Error ( 'verifyCaretAtMarker failed - expected to be in file "' + pos . fileName + '", but was in file "' + this . activeFile . fileName + '"' ) ;
1503
1568
}
1504
1569
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 ( ) + ')' ) ;
1570
+ throw new Error ( 'verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this . currentCaretPosition + '(' + this . getLineColStringAtPosition ( this . currentCaretPosition ) + ')' ) ;
1506
1571
}
1507
1572
}
1508
1573
@@ -1566,10 +1631,10 @@ module FourSlash {
1566
1631
this . taoInvalidReason = 'verifyCurrentNameOrDottedNameSpanText NYI' ;
1567
1632
1568
1633
var span = this . languageService . getNameOrDottedNameSpan ( this . activeFile . fileName , this . currentCaretPosition , this . currentCaretPosition ) ;
1569
- if ( span === null ) {
1634
+ if ( ! span ) {
1570
1635
this . raiseError ( 'verifyCurrentNameOrDottedNameSpanText\n' +
1571
1636
'\tExpected: "' + text + '"\n' +
1572
- '\t Actual: null ' ) ;
1637
+ '\t Actual: undefined ' ) ;
1573
1638
}
1574
1639
1575
1640
var actual = this . languageServiceShimHost . getScriptSnapshot ( this . activeFile . fileName ) . getText ( span . start ( ) , span . end ( ) ) ;
@@ -1581,12 +1646,8 @@ module FourSlash {
1581
1646
}
1582
1647
1583
1648
private getNameOrDottedNameSpan ( pos : number ) {
1584
- var spanInfo = this . languageService . getNameOrDottedNameSpan ( this . activeFile . fileName , pos , pos ) ;
1585
- var resultString = "\n**Pos: " + pos + " SpanInfo: " + JSON . stringify ( spanInfo ) + "\n** Statement: " ;
1586
- if ( spanInfo !== null ) {
1587
- resultString = resultString + this . languageServiceShimHost . getScriptSnapshot ( this . activeFile . fileName ) . getText ( spanInfo . start ( ) , spanInfo . end ( ) ) ;
1588
- }
1589
- return resultString ;
1649
+ this . taoInvalidReason = 'getNameOrDottedNameSpan NYI' ;
1650
+ return this . languageService . getNameOrDottedNameSpan ( this . activeFile . fileName , pos , pos ) ;
1590
1651
}
1591
1652
1592
1653
public baselineCurrentFileNameOrDottedNameSpans ( ) {
@@ -1596,18 +1657,14 @@ module FourSlash {
1596
1657
"Name OrDottedNameSpans for " + this . activeFile . fileName ,
1597
1658
this . testData . globalOptions [ testOptMetadataNames . baselineFile ] ,
1598
1659
( ) => {
1599
- var fileLength = this . languageServiceShimHost . getScriptSnapshot ( this . activeFile . fileName ) . getLength ( ) ;
1600
- var resultString = "" ;
1601
- for ( var pos = 0 ; pos < fileLength ; pos ++ ) {
1602
- resultString = resultString + this . getNameOrDottedNameSpan ( pos ) ;
1603
- }
1604
- return resultString ;
1660
+ return this . baselineCurrentFileLocations ( pos =>
1661
+ this . getNameOrDottedNameSpan ( pos ) ) ;
1605
1662
} ,
1606
1663
true /* run immediately */ ) ;
1607
1664
}
1608
1665
1609
1666
public printNameOrDottedNameSpans ( pos : number ) {
1610
- Harness . IO . log ( this . getNameOrDottedNameSpan ( pos ) ) ;
1667
+ Harness . IO . log ( this . spanInfoToString ( pos , this . getNameOrDottedNameSpan ( pos ) , "**" ) ) ;
1611
1668
}
1612
1669
1613
1670
private verifyClassifications ( expected : { classificationType : string ; text : string ; textSpan ?: TextSpan } [ ] , actual : ts . ClassifiedSpan [ ] ) {
@@ -2114,8 +2171,8 @@ module FourSlash {
2114
2171
return this . languageServiceShimHost . positionToZeroBasedLineCol ( this . activeFile . fileName , this . currentCaretPosition ) . line + 1 ;
2115
2172
}
2116
2173
2117
- private getLineColStringAtCaret ( ) {
2118
- var pos = this . languageServiceShimHost . positionToZeroBasedLineCol ( this . activeFile . fileName , this . currentCaretPosition ) ;
2174
+ private getLineColStringAtPosition ( position : number ) {
2175
+ var pos = this . languageServiceShimHost . positionToZeroBasedLineCol ( this . activeFile . fileName , position ) ;
2119
2176
return 'line ' + ( pos . line + 1 ) + ', col ' + pos . character ;
2120
2177
}
2121
2178
0 commit comments