OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.72k stars 168 forks source link

neovim: Reset buffer options to the previous state after closing popup window #739

Closed DasOhmoff closed 3 years ago

DasOhmoff commented 3 years ago

Hello, thank you for your help.

In my vim config I set the following line:

let OmniSharp_popup_options = {'wrap': v:true, *etc*}

These options get set when the popup window gets opened. The problem is that these options don't get reset back again after the popup window gets closed. This causes issues when f.e previewing definitions, etc. Is there a way to reset these options after the popup window gets closed?

Steps to reproduce.

  1. Set in your config:
    "Example option
    let OmniSharp_popup_options = {'wrap': v:true}
    set nowrap
  2. Open a C# file and put your cursor above a method call that you defined in your project. The definition of the method should be in another file.
  3. Use <plug>(omnisharp_preview_definition) to open up a preview popup window. Now wrapping gets applied in the preview window.
  4. Close the preview window
  5. Use <plug>(omnisharp_go_to_definition) to open up the file
  6. Execute :set wrap? to see that the wrapping of the text is still applied, even after the popup window got closed

My vim configuration automatically saves the layout of the window through the command autocmd BufWinEnter ?* mkview! as well, making it even more complicated, because now theses options persist throughout sessions and restarts.

I looked through the source code, and noticed the following line, maybe that is a good starting point to somehow achieve this goal: https://github.com/OmniSharp/omnisharp-vim/blob/e847eccc7d1f39ea660a20743cd87c96156cbb6a/autoload/OmniSharp/popup.vim#L202 It seems that the options are getting set there.

nickspoons commented 3 years ago

I don't see this behaviour:

asciicast

Is it possible that your buffer/session handling config is doing this?

nickspoons commented 3 years ago

Ah, sorry I re-read your description and see what you mean now. It's the window which is previewed which has these settings applied:

asciicast

It's even more clear in this screen cast where I also have let g:OmniSharp_popup_options = { 'winhl': 'Normal:NormalFloat' }

nickspoons commented 3 years ago

@DasOhmoff would you be able to test out PR #741 and see if this resolves the issue for you?

DasOhmoff commented 3 years ago

Yes. I did.

It indeed seems to have fixed the issue with the wrapping. But weirdly enough it doesn't seem to be restoring some other settings. For example line numbers still don't get restored, they are still off. (I always turn them on by default through my vim config)

nickspoons commented 3 years ago

OK, that sounds like an issue with window-local/buffer-local/global options. I'll have to look into what information neovim makes available.

I'm just going to change the issue title to make it clear that this is a neovim-specific issue.

nickspoons commented 3 years ago

@DasOhmoff it turned out not to be a local/global option, but a floating window config option which we were using in a way that appeared to be consistent with the recommendations from the help, but reduces how much control we have over options like 'number':

nvim_open_win({buffer}, {enter}, {config})                   *nvim_open_win()*
  …
  {config}  Map defining the window configuration. Keys:
    …
    • `style`: Configure the appearance of the window.
      Currently only takes one non-empty value:
      • "minimal" Nvim will display the window with
        many UI options disabled. This is useful
        when displaying a temporary float where the
        text should not be edited. Disables
        'number', 'relativenumber', 'cursorline',
        'cursorcolumn', 'foldcolumn', 'spell' and
        'list' options. 'signcolumn' is changed to
        `auto` and 'colorcolumn' is cleared. The
        end-of-buffer region is hidden by setting
        `eob` flag of 'fillchars' to a space char,
        and clearing the |EndOfBuffer| region in
        'winhighlight'.

I've pushed a change to the PR which removes it, but I don't know if this will cause other unexpected behaviour. Would you give it a spin?

DasOhmoff commented 3 years ago

Thank you for your efforts. Yes. I tried it out. It seems to be working, the options don't get changed.

The only issue now is that commands like OmniSharpDocumentation and OmniSharpSignatureHelp (which show the popup window) also show line numbers, etc. So if one enables in his config line number f.e, they also get shown in the popup window.

nickspoons commented 3 years ago

I suppose that's what that "style": "minimal" option is all about, displaying popup content in a simplified way.

Perhaps the correct way forward is to keep "style": "minimal" as we had before for displaying non-buffer content (documentation and signature help), and drop it for "buffer" popups such as previews?

nickspoons commented 3 years ago

I pushed a commit to the PR, tell me how that goes

DasOhmoff commented 3 years ago

I think it is working very well. I was not able to spot any issues :)