neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.33k stars 956 forks source link

The documentation popup is always in the way #2233

Closed WhyNotHugo closed 4 years ago

WhyNotHugo commented 4 years ago

Result from CocInfo

## versions

vim version: NVIM v0.4.4
node version: v14.7.0
coc.nvim version: 0.0.78-0ff42027ff
coc.nvim directory: /home/hugo/.homesick/repos/dotfiles/home/.config/nvim/plugged/coc.nvim
term: alacritty
platform: linux

## Output channel: rls

Setting sysroot to/home/hugo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu
running: rustup run stable-x86_64-unknown-linux-gnu rls, at /home/hugo/workspace/IdeasEnFoto/sync-tool

Describe the bug

The popup that shows documentation on a function shows very useful information, but it always gets in the way.

It's useful to see the docs for a function, but since I can't see the code I'm working on, I have to close it. Basically, we can see documentation XOR code.

Is there a way to show this elsewhere on the screen? Since the doc covers surrounding code, I've no way of checking the names of variables, or other contextual stuff. Imagine if Vim hides surrounding lines when you enter edit mode. :disappointed:

I recall many years ago using a plugin that use a window similar to Vim's help window on the top of the screen for these things (maybe omnicomplete...?). Maybe something like that can be used instead?

I've checked past issues and the wiki, but can't find anything related.

Example: 2020-08-07T22:28:29,207401674+02:00 ☝️ Can't figure out what variable I want to push() here, since I can't see the code while the docs are visible.

Completing the below details, but I feel this is more of a usability issue, not a crash-like bug.

Reproduce the bug

Nothing crazy needs to be done, just use any engine that provides auto-completion with documentation.

Screenshots (optional)

See above.

WhyNotHugo commented 4 years ago

I though coc.preferences.hoverTarget might be relevant, but it has no effect on this.

"suggest.floatEnable": false also doesn't seem to change anything here.

WhyNotHugo commented 4 years ago

Oh, I figured out that signature.target is the relevant setting here. But it only supports float and echo.

echo is useless, since it's just one line: 2020-08-07T23:06:07,536702247+02:00

Is it possible to use preview here like with other settings?

chemzqm commented 4 years ago

Is it possible to use preview here like with other settings?

no

oblitum commented 4 years ago

@WhyNotHugo you can substantially reduce noise by setting signature.preferShownAbove to false.

oblitum commented 4 years ago

@WhyNotHugo Additionally, I prefer to ensure just completion xor signatureHelp/docs is open on a given time, so I do autocmd vimrc CompleteChanged * call coc#util#float_hide(). With these two settings I have either one or the other open (not all at once), with preference to float them bellow, not up. See #990 for more info on this and how you can control displayed windows further.

WhyNotHugo commented 4 years ago

completion xor signatureHelp/docs

My issue isn't about completion vs docs, my problem is seeing the actual file I'm editing and the docs. completion is unrelated here.

@WhyNotHugo you can substantially reduce noise by setting signature.preferShownAbove to false.

The docs still cover up the code and make it impossible to read:

2020-08-08T00:11:59,935406180+02:00

WhyNotHugo commented 4 years ago

@chemzqm Really? Any chance this can be reconsidered? The docs are kinda useless in "floating" mode, since they cover up code.

For many compex functions, I end up having to open docs in a browser window half the time, since I need to see code & docs at the same time.

What's the blockage in using the preview window? There seems to be no workaround here, and preview is used for a bunch of other stuff. :disappointed:

oblitum commented 4 years ago

@WhyNotHugo as I said, I just meant to reduce the case, not completely provide an alternative. This is the norm here, three floats covering lots of code area, and as I explained on #990, I wished to reduce that to just one at a time at least, and it was attained as I explained. Personally I still prefer to have docs/signatureHelp close to the cursor, most IDEs will do that, it avoiding moving your eyes too much and losing context. If you look it up, on neovim you can have faux transparency, that's also another option for you.

WhyNotHugo commented 4 years ago

Personally I still prefer to have docs/signatureHelp close to the cursor, most IDEs will do that

I don't know why most IDEs think that concealing the user's code to show the docs is a good idea, but, then again, most other IDEs are complete crap.

What I find myself doing all day, every day, is just having a browser window with the docs on another screen, however, the fact that the IDE can find the right doc contextually is a huge timesaver. The fact that I can't see the docs and my code at the same time, make the whole feature useless.

I'd just like to stop wasting time all day opening docs in browser windows. Seems that coc can find the right docs, but refuses to let me see it while keeping the current file on-screen.

WhyNotHugo commented 4 years ago

@chemzqm Do you have any potential workaround here?

chemzqm commented 4 years ago

@WhyNotHugo it's function signature, not doc. You can use "signature.target": "echo"

WhyNotHugo commented 4 years ago

Yes, correct, signature window, not docs (though it includes all the documentation for the function as well for Python and Rust, and that's the part that's really useful).

"signature.target": "echo" results in me getting just this in the status line:

image

This is completely useless, it lacks any the relevant information, since it just shows the first line (which includes no useful information).

oblitum commented 4 years ago

If you look it up, on neovim you can have faux transparency, that's also another option for you.

For anyone that's interested in that:

set pumblend=20: 19:44:28_07-08-2020

autocmd vimrc User CocOpenFloat call setwinvar(g:coc_last_float_win, "&winblend", 20): 19:46:05_07-08-2020

oblitum commented 4 years ago

IIRC YCM provides you with preview window docs, because originally it was the only thing available in vim for this kind of thing, and it was kinda horrid indeed as it's intrusive at messing up window layout when you have more than one window open.

WhyNotHugo commented 4 years ago

IIRC YCM provides you with preview window docs, because originally it was the only thing available in vim for this kind of thing, and it was kinda horrid indeed as it's intrusive at messing up window layout when you have more than one window open.

Personally, I find that a lot more useful. While not aesthetically the best (and I remember the issues of windows getting shuffled around), having two layers of transparent text super-suposed is a far worse solution. I can't think of any other scenario where having two layer of text one on top of the other with transparency involved.

If you like that, that's fine, but I can't see what the impediment to supporting previewhere is. Things like hoverTarget support "float", "echo", "preview" already.

I'm generally quite happy with CoC, but jumping into a new language, I could strongly use having in-IDE documentation, and that's really a missing feature right now.

Floating windows are the worst things that's happened to Vim, and (while very pretty-looking) have terrible usability.

oblitum commented 4 years ago

@WhyNotHugo nothing to do with what I like, I'm just presenting options here, for anyone that lands here in the future and can pick whatever it finds best.

One easy route of preview-like implementation, instead of actually using preview, is to provide fixed positional floats, like this: https://github.com/ncm2/float-preview.nvim. So it would be, possibly, just offering an option to have the floats in fixed positions in corners of the parent window. The effect would be mostly the same as using preview window (or even better, no shuffling).

oblitum commented 4 years ago

Floating windows are the worst things that's happened to Vim, and (while very pretty-looking) have terrible usability.

Disagree.

WhyNotHugo commented 4 years ago

Disagree.

I just don't get the point. Why would somebody ever want the docs/signature to cover up the code you're working on? How do you actually use this day to day? To you memorise all the code around, and they type with the doc open, or do you memorise the docs and the continue with the code visible? Wouldn't you rather have both? We've such big screens nowadays! :joy:

One easy route of preview-like implementation, instead of actually using preview, is to provide fixed positional floats, like this: https://github.com/ncm2/float-preview.nvim. So it would be, possibly, just offering an option to have the floats in fixed positions in corners of the parent window. The effect would be mostly the same as using preview window.

I was just looking at the neovim docs trying to figure out if the API would let me move the window to a corner like that. That link looks perfectly on spot. However... it doesn't seem to work. It just, doesn't do anything. I wonder if there's anything special about coc's floating windows. :disappointed:

I still think it's a shame that some features support target = "preview", but this particular one doesn't.

WhyNotHugo commented 4 years ago

@chemzqm Any hints on any potential workarounds for this issue?

How have you set up this feature so that it works for you?

oblitum commented 4 years ago

I just don't get the point. Why would somebody ever want the docs/signature to cover up the code you're working on?

Simple, you stated that a general feature is the worst thing to have happened at the face of earth. It's not, it's a general feature that can have many uses, including replacing previewwindow, and improving upon it, like avoiding window shuffling. This feature is being used for many purposes besides this single application.

