mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Fix Format Selection on JSDoc comments (#42411)
This commit is contained in:
parent
f1583f08a0
commit
79ed041b6a
@ -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
|
||||
|
||||
44
tests/cases/fourslash/formatSelectionDocCommentInBlock.ts
Normal file
44
tests/cases/fourslash/formatSelectionDocCommentInBlock.ts
Normal 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
|
||||
*/
|
||||
}`);
|
||||
Loading…
x
Reference in New Issue
Block a user