Add a command "Go To Definition/Declaration "

未关闭
#14,509 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
50/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
cpp, typescript, vscode

调研方向

检查现有的 editor.action.revealDeclaration 和 editor.action.revealDefinition 命令,以及 issue 中的 F12/键绑定示例。跟踪 C/C++ 扩展的命令入口点,并确定当前符号上下文(包括 #include 行)如何选择目标;当一个原生命令能够始终如一地选择适当的操作时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
6.2k
派生
1.7k
平均合并
14 小时 46 分钟
30 天内合并 PR
61

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/vscode-cpptools 的其他 Issue

查看 microsoft/vscode-cpptools 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。