Fix Format Selection on JSDoc comments (#42411)

This commit is contained in:
Andrew Branch 2021-02-05 10:37:47 -08:00 committed by GitHub
parent f1583f08a0
commit 79ed041b6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 5 deletions

View File

@ -390,7 +390,8 @@ namespace ts.formatting {
sourceFile));
}
function formatSpanWorker(originalRange: TextRange,
function formatSpanWorker(
originalRange: TextRange,
enclosingNode: Node,
initialIndentation: number,
delta: number,
@ -424,16 +425,20 @@ namespace ts.formatting {
}
if (!formattingScanner.isOnToken()) {
const indentation = SmartIndenter.nodeWillIndentChild(options, enclosingNode, /*child*/ undefined, sourceFile, /*indentByDefault*/ false)
? initialIndentation + options.indentSize!
: initialIndentation;
const leadingTrivia = formattingScanner.getCurrentLeadingTrivia();
if (leadingTrivia) {
indentTriviaItems(leadingTrivia, initialIndentation, /*indentNextTokenOrTrivia*/ false,
indentTriviaItems(leadingTrivia, indentation, /*indentNextTokenOrTrivia*/ false,
item => processRange(item, sourceFile.getLineAndCharacterOfPosition(item.pos), enclosingNode, enclosingNode, /*dynamicIndentation*/ undefined!));
if (options.trimTrailingWhitespace !== false) {
trimTrailingWhitespacesForRemainingRange();
}
}
}
if (options.trimTrailingWhitespace !== false) {
trimTrailingWhitespacesForRemainingRange();
}
return edits;
// local functions

View File

@ -0,0 +1,44 @@
/// <reference path="fourslash.ts" />
//// {
//// /*1*//**
//// * Some doc comment
//// *//*2*/
//// const a = 1;
//// }
////
//// while (true) {
//// /*3*//**
//// * Some doc comment
//// *//*4*/
//// }
format.selection("1", "2");
verify.currentFileContentIs(
`{
/**
* Some doc comment
*/
const a = 1;
}
while (true) {
/**
* Some doc comment
*/
}`);
format.selection("3", "4");
verify.currentFileContentIs(
`{
/**
* Some doc comment
*/
const a = 1;
}
while (true) {
/**
* Some doc comment
*/
}`);