Adds floating block comments to the outlining spans response#36880
Adds floating block comments to the outlining spans response#36880orta merged 2 commits intomicrosoft:masterfrom
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.
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.
andrewbranch
left a comment
There was a problem hiding this comment.
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. |
andrewbranch
left a comment
There was a problem hiding this comment.
🎉 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.