@@ -1155,9 +1155,11 @@ namespace ts.formatting {
1155
1155
/**
1156
1156
* Gets the indentation level of the multi-line comment enclosing position,
1157
1157
* and a negative value if the position is not in a multi-line comment.
1158
+ *
1159
+ * @param precedingToken Must be the result of `findPrecedingToken(position, sourceFile)`.
1158
1160
*/
1159
- export function getIndentationOfEnclosingMultiLineComment ( sourceFile : SourceFile , position : number , options : EditorSettings ) : number {
1160
- const range = getRangeOfEnclosingComment ( sourceFile , position , /*onlyMultiLine*/ true ) ;
1161
+ export function getIndentationOfEnclosingMultiLineComment ( sourceFile : SourceFile , position : number , precedingToken : Node | undefined , options : EditorSettings ) : number {
1162
+ const range = getRangeOfEnclosingComment ( sourceFile , position , /*onlyMultiLine*/ true , precedingToken || null ) ; // tslint:disable-line:no-null-keyword
1161
1163
if ( range ) {
1162
1164
const commentStart = range . pos ;
1163
1165
const commentLineStart = getLineStartPositionForPosition ( commentStart , sourceFile ) ;
@@ -1167,10 +1169,14 @@ namespace ts.formatting {
1167
1169
return - 1 ;
1168
1170
}
1169
1171
1172
+ /**
1173
+ * @param precedingToken pass `null` if preceding token was already computed and result was `undefined`.
1174
+ */
1170
1175
export function getRangeOfEnclosingComment (
1171
1176
sourceFile : SourceFile ,
1172
1177
position : number ,
1173
1178
onlyMultiLine : boolean ,
1179
+ precedingToken : Node | null | undefined = findPrecedingToken ( position , sourceFile ) , // tslint:disable-line:no-null-keyword
1174
1180
tokenAtPosition = getTokenAtPosition ( sourceFile , position , /*includeJsDocComment*/ false ) ,
1175
1181
predicate ?: ( c : CommentRange ) => boolean ) : CommentRange | undefined {
1176
1182
// Considering a fixed position,
@@ -1181,7 +1187,6 @@ namespace ts.formatting {
1181
1187
// Note, `node.start` is the start-position of the first comment following the previous
1182
1188
// token that is not a trailing comment, so the leading and trailing comments of all
1183
1189
// tokens contain all comments in a sourcefile disjointly.
1184
- const precedingToken = findPrecedingToken ( position , sourceFile ) ;
1185
1190
const trailingRangesOfPreviousToken = precedingToken && getTrailingCommentRanges ( sourceFile . text , precedingToken . end ) ;
1186
1191
const leadingCommentRangesOfNextToken = getLeadingCommentRangesOfNode ( tokenAtPosition , sourceFile ) ;
1187
1192
const commentRanges = trailingRangesOfPreviousToken && leadingCommentRangesOfNextToken ?
0 commit comments