Disable peek in Visual Studio Code

I've made a pull request to fix this https://github.com/Microsoft/vscode/pull/68023, but until then here's a temp fix that patches the VSCode installation files. You'll need to re-apply every update.

EDIT: The fix was merged into vscode. It should be in later versions.

With this fix Ctrl+Click will:

  • Use peek if there are multiple definitions
  • When using peek, will not navigate to the best match in the editor and cause you to lose your spot
  • If there is only one definition, it will navigate to the best match and NOT open peek.

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

    • https://github.com/Microsoft/vscode/blob/e82d8bb6e6c8fd07ca16eacd16663ebd221187cb/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts#L128
  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.


I tried to find a workaround changing the behavior of CMD + Click to go to implementation but it appears there is no solution yet?

The VSCode documentation shows its set by default to go to definition without a way to modify it: https://code.visualstudio.com/docs/editor/editingevolved

On my machine (Mac) if I press CMD + Click or F12 on a method it will direct me to the Peek view on the definition, however CMD+F12 will direct me to the implementation without the peek appearing.