-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
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.
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); |
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.
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
.
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.
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; |
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.
Any particular reason we changed from 40 to 39?
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.
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(); |
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.
We are calling this on every single node -- we should come up with a way to call this less often.
* 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) ...
Move stuff out of the big stateful closure into their own functions. There are all pure or at most take an
out
array.