Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to make pum and signatureHelp floating window mutually exclusive #990

Closed
oblitum opened this issue Jul 17, 2019 · 25 comments
Closed
Labels
enhancement New feature or request

Comments

@oblitum
Copy link
Member

oblitum commented Jul 17, 2019

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I don't like too many floating windows covering big part of surrounding code.

Describe the solution you'd like
A clear and concise description of what you want to happen.

My wish is that I can have at a time only one of the windows open: pum for completion XOR signatureHelp window. I'm not sure this can be accomplished but the idea is that for when one of the two is going to be shown, it will call a command to hide the other.

Another thing to consider too in this context of options for how and which windows may be displayed regards the documentation window that's shown besides signatureHelp. Is there an option to disable it?

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

I'm currently using call coc#config('signature', {'preferShownAbove': v:false}) to great effect, since the side effect of showing signatureHelp bellow is that it causes most of time the pum to be hidden (because it also prefers to shown bellow), and vice-versa, making them mutually exclusive. But this does not work always, if I'm typing at the bottom of the window, pum most certainly will be shown above (because there's no room for it bellow), but signatureHelp will stay open bellow (because there was room for it), besides that, in fact, preferring signatureHelp bellow or above is a feature of its own which should not be confused with window hiding (reason why this happens).

@oblitum oblitum changed the title make pum and signatureHelp floating window mutually exclusive Option to make pum and signatureHelp floating window mutually exclusive Jul 17, 2019
@chemzqm chemzqm added the enhancement New feature or request label Jul 18, 2019
@oblitum
Copy link
Member Author

oblitum commented Jul 18, 2019

Was this fixed?

screencast

Also, it's a feature request for new options for controlling amount of windows open, not sure it can be fixed without adding an option.

@oblitum
Copy link
Member Author

oblitum commented Jul 19, 2019

This hasn't been fixed at all... :-(

@chemzqm
Copy link
Member

chemzqm commented Jul 19, 2019

You can use autocmd User CocOpenFloat to hide the popup, check w:popup for float window aside with pum and w:float for all float window.

@oblitum
Copy link
Member Author

oblitum commented Jul 19, 2019

Sounds cool, I tried this to check how it works but I never get any message:

autocmd vimrc User CocOpenFloat if exists('w:popup') | echom 'popup' | else | echom 'no popup' | endif | if exists('w:float') | echom 'float' | else | echom 'no float' | endif

I'm trying to understand when w:popup and w:float should be used, because I dunno any docs about them, but it seems CocOpenFloat is never being triggered.

@chemzqm
Copy link
Member

chemzqm commented Jul 19, 2019

It's a silent autocmd, can be improved.

@oblitum
Copy link
Member Author

oblitum commented Jul 19, 2019

No idea how to close (nvim_win_close) a previous floating window when w:popup exists since I don't have a window id.

Besides that, just a thought to make sure of behavior since I couldn't try it yet, I'm expecting this event is triggered before current popups/windows are displayed, to avoid any confusion on hiding the current ones (doesn't make sense to immediately hide something that just got displayed).

@chemzqm
Copy link
Member

chemzqm commented Jul 19, 2019

I don't have a window id.

You can iterate all windows

I'm expecting this event is triggered before current popups/windows are displayed

No, it's triggered just after float window displayed, it's neovim only, the current window id would be the opened float window, you can just check it.

@chemzqm
Copy link
Member

chemzqm commented Jul 19, 2019

doesn't make sense to immediately hide something that just got displayed

It's possible signature help shown after preview window of pum, so you might want to hide it.

@oblitum
Copy link
Member Author

oblitum commented Jul 19, 2019

OK, I'll try iterate.

it's neovim only

I think that could be put in CocOpenFloat docs. I was thinking of having to write two implementations until now.

@oblitum
Copy link
Member Author

oblitum commented Jul 19, 2019

I think CocOpenFloat needs to be triggered when pum will be shown, otherwise it seems not useful to fix the issue in the previous gif. I tried this:

autocmd vimrc User CocOpenFloat
\  if exists('t:previous_window') && nvim_win_is_valid(t:previous_window)
\|   call nvim_win_close(t:previous_window, v:false)
\|   unlet t:previous_window
\| endif
\  if exists('w:float')
\|   let t:previous_window = win_getid()
\| endif

It doesn't work because in the gif I was left with a signature floating window open and when started typing after it, completion pum shows up, without hiding signature, but pum display doesn't trigger CocOpenFloat, only floating windows do, so I can't hide that floating window with it.

@chemzqm
Copy link
Member

chemzqm commented Jul 19, 2019

I think CocOpenFloat needs to be triggered when pum will be shown,

No, it's fired on preview window open, all you need is check w:popup and close other window that has w:float and not current window.

@oblitum
Copy link
Member Author

oblitum commented Jul 19, 2019

The former problem is having signature floating window closed when a pum window gets open, for not having code covered both bellow and down. It was not about the preview window that's shown on completion selection, in the gif I didn't select anything at the end, but that's indeed an additional scenery I didn't think of, like the following:

18:38:42_19-07-2019

But it's not what I mentioned first. Here there's 3 windows floating (1 pum + 2 floating window), which can be reduced from 3 to 2, but initially I talked about reducing from 2 (1 floating down + 1 pum up) to 1 (pum XOR floating).

@chemzqm
Copy link
Member

chemzqm commented Jul 19, 2019

Use CompleteChanged autocmd.

@oblitum
Copy link
Member Author

oblitum commented Jul 19, 2019

oh, I didn't know about that event, it's not yet in my nvim docs. Finally, I think this is doing what I wanted:

autocmd vimrc User CocOpenFloat
\  if !exists('w:popup')
\|   let t:last_signature_help = win_getid()
\| endif

autocmd vimrc CompleteChanged *
\  if exists('t:last_signature_help')
\|   if nvim_win_is_valid(t:last_signature_help)
\|     call nvim_win_close(t:last_signature_help, v:false)
\|   endif
\|   unlet t:last_signature_help
\| endif

@oblitum
Copy link
Member Author

oblitum commented Jul 19, 2019

It works, but if you have any idea of something more simple or clean, I'd like to know about :)

@oblitum
Copy link
Member Author

oblitum commented May 3, 2020

Above solution won't work after 4e72e5b.

@oblitum
Copy link
Member Author

oblitum commented May 3, 2020

@chemzqm any tip how to achieve the same as above after the latest changes?

@chemzqm
Copy link
Member

chemzqm commented May 3, 2020


function! CloseOthers() abort
  if win_getid() == get(g:, 'coc_popup_id', 0)
    for i in range(1, winnr('$'))
      if getwinvar(i, 'float')
        let winid = win_getid(i)
        if winid != g:coc_popup_id
          call coc#util#close_win(winid)
        endif
      endif
    endfor
  endif
endfunction

@oblitum
Copy link
Member Author

oblitum commented May 3, 2020

@chemzqm thx. I'm calling that function at autocmd vimrc CompleteChanged * call CloseOthers() but it's not producing the desired effect, actually I'm not seeing any effect and I'm getting completion and float together as in the previous screenshot:

@chemzqm
Copy link
Member

chemzqm commented May 3, 2020

Use it with CocOpenFloat autocmd

@oblitum
Copy link
Member Author

oblitum commented May 3, 2020

@chemzqm Like as autocmd vimrc User CocOpenFloat call CloseOthers() ?

Still no effect.

@oblitum
Copy link
Member Author

oblitum commented May 3, 2020

Not sure whether you're following me here but I don't want both completion pum and signature help float open at the same time, that's why CompleteChanged was used before, because pum isn't a float window and hence doesn't trigger CocOpenFloat.

Tried this too but it didn't work either:

autocmd vimrc CompleteChanged * call coc#util#close_pum_float()

@oblitum
Copy link
Member Author

oblitum commented May 4, 2020

With this new api I can fix the problem and does what I'm requesting on this issue:

autocmd vimrc CompleteChanged * call coc#util#float_hide()

@oblitum
Copy link
Member Author

oblitum commented Dec 17, 2020

@jacobsandlund
Copy link

For anyone coming to this issue, the api has changed so you need to call:

autocmd CompleteChanged * call coc#float#close_all()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants