-
Notifications
You must be signed in to change notification settings - Fork 348
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
Goto super method in hierarchy of inheritance #1487
Goto super method in hierarchy of inheritance #1487
Conversation
d7915f0
to
dbf2942
Compare
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.
Thanks for the amazing work! I have some comments, but mostly around making the code more maintainable.
metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/GoToSuperMethod.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/CodeLensProvider.scala
Outdated
Show resolved
Hide resolved
94b3686
to
216d7ef
Compare
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 think it's almost ready! I left a couple of comments and will try to finish the review tomorrow
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SymbolWithAsSeenFrom.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/CodeLensProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/codelenses/CodeLenses.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/codelenses/SuperMethodLensesProvider.scala
Outdated
Show resolved
Hide resolved
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.
Thank you for this contribution! A few minor comments on style, the only blocking comments are to remove usage of asInstanceOf
metals/src/main/scala/scala/meta/internal/implementation/GoToSuperMethod.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/codelenses/CodeLenses.scala
Outdated
Show resolved
Hide resolved
This is super impressive work @kpbochenek I agree the configuration option to enable/disable the code lenses is merited in this case, even if we try to avoid user-facing configuration options. I'm really excited to try this out 😄 |
First of all, this is awesome :) Is it possible to completely separate this from being dependent on having |
metals/src/main/scala/scala/meta/internal/metals/CodeLensProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
metals/src/main/scala/scala/meta/internal/metals/codelenses/SuperMethodLensesProvider.scala
Outdated
Show resolved
Hide resolved
Updated and commented on all requests. There should probably still be some documentation added for users but I would like to firstly get this one merged, then give it a moment to settle and verify usability is okay, then update docs in another PR. |
metals/src/main/scala/scala/meta/internal/implementation/SuperMethodProvider.scala
Outdated
Show resolved
Hide resolved
@ckipp01 do you think you could try test command
If you are on overridden method it should show you popup(the same as for NewScalaFile) with list of super methods you want to go (it is good to test if there is C.x <: B.x <: A.x, call it on C.x and see a list: [B.x, A.x]) I assumed you might be familiar with vim <-> metals (coc-vim?) stuff but if I am wrong do you know who I could talk to about this? |
Sure. The implementation ends up being a tad different since the coc.nvim api doesn't have I'll probably also just make a shortcut to easily be able to trigger it instead of using the command pallete. |
@ckipp01 thanks for checking 👍 if it works with 2 editors it should work with all :D |
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.
Looks good, let's have it merged after the release. I would feel better if we let it sit in the SNAPSHOT for a while, if no one objects?
Thanks @kpbochenek for the amazing work!
@tgodzik I think it's OK to merge now and include it in the release notes. It's a very impressive feature! |
708dc75
to
99ef3cd
Compare
TokenEditDistance.fromBuffer(path, textDocument.text, buffers) | ||
|
||
for { | ||
occurrence <- textDocument.occurrences |
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 wonder if it would be faster to go over symbols, check if they are field or method and only as the last step find occurence?
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.
Overall, I think this is ready to merge. I added one comment about possible optimization, but maybe until we have proper benchmarks we cannot really assume anything.
The question remains on how we go around and merge it? If we merge this PR this will cause lense to appear which do not do anything. We need the merge in the VS Code plugin for that. @olafurpg @gabro @ckipp01 What do you think?
I think 3 is most reasonable for now. |
I think we should just do nightly releases and not worry about it 😏 ... Jokes aside, yea we ran into this in the last big release as well, and I think it will continue to happen 🤔 . For coc-metals I error on the side of merging things in that require the snapshot of metals since it's easy to use both the master branch of coc-metals and a snapshot or vice versa. However, in VS Code we have the tricky situation where I assume the average user doesn't want to build the VS Code extension locally in order to use a Metals snapshot. Would it be possible to do a hybrid of one, and turn the feature off by default unless explicitly turned on by the client? That way the lenses won't appear? Then when we do merge and release the vs code client the default "on" will trigger it and the lenses will then appear? |
I think that's a great idea! We can update the vscode plugin and label it to wait for the release. |
fcf7cb9
to
126130a
Compare
126130a
to
55838e6
Compare
Fixes #1416
Goto super method + lenses
Preview of how it looks like in VSCode:

During requesting lenses metals will also calculate if any definition of a method in requested file overrides another method, if yes it will attach lens to this position to be able to go to super method. Lenses also link to methods in external dependencies and are displayed in files from libraries.
They are configurable from
UserConfiguration
, example from VSCode:If they are found to be disturbing your workflow they can be easily disabled(they are enabled by default). Goto Super Method lenses should be quick to calculate but if you notice significant slowdown you can also disable them(when disabled they are not only not displayed but also not calculated at all)
There is also exposed server command:

goto-super-method
that can be mapped and used through shortcut. As example from VSCode PR (in client it ismetals.go-to-super-method
):Goto Super Method in hierarchy
Preview how it looks like in VSCode:

Metals server exposes command
super-method-hierarchy
that can be invoked on a method definition. It calculated super method hierarchy and if more than one position is found it displays quickPick window (same as from new scala file) with super methods and when user selects one entry it jumps to that definition.As example from VSCode it can be bind to a shortcut this way:

Internal
At core of those changes is implementation of a function to perform linearization of any provided class. It is used in this PR to find first next super method or list super methods according to linearization rules but it can also be used in a future for another features.
Other changes: