Vscode: Allow peek editor to be disabled

Created on 27 Jun 2018  Â·  50Comments  Â·  Source: microsoft/vscode

I'd like to be able to disable the peek editor. I don't want to see it or use it ever.

Thanks for a great product.

editor-symbols feature-request on-testplan

Most helpful comment

It's "editor.gotoLocation.multiple": "goto" now

All 50 comments

Can you just avoid using "find all references", "peek definition", etc? We don't have another UI option for "find all references" currently. Can you explain some more about what you want?

I don’t want it to pop up when I use “go to definition“, even if there are multiple definitions.

What would be the expected behavior when there are multiple definitions? There would be no way to reach anything but the first one

So, multiple definitions seem to always happen in cases like this:

function foo() { /* ... */ } // <-- definition 2

export default {
  foo, // <-- definition 1
};

and the only time the peek editor shows up is when it navigates to a different file. Once I'm in that file, at definition 1 in my example above where I always land, activating "go to definition" again brings me to definition 2.

So, going to definitions seems to be a completely independent of the peek editor.

What about multiple definitions requires a visual UI? I'd like to just navigate them as if I were navigating through a chain of bookmarked spots, by continually pressing F12.

+1 for:

  1. giving us a way to disable this completely
  2. default to "finding first"; we trust y'alls ability to make a reasonably good guess as to what's first

Mine's completely broken with curried functions in the new version of Code, old worked. Example, I have a function called createUserUnsafe:

.then( ({salt, encryptedPassword}) =>
    createUserUnsafe(
        dbClient,
        newUsername,
        encryptedPassword,
        salt,
        newEmail
    )
)

I COMMAND+Click, and it shows that it has 2 entries, which is not true:

screen shot 2018-06-28 at 9 53 02 am

  1. I'm not using TypeScript
  2. I only defined this function once, in the same file.

Rather than fix it to support curried functions, just give us the ability to turn this off, and guess if you find multiple.

at definition 1 in my example above where I always land, activating "go to definition" again brings me to definition 2.

Ok, you describe a mode in which F12 walks you to all definition of that symbol (function foo) but isn't the question then how to you leave that mode?

@jrieken There is no mode to leave. If I'm in a file and I hit F12 on a function call and that function is defined in the same file...there is no visual that pops up. The cursor simply jumps to the locally defined function.

There is no mode to leave. If I'm in a file and I hit F12 on a function call and that function is defined in the same file...there is no visual that pops up. The cursor simply jumps to the locally defined function.

Yeah, but that's how it works today. uUnless there are multiple definitions in which case don't pick on randomly but show the peek.

Yes and I'm asking them to pick one and not show the peek editor.

