mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-08 18:11:45 -06:00
feat(42735): add single line comments to selection ranges (#42763)
This commit is contained in:
parent
475036950e
commit
ff5ae3561f
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
const a = 1; ///**/comment content
|
||||
|
||||
comment content
|
||||
//comment content
|
||||
const a = 1; //comment content
|
||||
@ -0,0 +1,5 @@
|
||||
const a = 1; //a b/**/c d
|
||||
|
||||
a bc d
|
||||
//a bc d
|
||||
const a = 1; //a bc d
|
||||
5
tests/cases/fourslash/smartSelection_comment1.ts
Normal file
5
tests/cases/fourslash/smartSelection_comment1.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const a = 1; ///**/comment content
|
||||
|
||||
verify.baselineSmartSelection();
|
||||
5
tests/cases/fourslash/smartSelection_comment2.ts
Normal file
5
tests/cases/fourslash/smartSelection_comment2.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const a = 1; //a b/**/c d
|
||||
|
||||
verify.baselineSmartSelection();
|
||||
Loading…
x
Reference in New Issue
Block a user