-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Expose indentation suppressor from SmartIndenter #4757
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
Conversation
@@ -282,19 +282,19 @@ namespace ts.formatting { | |||
*/ | |||
function getOwnOrInheritedDelta(n: Node, options: FormatCodeOptions, sourceFile: SourceFile): number { | |||
let previousLine = Constants.Unknown; | |||
let childKind = SyntaxKind.Unknown; | |||
let child: Node = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use undefined
, not null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanielRosenwasser Fixed.
@@ -503,7 +490,7 @@ namespace ts.formatting { | |||
indentation -= options.IndentSize; | |||
} | |||
|
|||
if (SmartIndenter.shouldIndentChildNode(node.kind, SyntaxKind.Unknown)) { | |||
if (SmartIndenter.shouldIndentChildNode(node, null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
not null
Ping @vladima |
@@ -493,9 +480,9 @@ namespace ts.formatting { | |||
} | |||
}, | |||
getIndentation: () => indentation, | |||
getDelta: () => delta, | |||
getDelta: (child) => (delta && SmartIndenter.shouldInheritParentIndentation(node, child)) ? 0 : delta, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to me condition SI.shouldInheritParentIndentation() ? 0 : delta
look more clear and it is doing the same thing.
- if delta is not-null-or-zero then body of
getDelta
boils down toSI.shouldInheritParentIndentation() ? 0 : delta
- if delta zero then
getDelta
evaluates to justdelta
which will mean the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it's doing the same thing. I was to pass the SI check when delta value is already zero but I agree that it looks less clear. Do you want me to fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
} | ||
}, | ||
getIndentation: () => indentation, | ||
getDelta: () => delta, | ||
getDelta: (child) => getEffectiveDelta(delta, child), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove parens around child
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
} | ||
switch (parent) { | ||
|
||
export function nodeWillIndentChild(parent: TextRangeWithKind, child: TextRangeWithKind, indentByDefault: boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be marked as /@internal/
sorry for the delay. Can you add the @internal annotation in your next PR. |
Expose indentation suppressor from SmartIndenter
Separated from #4609.
shouldIndentChildNode
function already have indentation suppressing feature, but currently auto-formatter disables it to get delta value and implements another suppressor incomputeIndentation
function.This PR split the suppressor from
shouldIndentChildNode
and expose it as a separate function so that formatter can use it without implementing its own one.The function will help suppress indentation of:
ImportClause
node inImportDeclaration
node. (Fix named export/import formatting #4609)JsxClosingElement
node. (Fixing JSX/TSX closing tag/attribute/expression formatting #4398)Note:
shouldInheritParentIndentation
and its internalnodeWillIndentChild
receives TextRangeWithKind to check more conditions other than syntax kind.