Skip to content

Add a command "Go To Definition/Declaration " #14509

Description

Feature Request

I would love to be able to apply "Go To Declaration" when I am requesting it on a definition, and "Go To Definition" when I am requesting it on a declaration.

I foolishly thought this was the standard F12 behaviour before finding out I need to bind both and use them contextually! I imagine its trivial to implement the context switching internally and apply the correct one given the context of the request.

i.e.
IF requested on a declaration -> Go To Definition
IF requested on a definition -> Go To Decleration

My workaround currently is binding the behaviour to the "when" field inside Keybinds.json based on file endings:

    {
        "key": "F12",
        "command": "editor.action.revealDeclaration",
        "when": "editorHasDeclarationProvider && editorTextFocus && !isInEmbeddedEditor && resourceExtname =~ /\\.(cpp|cxx|cc|c\\+\\+|c)$/"
    },
    {
        "key": "F12",
        "command": "editor.action.revealDefinition",
        "when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor && resourceExtname =~ /\\.(hpp|hxx|hh|h\\+\\+|h|inl|ipp)$/"
    },

This fails in nuanced cases such as F12 on #include lines when in a source file, this will attempt "Go To Declaration" and fail but should be using "Go To Definition". Another reason a context based command would be useful!

A native command provided by the extension would be nice.

Activity

  1. MStachowicz commented on Jun 11, 2026

    @MStachowicz
    Author

    I have found a better workaround, continuing to use "Go To Definition" and settings VSCode settings as:

    "editor.gotoLocation.alternativeDefinitionCommand": "editor.action.revealDeclaration",

    This defaults to "Find all references" which always confused me, I think the above should be default as it mirrors Visual Studio.

    Now the Go to definition works as I desired above:

    IF requested on a declaration -> Go To Definition
    IF requested on a definition -> Go To Decleration
    

    Thanks #13147 for helping me find this option.

  2. sean-mcmanus commented on Jun 15, 2026

    @sean-mcmanus
    Contributor

    We could potentially set the default settings for C/C++ in our package.json.

        "editor.gotoLocation.alternativeDefinitionCommand": "editor.action.revealDeclaration",
        "editor.gotoLocation.alternativeDeclarationCommand": "editor.action.revealDefinition"

    However, I already see go to def on a def return the declaration, but maybe there might be cases where that doesn't happen? Maybe we could internally change go to decl to match and return the definition.

  3. github-actions commented on Aug 15, 2026

    @github-actions

    This feature request is being closed due to insufficient upvotes. Please leave a 👍-upvote or 👎-downvote reaction on the issue to help us prioritize it. When enough upvotes are received, this issue will be eligible for our backlog.

  4. added this to the Triage milestone on Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions