Reputation: 96798
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:
Their behaviour is as follows:
PD, Multiple Definitions
GtD, Single Definition
All of those are fine except the last. Doing both things results in a really redundant and confusing UI like this:
There should be a way to have one of these behaviours:
Or:
Upvotes: 89
Views: 13599
Reputation: 2653
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.
With this fix Ctrl+Click will:
Figure out what the function that needs to be patched looks like. The method is DefinitionAction.prototype._onResult(editorService, editor, model)
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.
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.
_openReference
is nearby. Use that to narrow the search.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]
}
})
})
}
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]
}
})
})
}
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.
Upvotes: 15
Reputation: 969
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.
Upvotes: 2
Reputation: 8605
This seems to have been fixed in a newer version. If I now hover over FOO
in foo.cpp
, I see the normal tooltip #define FOO 2
. If I press Ctrl, the message expands to add the text "Click to show 2 definitions" and if I click while still holding Ctrl, I get the peek window, as requested.
Upvotes: 0