feat(42735): add single line comments to selection ranges (#42763)

This commit is contained in:
Oleksandr T
2021-02-12 03:14:55 +02:00
committed by GitHub
parent 475036950e
commit ff5ae3561f
5 changed files with 36 additions and 0 deletions

View File

@@ -13,10 +13,16 @@ namespace ts.SmartSelectionRange {
const prevNode: Node | undefined = children[i - 1];
const node: Node = children[i];
const nextNode: Node | undefined = children[i + 1];
if (getTokenPosOfNode(node, sourceFile, /*includeJsDoc*/ true) > pos) {
break outer;
}
const comment = singleOrUndefined(getTrailingCommentRanges(sourceFile.text, node.end));
if (comment && comment.kind === SyntaxKind.SingleLineCommentTrivia) {
pushSelectionCommentRange(comment.pos, comment.end);
}
if (positionShouldSnapToNode(sourceFile, pos, node)) {
// 1. Blocks are effectively redundant with SyntaxLists.
// 2. TemplateSpans, along with the SyntaxLists containing them, are a somewhat unintuitive grouping
@@ -89,6 +95,16 @@ namespace ts.SmartSelectionRange {
}
}
}
function pushSelectionCommentRange(start: number, end: number): void {
pushSelectionRange(start, end);
let pos = start;
while (sourceFile.text.charCodeAt(pos) === CharacterCodes.slash) {
pos++;
}
pushSelectionRange(pos, end);
}
}
/**