Skip to content

Clean up outliningElementsCollector #20143

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
2 commits merged into from
Nov 21, 2017
Merged

Clean up outliningElementsCollector #20143

2 commits merged into from
Nov 21, 2017

Conversation

ghost
Copy link

@ghost ghost commented Nov 19, 2017

Move stuff out of the big stateful closure into their own functions. There are all pure or at most take an out array.

@ghost ghost requested a review from uniqueiniquity November 19, 2017 18:31
Copy link
Contributor

@uniqueiniquity uniqueiniquity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much needed cleanup, thanks! Just a couple notes.

addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n), /*useFullStart*/ !isArrayLiteralExpression(n.parent));
break;
case SyntaxKind.ModuleBlock:
return spanForNode(n.parent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this not properly find the open and close brace tokens? They're children of the block itself, but we want to pass the parent to createOutliningSpan.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spanForNode closes over n and uses that to find tokens. The argument is hintSpanNode which is only used for its own span, not for its tokens.

return elements.sort((span1, span2) => span1.textSpan.start - span2.textSpan.start);
function addNodeOutliningSpans(sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push<OutliningSpan>): void {
let depth = 0;
const maxDepth = 39;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason we changed from 40 to 39?

Copy link
Author

@ghost ghost Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was fixing an off-by-one error. I pushed a better fix.

let depthRemaining = 40;
sourceFile.forEachChild(function walk(n) {
if (depthRemaining === 0) return;
cancellationToken.throwIfCancellationRequested();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are calling this on every single node -- we should come up with a way to call this less often.

@ghost ghost merged commit 7c5a0ec into master Nov 21, 2017
@ghost ghost deleted the out branch November 21, 2017 19:27
errendir added a commit to errendir/TypeScript that referenced this pull request Nov 27, 2017
* origin/master: (28 commits)
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  Removes redundant comments (microsoft#20214)
  Catch illegal jsdoc tags on constructors (microsoft#20045)
  Use stricter types for event bodies
  Use {} instead of any to improve type checking
  Update public API baseline
  Update project on PackageInstalledResponse
  Unswap arguments
  LEGO: check in for master to temporary branch.
  Fix visibility checking of mutually recursive exports (microsoft#19929)
  Add dt baseline folder to gitignore (microsoft#20205)
  Support getJSDocCommentsAndTags for special property assignments (microsoft#20193)
  Clean up outliningElementsCollector (microsoft#20143)
  Correct project root path passed to Typings Installer
  Check hasOwnProperty before copying property
  Convert legacy safe list keys to lowercase on construction
  Port generated lib files (microsoft#20177)
  Clean up lexical classifier (microsoft#20123)
  Allow curly around `@type` jsdoc to be optional (microsoft#20074)
  ...
@ghost ghost mentioned this pull request Apr 2, 2018
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant