Skip to content

Allow go-to-definition to show references when invoked on a declaration #2725

Description

@tothambrus11

Description

When the definition request is sent at a site of a declaration (e.g. when somebody ctrl+clicks a function declaration's name), we currently return an empty list (or maybe nil?). At least VSCode and Zed have a feature when after a definition request whose result includes the cursor, they realize that we would just jumpt back to ourselves, so they issue a references request and show all the usages of our symbol, which has quite a nice UX.

To enable this, we would need to pattern match the node under cursor, and if it's not a name but a declaration, just return the span of that declaration. I tested this in Hylo's LSP, and this strategy is confirmed to work in VSCode:

Image Image

References for the support:

Activity

  1. Pradyumn-cloud commented on Jul 29, 2026

    @Pradyumn-cloud

    Hello, I tried to work on this issue and found- SourceKitLSPServer.swift:2128-2136 returns declaration for Swift symbols that have both bestLocalDeclaration + a USR (symbol.usr?.hasPrefix("s:")).
    We can add a fallback that also handles cases where SourceKit does not provide a USR. Would you like me to implement it?

  2. ahoppen commented on Jul 30, 2026

    @ahoppen
    Member

    If we don’t have a USR, we wouldn’t be able to find references, so I don’t think there’s no point in fixing anything for the case.

    @tothambrus11 I just tried reproducing it and was able to see the jump-to-references behavior for SourceKit-LSP. Do you have an example project where you don’t see it?

  3. tothambrus11 commented on Jul 30, 2026

    @tothambrus11
    Author

    I will check again with the latest version. The last time I checked, the LSP seemed to bring me to the start of the declaration, which is the expected behavior. Maybe the VSCode extension has something misconfigured.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions