-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Better outlining spans for prototype methods #32782
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
Better outlining spans for prototype methods #32782
Conversation
@dragomirtitian Thanks for looking into this! Regarding the problems you raised:
|
@amcasey Thank you for your feedback.
|
|
@jessetrinity is doing work in this area and is probably a better person to sign off on the actual code change. |
…s are mixed with other declarations).
I finished the changes for when ES5 classes are interwoven with other declarations. The outline is broken only if there is code that generates other outline nodes between class members: If you think I should make any other changes let me know. |
Aside from the one issue I noted it's looking pretty good so far in VS! |
I don't think we see that exact issue in VS, but it does look like our nav bar blows up when there is briefly an extra PropertyAccessExpression in there: |
I would want a sign off from @mjbvz as well for how the changes affect VSCode. |
@jessetrinity Strange. I will check the spans returned for the outline nodes. I did not see similar behavior in VS Code 😕. |
The overall presentation looks reasonable. Adding @jrieken in case he has any specific feedback on the error matching in the outline panel. For implementation, VS Code uses
These are important user facing features that should be available as soon as possible, so we run |
FYI I want to change the presentation of NavBar items with #33040. Updating the tests between both of these might be a little rough. If you don't get these changes in before that I would be happy to resolve any conflicts. |
@jessetrinity Thanks for the heads-up about this. It's been a hectic week and I haven't had time to finalize this. I will try to finish over the weekend. |
@jessetrinity I fixed the issue with multi-line values in the navigation item name. The reason was that previously I would put whatever was the target of the prototype access (ie for My solution was to walk up the prototype access target and add nodes for each identifier in the path. This will remove any spaces and should work fine (I did think about how to do this without generating the extra nodes, but I think this is the best solution, the other solution I considered was to keeping the current names and use a regex to remove unwanted characters, but this seemed hacky. The extra number of nodes should not be an issue in most situations, I expect most such classes are not nested in deep namespaces) |
@mjbvz I don't see any reason the changes in this PR would be incompatible with these features. I did try to be mindful towards performance while improving the outline, so users should not see any performance degradation in these features. Other than that I don't see any other potential issues, so I think it will work well 😊 |
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.
Change looks good as long as it can still run on the syntactic ts server
I think we just merged something similar to keep the navbar from breaking in these situations (it wouldn't keep us from getting into them in the first place, like this PR now does).
You would think that, but it turns out people do this quite extensively. Either way after some discussion we have decided that seeing all of the nested nodes is probably the best way to present it. |
* Changed outlining to better outline ES5 classes (functions assigned to prototype) * Changed outlining to better outline ES5 classes (properties assigned to functions) * Fixed some small bugs when merging es5 class nodes. Added tests for new es5 class outline. * Added support for interlaced ES5 classes (where an ES5 class's members are mixed with other declarations). * Fixed crash in outline when assigning {} to the prototype. * Added support for nested es5 declarations. * Added support for prototype assignment for es5 classes.
Fixes #31516
Hi @DanielRosenwasser, @amcasey
I know it's been a while since i said I would have a look at this, but I finally got around to finishing the implementation for this.
First the good news, this is what an ES5 class looks like now:
Now for the problems:
I see some options:

a. Do nothing, the outline looks nice, although the bug report about this kind of writes itself
b. Create multiple additional spans for the class if the members are not contiguous. This is probably the best option but it can end up splitting up the class outline node:
c. Include any extra node in the class outline, maybe marking them in some distinctive way (although I am not sure what that would look like, and it would be kind of confusing)
d. Change the way errors are matched with outline nodes in VS-Code (probably a bigger change than we want to make for this feature)
Given assignments of the form
It is impossible to tell without using the type checker, if the assignments will need to become static members on a class named
A
or they are just regular assignments. One option would be to keep all such assignments and remove them from the outline during the merging of outline nodes. This could end up creating a lot of extra nodes. My solution to limit the number of generated nodes was to track any found classes in the current scope, and only add nodes for the assignments above if a class like definitionA
was found in the current scope.A
is considered a class like definition if a functionA
is declared, or if a something was already assigned to the prototype ofA
:I do not search the scope before-hand, but rather mark the class when I find it, this does mean that if static members are assigned before I mark the class they do not appear in the outline as part of the class:

The alternative might be to not add these members at all.