Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Preserve newlines from original source when printing nodes from TextChanges #36688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 19, 2020
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2b9e4aa
Allow emitter to write multiple newlines in node lists
andrewbranch Feb 6, 2020
c689617
Progress
andrewbranch Feb 7, 2020
6e272f3
Progress
andrewbranch Feb 7, 2020
839fb8e
Fix recomputeIndentation
andrewbranch Feb 7, 2020
0ea8d79
Add tests, fix leading line terminator count
andrewbranch Feb 7, 2020
6ff9c2b
Do a bit less work when `preserveNewlines` is off
andrewbranch Feb 10, 2020
c91efd4
Fix accidental find/replace rename
andrewbranch Feb 11, 2020
e3ef427
Restore some monomorphism
andrewbranch Feb 19, 2020
e535e27
Fix single line writer
andrewbranch Feb 19, 2020
21b0cb8
Fix other writers
andrewbranch Feb 19, 2020
b6cf73d
Merge branch 'master' into bug/27294
andrewbranch Feb 19, 2020
0c536c5
Revert "Fix other writers"
andrewbranch Feb 19, 2020
91eaf80
Revert "Fix single line writer"
andrewbranch Feb 19, 2020
3be2c86
Revert "Restore some monomorphism"
andrewbranch Feb 19, 2020
8ed98bc
Add equal position optimization to getLinesBetweenRangeEndAndRangeStart
andrewbranch Feb 19, 2020
d9c80fd
Add one more test
andrewbranch Feb 19, 2020
af188d4
Actually save the test file
andrewbranch Feb 19, 2020
19a9728
Rename preserveNewlines to preserveSourceNewlines
andrewbranch Feb 28, 2020
131f2bb
Make ignoreSourceNewlines internal
andrewbranch Feb 28, 2020
34147a5
Optimize lines-between functions
andrewbranch Mar 2, 2020
cf96308
Merge branch 'master' into bug/27294
andrewbranch Mar 2, 2020
075c782
Add comment;
andrewbranch Mar 2, 2020
563d223
Fix trailing line terminator count bug for function parameters
andrewbranch Mar 13, 2020
8b61d66
Preserve newlines around parenthesized expressions
andrewbranch Mar 14, 2020
e7c2b28
Merge branch 'master' into bug/27294
andrewbranch Mar 14, 2020
e99d833
Back to speculative microoptimizations, yay
andrewbranch Mar 16, 2020
ac768d0
Don’t call getEffectiveLines during tsc emit at all
andrewbranch Mar 16, 2020
6daa27e
Merge branch 'master' into bug/27294
andrewbranch Mar 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix recomputeIndentation
  • Loading branch information
andrewbranch committed Feb 7, 2020
commit 839fb8e8c6657b9a22067d38ead2f16d2d320bff
9 changes: 4 additions & 5 deletions src/services/formatting/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,8 @@ namespace ts.formatting {
!suppressDelta && shouldAddDelta(line, kind, container) ? indentation + getDelta(container) : indentation,
getIndentation: () => indentation,
getDelta,
recomputeIndentation: (lineAdded, parentIn) => {
const parent = node.parent || parentIn;
if (node !== parent && SmartIndenter.shouldIndentChildNode(options, parent, node, sourceFile)) {
recomputeIndentation: (lineAdded, parent) => {
if (SmartIndenter.shouldIndentChildNode(options, parent, node, sourceFile)) {
indentation += lineAdded ? options.indentSize! : -options.indentSize!;
delta = SmartIndenter.shouldIndentChildNode(options, node) ? options.indentSize! : 0;
}
Expand Down Expand Up @@ -992,15 +991,15 @@ namespace ts.formatting {
// Handle the case where the next line is moved to be the end of this line.
// In this case we don't indent the next line in the next pass.
if (currentParent.getStart(sourceFile) === currentItem.pos) {
dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ false, currentParent);
dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ false, contextNode);
}
break;
case LineAction.LineAdded:
// Handle the case where token2 is moved to the new line.
// In this case we indent token2 in the next pass but we set
// sameLineIndent flag to notify the indenter that the indentation is within the line.
if (currentParent.getStart(sourceFile) === currentItem.pos) {
dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ true, currentParent);
dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ true, contextNode);
}
break;
default:
Expand Down