在Visual Studio Code中禁用Peek

86

有没有办法在Visual Studio Code中禁用ctrl-click“查看”功能?理想情况下,我希望ctrl-click只是在新标签页中打开包含定义的文件。

编辑:我提交了一个问题,至少让它不那么令人困惑。显然我的术语略微错误。

澄清一下,有两个操作:

  1. 右键单击 -> 查看定义
  2. 右键单击 -> 转到定义(绑定到ctrl-click)

它们的行为如下:

  1. PD,单个定义
    • 打开内联界面显示定义。
  2. PD,多个定义

    • 打开内联界面显示定义。
  3. GtD,单个定义

    • 打开包含定义的文件。
  4. GtD,多个定义
    • 随机选择其中一个定义,打开该文件,并显示所有定义的内联界面。
除了最后一个之外,所有的都可以。两件事情一起做会导致一个非常冗余和混乱的用户界面,如下所示:

Confusing!

应该有一种方法来实现以下其中一种行为:

  • 随机选择一个定义,打开该文件。

或者:

  • 打开内联界面,显示所有定义(在当前文件中

我已经为你点赞了,但是你在 GitHub 上的问题与“Ctrl + 单击只会在新标签页中打开包含定义的文件”无关(我的意思是禁用它)。我已经在这里开了一个新的问题。 - fabriciorissetto
@Matt,你到底想要什么?你是想完全禁用Peek功能吗?还是希望多个引用在Peek窗口中打开,而不是第一个引用? - Tarun Lalwani
@TarunLalwani 我玩了一下之后发现有多个问题。首先,Flow JavaScript支持中存在一个错误,即当它们相同时会显示多个定义。当然,这超出了本问题的范围。对于此赏金,我想说如果VSCode已经打开了另一个文件并且该选项卡包含两个定义,则可以接受禁用peek的内容。如果定义在两个不同的文件中,则随机选择它们并没有太多意义。希望我表述更清晰,对混淆感到抱歉 :) - Matt
@Matt,这需要在 https://github.com/Microsoft/vscode/blob/e499dc62b581c67e329c49c91187316221b2d2f3/src/vs/editor/contrib/goToDeclaration/goToDeclarationCommands.ts#L129 上修改代码,因此我无法提供代码更改的答案,但是可以指出方向,因为这需要重建 vscode。 - Tarun Lalwani
具体的VS版本? - Mark Schultheiss
3个回答

13

我已经提交了一个拉取请求来修复这个问题https://github.com/Microsoft/vscode/pull/68023,但在此之前,这里有一个临时解决方法,可以修补VSCode安装文件。 每次更新后都需要重新应用。

编辑:修复已合并到VSCode中。它应该出现在较新的版本中。

通过这个修复,Ctrl+Click将:

  • 如果有多个定义,则使用Peek
  • 使用Peek时,不会导航到编辑器中的最佳匹配项,并且会使您失去当前位置
  • 如果只有一个定义,则会导航到最佳匹配项而不打开Peek。

  1. Figure out what the function that needs to be patched looks like. The method is DefinitionAction.prototype._onResult(editorService, editor, model)

  2. Go to the VSCode installation directory. %LocalAppData%\Programs\Microsoft VS Code and right click and open the directory in VSCode so that we can use VSCode's search feature to search for text in every file.

  3. Search for _onResult and evaluate every result, checking to see if the signature and body matches what we are expecting from the function we saw in step 1.

    • We know from step 1, the function _openReference is nearby. Use that to narrow the search.
    • I found it in workbench.main.js line 2454. Use bracket matching to find the end or know that it ends immediately before t.prototype._openReference
    • The function when formatted is the following (async func is compiled down to statemachine, that's why it looks nothing like the source typescript):

      t.prototype._onResult = function (e, t, r) {
        return i(this, void 0, void 0, function () {
          var i, s, a;
          return n(this, function (n) {
            switch (n.label) {
              case 0:
                return i = r.getAriaMessage(), o.alert(i), this._configuration.openInPeek ? (this._openInPeek(e, t, r), [3, 3]) : [3, 1];
              case 1:
                return s = r.nearestReference(t.getModel().uri, t.getPosition()), [4, this._openReference(t, e, s, this._configuration.openToSide)];
              case 2:
                (a = n.sent()) && r.references.length > 1 ? this._openInPeek(e, a, r) : r.dispose(), n.label = 3;
              case 3:
              return [2]
            }
          })
        })
      }
      
  4. Replace the function with the following (if using same version) or format and edit the function you found to be similar to this example. Note the o variable is the global\window object and subject to change.

    t.prototype._onResult = function (e, t, r) {
      return i(this, void 0, void 0, function () {
        return n(this, function (n) {
          switch (n.label) {
            case 0:
              return r.getAriaMessage(), o.alert(r.getAriaMessage()), this._configuration.openInPeek || r.references.length > 1 ? (this._openInPeek(e, t, r), [3, 3]) : [3, 1];
            case 1:
              return [4, this._openReference(t, e, r.nearestReference(t.getModel().uri, t.getPosition()), this._configuration.openToSide)];
            case 2:
              r.dispose(), n.label = 3;
            case 3:
            return [2]
          }
        })
      })
    }
    
  5. Launch VSCode. You will get a Your Code installation appears to be corrupt. Please reinstall. Just hit the gear icon and click Don't Show Again.


2
我尝试找到一个解决方案来更改CMD + 点击的行为以便跳转到实现,但目前似乎还没有解决方案?
VSCode文档显示它默认设置为跳转到定义,没有修改的方法: https://code.visualstudio.com/docs/editor/editingevolved 在我的Mac机器上,如果我按下CMD + 点击或F12在一个方法上,它会将我定向到定义的Peek视图,然而CMD+F12则不会出现Peek,直接跳转到实现。

0

这个问题似乎在新版本中已经被修复了。如果我现在将鼠标悬停在foo.cpp文件中的FOO上,我会看到正常的工具提示#define FOO 2。如果我按下Ctrl键,消息会扩展并添加文本“单击以显示2个定义”,如果我在仍然按住Ctrl键的情况下单击,我将得到所请求的窥视窗口。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接