Skip to content

Set C/C++ go-to fallback defaults between definition and declaration - #14681

Open
Prashant Kumar Rai (8prashant) wants to merge 2 commits into
microsoft:mainfrom
8prashant:fix/14509-goto-definition-declaration-toggle
Open

Set C/C++ go-to fallback defaults between definition and declaration#14681
Prashant Kumar Rai (8prashant) wants to merge 2 commits into
microsoft:mainfrom
8prashant:fix/14509-goto-definition-declaration-toggle

Conversation

@8prashant

Copy link
Copy Markdown

This PR improves C/C++ navigation defaults so definition and declaration commands fall back to each other automatically.

Linked issue

Fixes #14509

What changed

  • Updated C/C++ language-specific configuration defaults to set:
    • editor.gotoLocation.alternativeDefinitionCommand = editor.action.revealDeclaration
    • editor.gotoLocation.alternativeDeclarationCommand = editor.action.revealDefinition
  • Applied for:
    • [c]
    • [cpp]
    • [cuda-cpp]

Why

This provides smoother F12 behavior across declaration/definition contexts without requiring users to create custom keybindings by file extension.

Test coverage

  • Added a unit test that validates these defaults are present in package.json for [c], [cpp], and [cuda-cpp].
  • Test executed:
    • ./node_modules/.bin/mocha.cmd dist/test/unit/gotoLocationDefaults.test.js --timeout 30000
  • Result: passing (1 test).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds reciprocal declaration/definition navigation fallbacks for C, C++, and CUDA C++.

Changes:

  • Configures declaration and definition fallback commands.
  • Adds unit coverage for all supported language defaults.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Extension/package.json Adds language-specific navigation defaults.
Extension/test/unit/gotoLocationDefaults.test.ts Verifies the defaults for C, C++, and CUDA C++.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bobbrow

Bob Brown (bobbrow) commented Aug 14, 2026

Copy link
Copy Markdown
Member

For the most part we avoid changing VS Code defaults for languages because they are more difficult for the average user to override. We have only approved very few changes to the default settings that negatively impact the experience.

I don't think this is a change we want to take unless we get more feedback that confirms this is a widespread problem with the experience. I believe our language server is supposed to return the declaration when on the definition and vice versa already so I'd rather we fix any bugs in the language server itself than apply this policy for all users.

@sean-mcmanus

Sean McManus (sean-mcmanus) commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Bob Brown (@bobbrow) My impression was that is a widespread problem. I recall the default fallback is find all references which is almost never what a user wants. I think these defaults are what users actually want for C/C++, but I haven't tried it out yet.

I think there is one case where were return the declaration for the definition but not the other way around or something. I don't think there's a cpptools side bug.

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

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

Add a command "Go To Definition/Declaration "

5 participants