-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Adds floating block comments to the outlining spans response #36880
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
if (sourceFile.statements.length > 0) return; | ||
|
||
// This will instead set up spans for the missing ones | ||
forEach(getLeadingCommentRangesOfNode(sourceFile, sourceFile), (range) => { |
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.
I don't know this code at all, but it seems like this must be similar to the code in addNodeOutliningSpans. Maybe enough to share?
Edit:
Narrator voice It wasn't.
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.
What happens if you have a multiline comment that at the end of a file that does have statements?
console.log(0);
/*
* Does this comment
* get picked up? Should it?
*/
Comments at the end of a file should show up on the EndOfFileToken
child of the source file, so maybe that could just be added to the end of the loop in addNodeOutliningSpans
? If it looped over sourceFile.getChildren()
instead of sourceFile.statements
, would it Just Work™?
…cial casing the EOF token
Great points, I've refactored it to be closer to @andrewbranch's idea. That mostly worked, yep. Turned into a bit of a show because some tests then had filtered and unfiltered outline spans by types, so I needed to make sure that they were all fine at the fourslash test layer. |
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.
🎉 glad my idea worked out!
@typescript-bot cherry-pick this to release-3.8 |
Heya @RyanCavanaugh, I've started to run the task to cherry-pick this into |
@orta can you manually port to 3.8 please? The cherry-pick build failed due to octokit being out of date. Alternatively you can push a master merge to the feature branch and request the cherry-pick again |
Fixes #22732
When you have a sourcefile which is just a comment, then there are no statement nodes which we can iterate over to grab the comments from. This PR adds an extra check for top level unattached comments and adds an outlining span for them.
It's careful to only handle multiline comments to not clash with the region support.