Issue Type: Bug
.cpp file.Expected results:
VS Code does exactly one of "Go to Definition" or "Peek Definition". There is a preference where I can control which one.
Actual results:
VS Code does both: it jumps to the definition, and then opens a code lens with the same definition.
Note:
I'd prefer Cmd-Click to "Peek Definition", which it used to do a while ago.
Workaround:
For Peek Definition, Alt-F12 works fine.
For Go to Definition, F12 sometimes works fine, but sometimes has the same bug, i.e. it jumps to definition __and__ opens a code lens with the same piece of code.
Extension version: 0.17.4
VS Code version: Code 1.23.1 (d0182c3417d225529c6d5ad24b7572815d0de9ac, 2018-05-10T16:03:31.083Z)
OS version: Darwin x64 17.5.0
System Info
|Item|Value|
|---|---|
|CPUs|Intel(R) Xeon(R) W-2191B CPU @ 2.30GHz (36 x 2300)|
|GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: enabled
rasterization: enabled
video_decode: enabled
video_encode: enabled
vpx_decode: enabled
webgl: enabled
webgl2: enabled|
|Load (avg)|2, 2, 2|
|Memory (System)|32.00GB (0.31GB free)|
|Process Argv|/Applications/Visual Studio Code.app/Contents/MacOS/Electron|
|Screen Reader|no|
|VM|0%|
This is "by design" when multiple definitions are found. The code lens shows alternative definitions, which might be the correct one. The jumped to version is just the 1st one in the list. This will be fixed when we implement multi-translation unit intellisense and are able to locate the 1 true definition.
I see, thanks for the explanation. If possible, I'd still like to have a quick mouse interaction for Peek Definition, maybe Cmd-Shift-Click. But that's a feature wish I guess.
@sean-mcmanus: I would strongly prefer it to just show a peek when multiple definitions are found. Jumping to and peeking the same source is rather distracting/confusing.
As a whole though, the extension is amazing :)
VS Code itself controls that behavior -- we just return a list of results. See https://github.com/Microsoft/vscode/issues/31046 for an issue on their side. Also, when we implement Go to Definition using the IntelliSense engine (instead of a fuzzy symbol lookup), then only 1 definition should be found.
@sean-mcmanus what about virtual methods? How would you expect this to work once the IntelliSense engine is used?
Visual Studio uses the single compile-time type for go to definition and not the run-time type of the object (i.e. base->func() goes to the base class, not multiple subclass definition), so that's how we would behave unless we did something special.
I'm also having the same issue, I don't have 2 definitions for a function, only 1.
That means that the "code lens" is opened each time I uses it for no reason, will this be fixed?
@wtyp The code lens opens because we incorrectly detect 2 definitions, right? That is intentional to allow users to manual select the correct definition. Getting the correct definition is being tracked by https://github.com/Microsoft/vscode-cpptools/issues/255 . The VS Code issue to stop automatically jumping to a definition is https://github.com/Microsoft/vscode/issues/31046 .
This behaviour started surfacing perhaps a couple of updates ago.
When I Go to Definition*, it opens the file with the definition and then proceeds to Peek Definition because it apparently detects the _same_ definition _twice_. Selecting either from the peek popup, takes me to the exact same place.
*It doesn't happen on every one, just maybe methods or when the code hint says Click to show 2
definitions. Happens even with extensions disabled.
EDIT: Seems to be same as: https://github.com/Microsoft/vscode/issues/51489 and thus will be fixed with the next release! 馃帀 I've verified with Insiders edition and appears to working as expected.
VS Code fixed this via adding a editor.gotoLocation.multiple setting that defaults to "peek".
Most helpful comment
@sean-mcmanus: I would strongly prefer it to just show a peek when multiple definitions are found. Jumping to and peeking the same source is rather distracting/confusing.
As a whole though, the extension is amazing :)