respond to comments
This commit is contained in:
parent
e7d2af0d72
commit
e4e969a210
1 changed files with 12 additions and 9 deletions
|
@ -1159,17 +1159,20 @@ namespace ts.formatting {
|
||||||
sourceFile: SourceFile,
|
sourceFile: SourceFile,
|
||||||
position: number,
|
position: number,
|
||||||
onlyMultiLine: boolean,
|
onlyMultiLine: boolean,
|
||||||
precedingToken: Node | null | undefined = findPrecedingToken(position, sourceFile), // tslint:disable-line:no-null-keyword
|
precedingToken?: Node | null, // tslint:disable-line:no-null-keyword
|
||||||
tokenAtPosition = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false),
|
tokenAtPosition = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false),
|
||||||
predicate?: (c: CommentRange) => boolean): CommentRange | undefined {
|
predicate?: (c: CommentRange) => boolean): CommentRange | undefined {
|
||||||
// Considering a fixed position,
|
const tokenStart = tokenAtPosition.getStart(sourceFile);
|
||||||
// - trailing comments are those following and on the same line as the position.
|
if (tokenStart <= position && position < tokenAtPosition.getEnd()) {
|
||||||
// - leading comments are those in the range [position, start of next non-trivia token)
|
return undefined;
|
||||||
// that are not trailing comments of that position.
|
}
|
||||||
//
|
|
||||||
// Note, `node.start` is the start-position of the first comment following the previous
|
if (precedingToken === undefined) {
|
||||||
// token that is not a trailing comment, so the leading and trailing comments of all
|
precedingToken = findPrecedingToken(position, sourceFile);
|
||||||
// tokens contain all comments in a sourcefile disjointly.
|
}
|
||||||
|
|
||||||
|
// Between two consecutive tokens, all comments are either trailing on the former
|
||||||
|
// or leading on the latter (and none are in both lists).
|
||||||
const trailingRangesOfPreviousToken = precedingToken && getTrailingCommentRanges(sourceFile.text, precedingToken.end);
|
const trailingRangesOfPreviousToken = precedingToken && getTrailingCommentRanges(sourceFile.text, precedingToken.end);
|
||||||
const leadingCommentRangesOfNextToken = getLeadingCommentRangesOfNode(tokenAtPosition, sourceFile);
|
const leadingCommentRangesOfNextToken = getLeadingCommentRangesOfNode(tokenAtPosition, sourceFile);
|
||||||
const commentRanges = trailingRangesOfPreviousToken && leadingCommentRangesOfNextToken ?
|
const commentRanges = trailingRangesOfPreviousToken && leadingCommentRangesOfNextToken ?
|
||||||
|
|
Loading…
Reference in a new issue