@@ -107,12 +107,14 @@ namespace ts {
107
107
scanner . setTextPos ( pos ) ;
108
108
while ( pos < end ) {
109
109
const token = scanner . scan ( ) ;
110
- Debug . assert ( token !== SyntaxKind . EndOfFileToken ) ; // Else it would infinitely loop
111
110
const textPos = scanner . getTextPos ( ) ;
112
111
if ( textPos <= end ) {
113
112
nodes . push ( createNode ( token , pos , textPos , this ) ) ;
114
113
}
115
114
pos = textPos ;
115
+ if ( token === SyntaxKind . EndOfFileToken ) {
116
+ break ;
117
+ }
116
118
}
117
119
return pos ;
118
120
}
@@ -1757,17 +1759,20 @@ namespace ts {
1757
1759
function getFormattingEditsAfterKeystroke ( fileName : string , position : number , key : string , options : FormatCodeOptions | FormatCodeSettings ) : TextChange [ ] {
1758
1760
const sourceFile = syntaxTreeCache . getCurrentSourceFile ( fileName ) ;
1759
1761
const settings = toEditorSettings ( options ) ;
1760
- if ( key === "{" ) {
1761
- return formatting . formatOnOpeningCurly ( position , sourceFile , getRuleProvider ( settings ) , settings ) ;
1762
- }
1763
- else if ( key === "}" ) {
1764
- return formatting . formatOnClosingCurly ( position , sourceFile , getRuleProvider ( settings ) , settings ) ;
1765
- }
1766
- else if ( key === ";" ) {
1767
- return formatting . formatOnSemicolon ( position , sourceFile , getRuleProvider ( settings ) , settings ) ;
1768
- }
1769
- else if ( key === "\n" ) {
1770
- return formatting . formatOnEnter ( position , sourceFile , getRuleProvider ( settings ) , settings ) ;
1762
+
1763
+ if ( ! isInComment ( sourceFile , position ) ) {
1764
+ if ( key === "{" ) {
1765
+ return formatting . formatOnOpeningCurly ( position , sourceFile , getRuleProvider ( settings ) , settings ) ;
1766
+ }
1767
+ else if ( key === "}" ) {
1768
+ return formatting . formatOnClosingCurly ( position , sourceFile , getRuleProvider ( settings ) , settings ) ;
1769
+ }
1770
+ else if ( key === ";" ) {
1771
+ return formatting . formatOnSemicolon ( position , sourceFile , getRuleProvider ( settings ) , settings ) ;
1772
+ }
1773
+ else if ( key === "\n" ) {
1774
+ return formatting . formatOnEnter ( position , sourceFile , getRuleProvider ( settings ) , settings ) ;
1775
+ }
1771
1776
}
1772
1777
1773
1778
return [ ] ;
@@ -1826,6 +1831,12 @@ namespace ts {
1826
1831
return true ;
1827
1832
}
1828
1833
1834
+ function getSpanOfEnclosingComment ( fileName : string , position : number , onlyMultiLine : boolean ) {
1835
+ const sourceFile = syntaxTreeCache . getCurrentSourceFile ( fileName ) ;
1836
+ const range = ts . formatting . getRangeOfEnclosingComment ( sourceFile , position , onlyMultiLine ) ;
1837
+ return range && createTextSpanFromRange ( range ) ;
1838
+ }
1839
+
1829
1840
function getTodoComments ( fileName : string , descriptors : TodoCommentDescriptor [ ] ) : TodoComment [ ] {
1830
1841
// Note: while getting todo comments seems like a syntactic operation, we actually
1831
1842
// treat it as a semantic operation here. This is because we expect our host to call
@@ -2050,6 +2061,7 @@ namespace ts {
2050
2061
getFormattingEditsAfterKeystroke,
2051
2062
getDocCommentTemplateAtPosition,
2052
2063
isValidBraceCompletionAtPosition,
2064
+ getSpanOfEnclosingComment,
2053
2065
getCodeFixesAtPosition,
2054
2066
getEmitOutput,
2055
2067
getNonBoundSourceFile,
0 commit comments