Skip to content

control-click on 'var' should navigate directly to the definition #2535

Closed

Description

@bsutton

If I perform a 'ctrl-click' on a type such as:

Widget aWigglyWidget;

Then dart-code takes me to the library for the Widget type.

If I perform a 'ctrl-click' on a var such as:

var aWigglyWidget = getAWidget();

Then dart-code opens a code lense.
I both cases I want to be taken to the dart library for Widget.

Activity

  1. DanTup commented on Jun 11, 2020

    @DanTup
    Member

    @bwilkerson interested in your thoughts on this (it would need to be done in the server). If it seems sensible, does the server have easy access to get the type? (I'm happy to take a look if it's within my ability!).

  2. added
    awaiting infoRequires more information from the customer to progress
    in editorRelates to code editing or language features
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Jun 11, 2020
  3. bwilkerson commented on Jun 11, 2020

    @bwilkerson

    Yes. It should be fairly straightforward to extend the _DartNavigationComputerVisitor to add regions for the keyword var.

    If we do that, should we also provide navigation from const and final? If yes, should we always provide it or only when there is no explicit type?

    (And out of curiosity, what's a "code lense"?)

  4. DanTup commented on Jun 11, 2020

    @DanTup
    Member

    If we do that, should we also provide navigation from const and final? If yes, should we always provide it or only when there is no explicit type?

    I think if it was supported on them without types, it should also work with types - if a user has it in their mind that it works on const and their cursor is already on const, they might (reasonably) assume it'll work there and press the keybind for it.

    out of curiosity, what's a "code lense"?

    In VS Code (and I think VS), there's a feature called CodeLens that allows injecting links into the editor. We use it in the VS Code extensions to provide easy links for things like running/debugging tests:

    Screenshot 2020-06-11 at 16 17 39

    (unfortunately it doesn't work in the analysis server repo because it uses the outline data to know where tests are, and things work a bit differently there - something that bugs me and I'd love to find a fix for!).

    However, I think in this context Brett was referring to the "peek"-style window that opens when Ctrl+Clicking var. It turns out we do actually find class, but we also include the location of the variable, and that results in VS Code this opening this to pick between the two definitions:

    Screenshot 2020-06-11 at 16 20 54

    So it turns out, we don't need to add the location of the class, rather we need to not include the variable. For non-LSP, this could be done in the VS Code extension code (assuming we can tell which one is which - perhaps when there are multiple we should ignore the one that's on the same line that we searched?), and for LSP this would be done in the server. WDYT?

  5. bwilkerson commented on Jun 11, 2020

    @bwilkerson

    For non-LSP, this could be done in the VS Code extension code (assuming we can tell which one is which - perhaps when there are multiple we should ignore the one that's on the same line that we searched?), ...

    Using the line number seems reasonable. It's highly unlikely that anyone will declare the type on the same line as a variable of that type.

    ... and for LSP this would be done in the server.

    Yep, that would be the appropriate place. Then it will work the same for all LSP-based clients.

  6. DanTup commented on Jun 11, 2020

    @DanTup
    Member

    Great - I pushed a fix here for non-LSP and a CL at https://dart-review.googlesource.com/c/sdk/+/150980/ for LSP.

  7. added and removed
    awaiting infoRequires more information from the customer to progress
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Jun 11, 2020
  8. changed the title [-]control-click on 'var' should navigate to the type's libraries.[/-] [+]control-click on 'var' should navigate directly to the definition[/+] on Jun 11, 2020
  9. bsutton commented on Jun 11, 2020

    @bsutton
    Author
  10. added this to the v3.12.0 milestone on Jun 22, 2020
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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions