Add a command "Go To Definition/Declaration "

Open
#14,509 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
50/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp, typescript, vscode

Research direction

Review the existing editor.action.revealDeclaration and editor.action.revealDefinition commands and the F12/keybinding examples in the issue. Trace the C/C++ extension's command entry points and determine how the current symbol context, including #include lines, selects the target; done means one native command consistently chooses the appropriate action.

Written by the indexing model from the issue text.

Description

enhancement Feature: Go to Definition Language Service more votes needed
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.

Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/vscode-cpptools

All issues in microsoft/vscode-cpptools

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.