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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}
}
/**

View File

@ -0,0 +1,5 @@
const a = 1; ///**/comment content
comment content
//comment content
const a = 1; //comment content

View File

@ -0,0 +1,5 @@
const a = 1; //a b/**/c d
a bc d
//a bc d
const a = 1; //a bc d

View File

@ -0,0 +1,5 @@
/// <reference path="fourslash.ts" />
////const a = 1; ///**/comment content
verify.baselineSmartSelection();

View File

@ -0,0 +1,5 @@
/// <reference path="fourslash.ts" />
////const a = 1; //a b/**/c d
verify.baselineSmartSelection();