Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable peek in Visual Studio Code

Is there a way to disable the ctrl-click 'peek' feature in Visual Studio Code? Ideally I'd like ctrl-click to just open the file containing the definition in a new tab.

Edit: I submitted an issue to at least make it less confusing. Apparently my terminology is slightly wrong.

To clarify, there are two actions:

  1. Right-click -> Peek Definition
  2. Right-click -> Go to Definition (bound to ctrl-click)

Their behaviour is as follows:

  1. PD, Single Definition
    • Opens inline interface showing definition.
  2. PD, Multiple Definitions

    • Opens inline interface showing definitions.
  3. GtD, Single Definition

    • Open the file containing the definition.
  4. GtD, Multiple Definitions
    • Pick one of the definitions at random, open that file, and an inline interface showing all the definitions.

All of those are fine except the last. Doing both things results in a really redundant and confusing UI like this:

Confusing!

There should be a way to have one of these behaviours:

  • Pick one of the definitions at random, open that file.

Or:

  • Open inline interface showing all the definitions (in the current file)
like image 552
Timmmm Avatar asked Jan 04 '17 09:01

Timmmm


People also ask

How do I enable peek in Visual Studio?

You can peek a definition by choosing Peek Definition from the right-click menu for a type or member that you want to explore. If the option is enabled, you can also peek a definition using the mouse, by pressing Ctrl (or another modifier) and clicking the member name. Or, from the keyboard, press Alt+F12.

How do you turn off telemetry in VS Code?

Disable telemetry reporting# telemetryLevel user setting to off . From File > Preferences > Settings (macOS: Code > Preferences > Settings), search for telemetry , and set the Telemetry: Telemetry Level setting to off . This will silence all telemetry events from VS Code going forward.

How do I turn off IntelliSense code?

For C or C++, choose “Advanced“, then scroll to the “IntelliSense” section. For C# and Basic, check the “Show completion list after a character is typed” to disable it. For C/C++, you will have a few options, such as “Disable Auto Updating“, “Disable Squiggles“, and “Disable #include “Auto Complete“.


1 Answers

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.

like image 193
Derek Ziemba Avatar answered Oct 07 '22 23:10

Derek Ziemba