Skip to content

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

Merged
merged 2 commits into from
Feb 25, 2020

Conversation

orta
Copy link
Contributor

@orta orta commented Feb 19, 2020

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.

if (sourceFile.statements.length > 0) return;

// This will instead set up spans for the missing ones
forEach(getLeadingCommentRangesOfNode(sourceFile, sourceFile), (range) => {
Copy link
Member

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.

Copy link
Member

@andrewbranch andrewbranch left a 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™?

@orta
Copy link
Contributor Author

orta commented Feb 24, 2020

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.

Copy link
Member

@andrewbranch andrewbranch left a 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!

@orta orta merged commit 8a797ca into microsoft:master Feb 25, 2020
@RyanCavanaugh
Copy link
Member

@typescript-bot cherry-pick this to release-3.8

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 25, 2020

Heya @RyanCavanaugh, I've started to run the task to cherry-pick this into release-3.8 on this PR at 55599ed. You can monitor the build here.

@RyanCavanaugh
Copy link
Member

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getOutliningSpans does not return multiline comment
5 participants