And when I mentioned about possible implementation, I meant as possibly provided by coc, not that you would set it up manually (even though I think it is quite possible, you can even pick one of the snippets I've used to tweak window blend above to change other window characteristics).

WhyNotHugo commented 4 years ago

You mean, using autocmd vimrc User CocOpenFloat call setwinvar(g:coc_last_float_win, "&winblend", 20): as a reference?

That seems like a great lead for someone who's familiar with the internals for coc and neovim to code a solution, but I'm merely a user here.

I'm not familiar with the internals of either. Heck I haven't even been able to find the docs for a function to reposition or resize floating windows, let alone.

While saying "the code is all there" is quite accurate, the reality is that many of us just use the tools and don't know how all the codebase works.

chemzqm commented 4 years ago

Fixed by 7612f0b2

WhyNotHugo commented 4 years ago

This seems to work:

autocmd User CocOpenFloat call nvim_win_set_config(g:coc_last_float_win, {'relative': 'editor', 'row': 0, 'col': 0})
autocmd User CocOpenFloat call nvim_win_set_width(g:coc_last_float_win, 9999)
WhyNotHugo commented 4 years ago

Oh, you beat me to it! Thanks!

WhyNotHugo commented 4 years ago

Works like a charm! Many thanks! :sparkles:

oblitum commented 4 years ago

Good that it landed on coc, but your snippet is also useful as reference for anyone interested in further customization.

oblitum commented 4 years ago

@WhyNotHugo also, now that you can test either real previewwindow or the custom preview trick, I'm just curious which one you found nicer :)

WhyNotHugo commented 4 years ago

Hacking the preview window position turns out to look a wee bit nicer, due to how markdown is formatted (triple-backticks are hidden).

However, there's an issue with scrolling where it lets me scroll way past the end of the content. My guess is that it's related to how I've hacked the size/position, but not entirely sure. :thinking:

I did notice that, with both approaches, sometimes the first line of the signature is missing (ironically, in this case it's the important line). I haven't been able to figure out a pattern to when this happens, so it's not worth reporting yet.

Missing when the function is selected: 2020-08-08T02:51:32,644352800+02:00

Present when the parenthesis is added: 2020-08-08T02:51:44,153560492+02:00

oblitum commented 4 years ago

Seems scrolling related, you may possibly grab information from here on how to control/tweak that: https://github.com/neoclide/coc.nvim/issues/1405#issuecomment-626998607.

her commented 3 years ago

Maybe a dumb question, but why not just a toggle in insert mode to show/hide the signature / docs ?

Is there anything like that @chemzqm @oblitum

Thanks y'all!

chemzqm commented 3 years ago

No, I don't like that kind of surprise, you can tell coc.nvim to trigger.

gallor commented 3 years ago

@chemzqm I see the update for the "signature.target" for preview got released in v0.79 but I'm still seeing it float when I use "preview" for the value (and Coc gives the error "Value is not accepted. Valid values: "float", "echo"). Running on v0.80 on vim 0.4.4. Anything I need to do to enable this? Thanks.

chemzqm commented 3 years ago

No preview option for signature target.

gallor commented 3 years ago

Sorry for my confusion then but if there's no preview option for signature target why do the release notes say Support preview for signature.target, and your code for https://github.com/neoclide/coc.nvim/commit/7612f0b2cd5715c993494a4f28707e3a7193e6d3 looks like updates specifically for signature.target. Is it just not exposed to the configs or is that code for something completely different? Thanks!

yebt commented 3 years ago

Hi, i had the same problem, so i read the coc's functions documentation and i found coc#_hide(), with this function i remap: inoremap <expr> <ESC> pumvisible() ? "\<C-o>coc#_hide()" : "<ESC>"

kalyan2012 commented 2 years ago

How to change it to only show documentation on a shortcut keypress? So that I don't need to get distracted by documentation of common functions. And can get documentation for required functions.

misraelson commented 2 years ago

@kalyan2012

" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
misraelson commented 2 years ago

This seems to work:

autocmd User CocOpenFloat call nvim_win_set_config(g:coc_last_float_win, {'relative': 'editor', 'row': 0, 'col': 0})
autocmd User CocOpenFloat call nvim_win_set_width(g:coc_last_float_win, 9999)

Out of curiosity, wow would you write this for regular vim, not nvim? Thanks!

casonadams commented 2 years ago

Maybe you can try this.

Disable auto popup Add key binding to trigger the popup

config:

    "diagnostic.enableMessage": "never",
    "diagnostic.checkCurrentLine": true,

mapping: nmap <silent> gl <Plug>(coc-diagnostic-info)

Then on lines with errors gl will show the pop up window.