They are already picking one randomly (although, it's not that random) and navigating to that spot right before showing the peek editor.

So, the simple request here is to just not show the peek editor. If other users want the peek editor - it can be enabled by default for those people.

I'm going to work on an AutoHotKey script to do what I want, which is basically this:

If VSCode Window is Active,
When User Hits F12;
Wait 50ms
Send the ESC key;

Adding a setting that reduces many definition to just one is easy if that's what people want. Instead of fiddling with AutoHotKey, how about a PR? Code pointer is this: https://github.com/Microsoft/vscode/blob/763dea187d39c04b68281049814d3b494a408a63/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts#L99

OK, I was looking through the code surrounding the peek editor earlier and I couldn't find anything obvious.

For some reason, that link doesn't work for me - I get a 404 - however, there's enough information there to find the file. Thanks!

I think this is where the decision is made - https://github.com/Microsoft/vscode/blob/987160c70adb3fdab30da30fef7d1c05a74ff858/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts#L138-L143

I have no clue how to get the setting of a global value from within that module, so I'm just leaving this note here in case I can't get it done.

This is a sample for how to add a new setting to the system (https://github.com/Microsoft/vscode/blob/0c27d9b38e1ae2572e32475abde13d29f2eb71bf/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts#L494-L506) and then use the IConfigurationService to read the value

So, if I actually put some work into doing this - how long can I expect to wait before my pull request is merged?

I might just use my 15-minute AutoHotKey solution for now because it's very simple compared to possibly waiting weeks or months for a merge and/or maintaining my own branch of VSCode...

The reason I ask is that I've seen other good pull requests go un-merged and I don't want to waste my time if that's going to happen.

wait before my pull request is merged?

Hard to make a prediction... The first hurdle (do we want this) is already taken, it's mostly about code quality then.

The peek editor is pretty annoying in my workflow too.. Here's an example:

import React, {Component} from 'react'

class MainComponent extends Component {
  render () {
    return <SubComponent text="Hello World" />
  }
}

const SubComponent = ({text}) => {
  return (
    <div>{text}</div>
  )
}

export default MainComponent

If I F12 into SubComponent, it will pull up 2 definitions in the peek editor. One for the word SubComponent in the constant declaration, and the second for...

({text}) => {
  return (
    <div>{text}</div>
  )
}

Why would I ever need multiple definitions in this scenario? It's literally calling the function and the function's own declaration 2 different definitions. I have never used the peek editor, only ever dismissed it.

Please, give me an option to let it die.

For a stretch goal, it could be made less intrusive. Take me to the first definition, but put a small tooltip or intellisense context menu thing telling me there are additional definitions, and allowing me to go to the next one.

@10hendersonm That's a bug (https://github.com/Microsoft/TypeScript/issues/24809 or https://github.com/Microsoft/TypeScript/issues/24861) not a inherit problem with peeks

Here's the AutoHotKey script I've been using for a while to automatically hide the peek editor after I hit F12 when VSCode is the active window.

It works great. The peek editor does flicker onto the screen very, very briefly.

#IfWinActive, ahk_exe Code.exe
  F12::
  Send {F12}
  Sleep, 25                       ; Timeout might need to be adjusted...
  Send {Esc}
#IfWinActive

_EDIT: Of course, this doesn't work if you Ctrl+click on things to go to definition._

I'm working on a fix for this issue and have a few clarifying questions about the expectations.

Should the new setting disable the peek editor for just Go to Definition, or also Open Definition to the Side and Go to Type Definition?

Also, I'm assuming that the setting shouldn't affect the behavior of Go to Implementation.

@hhu94 I don't speak for everyone, but have a hunch most want it to act like it did before with no peek.

  1. Command + Click
  2. Either scrolls to the definition of the variable or method, or opens up the module/definition. For Python/JavaScript, this means either scrolling in the currently open file to the function definition, or open the source file where the function/class method is defined.

The concerns about finding multiple matches, fine, pick the first.

I'm aware that it should act the same way as before, just without the peek editor popping up. To clarify, my question is should the setting affect actions other than Go to Definition? In my PR I made it also affect Open Definition to the Side and Go to Type Definition.

Great question, no clue. I never use those, just Command + Click but I know the TypeScript and Python lovers may have good opinions about this.

So just tried this myself and now I get it. I'd vote:

  • Open Definition to the Side should ignore peek; you're looking to open the source of a class to compare for interfaces, or to work on a source class of a unit test class, it should just open the first it finds.
  • Go to Type Definition is tricky because it could be the source function, the literal type, where it's defined, where it's imported, yadda yadda... and that's WITHOUT the types you get with typed languages. That should probably stick with peek.

I see. I think the simplest solution will be to add a setting for each of the actions, since it seems like the use cases for the three actions might differ from user to user. I'll update my PR.

When using Find all References I just want to see a list of files. I don't want to peek definition into them. I find peek definition distracting and annoying. Especially when it is "peeking" into code that I'm already in in the current editor. It makes it confusing as to where the code is and what I'm looking at.

Real, why need it stupid mini window?

Just saw the PR, no reviews since September. Anything I can do to speed up the process / help on that PR ?
I would really fancy that feature to be honest

I'm revisiting this issue now and I can't find any situation in which Go to Definition would produce more than one definition (at least not in Typescript).

If someone can point me to a way to reproduce the issue I'll resolve the conflicts on my PR and push to get it merged. Otherwise I'll close it since it would mean the issue is not an issue anymore.

In a C++ source file, if I Go To definition of a function with its implementation in that source file and its declaration in a header file, Go To Definition will jump to the implementation in the source file but the peek editor will still pop up with the declaration in the header file.

Ideally VSCode would just jump to the implementation and the peek editor wouldn't pop up.

@DaanDeMeyer I can't seem to reproduce this. Which C++ extension are you using? Using this one , Go to Definition always jumps to the declaration in the header file, it doesn't show the peek editor.

In fact even using Peek Definition shows just the declaration in the header file, not the implementation.

// my_class.h
namespace N
{
    class my_class
    {
    public:
        void do_something();
    };

}
// my_class.cpp
#include "my_class.h" // header in local directory

using namespace N;

void my_class::do_something()
{
}
// my_program.cpp
#include "my_class.h"

using namespace N;

int main()
{
    my_class mc;
    mc.do_something();
    return 0;
}

I'm using clangd (from LLVM) with the corresponding extension vscode-clangd.

To reproduce the problem I have to Go To Definition of an implementation from the same source file where the implementation is defined (in your example, do_something would have to be called inside another function or method in my_class.cpp

To reproduce the problem I have to Go To Definition of an implementation from the same source file where the implementation is defined (in your example, do_something would have to be called inside another function or method in my_class.cpp

If you think "go to definition" shouldn't return multiple definitions (in some cases) then I would strongly encourage you to file an issue against the extension. Assume we implement "disablement" of peek by picking just one of many elements, how high is the change that the element we pick is the one you want? The "disablement" solution might always pick the wrong one, wrecking this feature for you.

I'm mostly looking to replicate the behavior from CLion (C++ IDE from Jetbrains). ctrl+b would move to the declaration/definition when used at a call site. When positioned over a definition/declaration, ctrl+b's semantics would change to switch between the declaration/definition. So to go to the declaration I'd just have to invoke ctrl+b a maximum of two times.

With VSCode, the peek editor pops up and I'm forced to use the arrow keys to get to the declaration/definition I need. As long as the amount of declarations/definitions isn't high (I'm thinking there are few cases where it would exceed 2), pressing ctrl+b again to get to the other declaration is a single keystroke whereas with the peek editor I have to navigate with the arrow keys to the right declaration which in my case with C++ is 5 keystrokes (4 to navigate + enter).

If the correct definition/declaration is chosen, the peek editor still pops up and I have to press a second keystroke (esc) to get it to disappear.

In short, I'd prefer to replace the peek editor with the Go To definition shortcut that navigates through the different declarations/definitions one by one. The order of declarations/definitions should be determined by the LSP extension used.

When positioned over a definition/declaration, ctrl+b's semantics would change to switch between the declaration/definition. So to go to the declaration I'd just have to invoke ctrl+b a maximum of two times.

Oh, I like that. We could be smarter there, esp when having two and being on one of them.

In short, I'd prefer to replace the peek editor with the Go To definition shortcut that navigates through the different declarations/definitions one by one.

Yes, that's what I have in mind and that's better than picking a single element. But also that isn't stateless and at least some status bar like 'At Definition 1 of 17' would be needed and a way to get out of this.

and a way to get out of this.

Can this be accomplished by just moving the cursor out of the declaration/definition name?

But also that isn't stateless

Depending on the exact definition of stateless, it seems stateless to me. The way I see it, given a list of definitions/declarations and the current definition where we're at, Go To Definition would simply move us to the next definition/declaration in the list. If we're at a call site, Go To Definition moves us to the first definition/declaration in the list.

The counter can then simply be the index of the current definition/declaration in the list.

at least some status bar like 'At Definition 1 of 17'

I'm not sure how many definitions/declarations we can realistically expect to have in a single list. I'm not sure if this would be used to cycle between virtual method implementations as well. If that's the case, the number could potentially be high and in that case a visual element telling at what definition we're at would definitely be useful.

Another thing that might be useful if the number of declarations/definitions is high is an option to open the peek editor since that's a scenario where it becomes really useful.

I feel like allowing disabling of the peek editor would be more of a workaround the problem instead of a real solution to the problem. The problem being that the UX around Go to Definition shouldn't use the peek editor, but a different mechanism.

Because of this I feel like my PR doesn't add much value and so I should abandon it. What do you think @jrieken ?

@hhu94 if i have component with enhancer export default withDeviceInfo(FilterVacanciesMain); and jumping on him, this window will seem to me

With https://github.com/Microsoft/vscode/issues/70032 I have added a new setting editor.gotoLocation.many with options peek, revealAndPeek, and reveal. The last option is very much related to this issue because it effectively disables peek and reveals the "first" result only.

I suggest "definition hierarchy" peek in another shortcut, as on Eclipse and some others.
This would prevent users from having to config to find a comfortable usage.

It's "editor.gotoLocation.multiple": "goto" now

It's "editor.gotoLocation.multiple": "goto" now

i use this but no reply

Remaining work for May, make F12 go to the next declaration/definition when invoked from within one, see https://github.com/microsoft/vscode/issues/53164#issuecomment-459005930

This is how it will look like

  • use 'goto' setting
  • trigger go to def, go to decl, go to implementation on a symbol with multiple results
  • the first is revealed, status message shows, hitting F12 cycles through them, hitting ESC or selection changes end this

May-23-2019 19-54-36

thank you for this

Thanks for the option, the peek window is a really annoying one which breaks my workflow because escape doesn't make it go away. I have to grab my mouse to get it out of the way which is not very user friendly. The other option is pressing enter, but only if you don't press escape 1st. Also the focus (choices) are shown on the right side of the preview, not the point where is was looking.

A simple popup with the filenames+line numbers as choices is better IMHO.

because escape doesn't make it go away

Well, the default is to hide on Esc. Do you use the editor.stablePeek setting by any chance?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukehoban picture lukehoban  Â·  3Comments

VitorLuizC picture VitorLuizC  Â·  3Comments

borekb picture borekb  Â·  3Comments

v-pavanp picture v-pavanp  Â·  3Comments

mrkiley picture mrkiley  Â·  3Comments