Skip to content

Consider adding "Go to Super" to context menu for improved visibility #4552

Closed

Description

@bsutton

I have a class B and a super class A.

class A {
 void somemethod();
}

class B extends A {
 @override
  void somemethod() ;
}

It would be nice to have a method where I could quickly navigate from B:something to A:something.

In eclipse I can click on the method name and be offered a number of navigation options one of which is 'navigate to super class' which switches the editor to the same method in the super class i.e A: something.

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on May 17, 2023
  2. DanTup commented on May 18, 2023

    @DanTup
    Member

    We have this in the command palette as "Go to super class/method". You can key-bind it, but unfortunately we can't add things to the context menu that are based on the position clicked (this is only possible for first-class functions VS Code provides).

    Screenshot 2023-05-18 at 18 40 24
  3. removed
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on May 18, 2023
  4. incendial commented on May 18, 2023

    @incendial

    @DanTup hey, have you considered using VS Code CodeLens feature for this? Or it'd be too noisy?

    Just curious.

  5. DanTup commented on May 18, 2023

    @DanTup
    Member

    I don't personally like lots of CodeLens (partly because they can lead to the code jumping around), but that's just me.

    But, to do this such that CodeLens only shows up where there actually is a super, we may need to do a lot more processing up-front (and on each file change). The current implementation does no work until you invoke it, and then just looks it up for the current location in the editor.

    If you'd like it, it's worth opening an issue to collect 👍 's though. If there's some demand for it, it may be worth exploring.

  6. incendial commented on May 18, 2023

    @incendial

    But, to do this such that CodeLens only shows up where there actually is a super, we may need to do a lot more processing up-front (and on each file change).

    Shouldn't a presence of the override annotation be enough? The annotation line is also known. And then you can calculate the navigation on click.

    If you'd like it, it's worth opening an issue to collect 👍 's though. If there's some demand for it, it may be worth exploring.

    I'm more concerned that this is something really not obvious (but we talked about this before), especially that it takes the cursor position. Not sure that there is enough demand for the change though.

  7. DanTup commented on May 18, 2023

    @DanTup
    Member

    Shouldn't a presence of the override annotation be enough? The annotation line is also known. And then you can calculate the navigation on click.

    Yeah, that would probably be good enough - though it's not free. We don't currently implement CodeLens in the server, so it would be a new request/round-trip on each change and a visit across the whole file. It's unlikely to be slow, but I'm conscious of all the things that happen on each key press (or some buffered set of) that add up (when you type a character in VS Code, it will ask for Folding Ranges, Semantic Tokens, Document Symbols, Code completion, Code Actions, etc.).

    Like I said, it's definitely worth filing an issue. There's a lot of things that could be done so having some gauge of interest will help prioritise them.

    I'm more concerned that this is something really not obvious (but we talked about this before), especially that it takes the cursor position.

    Yep, I completely agree discoverability in VS Code is not great (as we've discussed :)). Though I'm also conscious that we have a lot of features and if we try to put them all into the UI, things could get very busy, and the way CodeLens causes code to shift around can be really jarring, so it's probably the last place I'd like to put things without knowing they're wanted.

    There is an open VS Code issue about being able to render CodeLens in a way that doesn't shift code around which would improve that, but it's not available today.

  8. bsutton commented on May 19, 2023

    @bsutton
    Author

    I don't personally like lots of CodeLens (partly because they can lead to the code jumping around), but that's just me.

    But, to do this such that CodeLens only shows up where there actually is a super, we may need to do a lot more processing up-front (and on each file change). The current implementation does no work until you invoke it, and then just looks it up for the current location in the editor.

    If you'd like it, it's worth opening an issue to collect +1 's though. If there's some demand for it, it may be worth exploring.

    For the record, I also hate code lens.
    I've never had the reaction of - oh that's providing something useful that I want just now.

  9. bsutton commented on May 19, 2023

    @bsutton
    Author

    add things to the context menu that are based on the position clicked

    Is it worth opening a request on vs-code to allow this, or is it something they won't consider in order to protect visual studio?

    We have this in the command palette as "Go to super class/method". You can key-bind it, but unfortunately we can't add things to the context menu that are based on the position clicked (this is only possible for first-class functions VS Code provides).

    Screenshot 2023-05-18 at 18 40 24
  10. DanTup commented on May 19, 2023

    @DanTup
    Member

    Is it worth opening a request on vs-code to allow this, or is it something they won't consider in order to protect visual studio?

    I think they won't do it just because of how VS Code works. All menu entries like the top-level of context menu must be declared up-front so that there is no async work (eg. going to the extension host to ask for the entries). This is something I don't think they will compromise on for performance reasons.

    However, I just did some testing again and it seems like when you right-click, it does more the cursor to where you clicked. Sometimes it's not obvious because sometimes the editor seems to lose focus and you can't see it - but clicking in the explorer then tabbing back to the editor has the cursor where you right-clicked.

    So a possibility could be:

    • Add it to the context menu (it will show up always, just like Go to Definition)
    • When invoked from the context menu, use the current cursor position as the location

    I don't know whether it's a bit noisy to add less-used features like this to the context menu though, it's already quite long. I'm also not sure if we could put it in with the other VS Code "Go to" items.

    I'll re-open this as a request to try it out though.

  11. reopened this on May 19, 2023
  12. added this to the On Deck milestone on May 19, 2023
  13. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    in editorRelates to code editing or language features
    on May 19, 2023
  14. changed the title [-]Provide a quick navigation to a super function.[/-] [+]Consider adding "Go to Super" to context menu for improved visibility[/+] on May 19, 2023
  15. quyenvsp commented on May 25, 2023

    @quyenvsp

    @bsutton since my context menu already long, I don't think I want this. Did you tried set Keyboard Shortcuts for it? Current I am using Ctrl Alt Z, seem good.

  16. modified the milestones: On Deck, Backlog on Nov 27, 2023
  17. modified the milestones: Backlog, v3.82.0 on Jan 18, 2024
  18. DanTup commented on Jan 22, 2024

    @DanTup
    Member
    go_to_super_context.mp4
  19. DanTup commented on Jan 25, 2024

    @DanTup
    Member

    Forgot to tag this in the commit, implemented in 71a6e70.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions