List position based formatting#28340
Merged
DanielRosenwasser merged 11 commits intomicrosoft:masterfrom Nov 9, 2018
Merged
Conversation
... and add explicit delta suppressor for list end tokens
Closed
ghost
reviewed
Nov 8, 2018
| return false; | ||
| } | ||
|
|
||
| function getListIfVisualStartEndIsInListRange(list: NodeArray<Node> | undefined, start: number, end: number, node: Node) { |
There was a problem hiding this comment.
function getListIfVisualStartEndIsInListRange(list: NodeArray<Node> | undefined, start: number, end: number, node: Node, sourceFile: SourceFile): NodeArray<Node> | undefined {
return list && rangeContainsStartEnd(getListRange(node, list, sourceFile), start, end) ? list : undefined;
}
function getListRange(node: Node, list: TextRange, sourceFile: SourceFile): TextRange {
const children = node.getChildren(sourceFile);
for (let i = 1; i < children.length - 1; i++) {
if (children[i].pos === list.pos && children[i].end === list.end) {
return { pos: children[i - 1].end, end: children[i + 1].getStart(sourceFile) };
}
}
return list;
}- Should pass in
sourceFileto some methods for performance. - width = end - start, so end - width = start
- What does "visual" mean here?
Contributor
Author
There was a problem hiding this comment.
NodeArray starts at the previous token's end positions and ends at the last list item's end position. So think about the following code:
func(
// visually the list starts at line 0 and ends in line 2, but actually it ends at line 0
);
func(
1,
// visually the list starts at line 0 and ends in line 3, but actually it ends at line 1
// which means the position of these comments does not belong to the list range.
);
ghost
reviewed
Nov 9, 2018
| switch (node.kind) { | ||
| case SyntaxKind.TypeReference: | ||
| return getListIfVisualStartEndIsInListRange((<TypeReferenceNode>node).typeArguments, start, end, node); | ||
| return getListIfVisualStartEndIsInListRange((<TypeReferenceNode>node).typeArguments, start, end, node, sourceFile); |
There was a problem hiding this comment.
You could create a closure so you don't have to repeat the arguments start, end, node, sourceFile everywhere.
sheetalkamat
approved these changes
Nov 9, 2018
Member
|
I'm pulling this in, and if we'd like to address any changes related to code cleanliness or perf we can do this after. Thank you so much for sticking it out and sending out these changes again. |
Member
|
⭐️ ⭐️ ⭐️ ⭐️ ⭐️ ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Revives #13574
Fixes #5830, fixes #5890, fixes #6252, fixes #6320, fixes #6451, fixes #10681, fixes #26906