Skip to content

Conversation

thomasfaingnaert
Copy link
Collaborator

@thomasfaingnaert thomasfaingnaert commented Sep 12, 2019

Uses the hover logic to display documentation in the popup/floating window (like completeopt+=popup, but with Markdown capabilities).

Vim:
vim

Neovim:
nvim

TODO:

  • Cleanup Neovim window
  • Neovim positioning
  • Use completeopt+=popup positioning logic for Vim (?)
  • Allow disabling

@clason
Copy link
Contributor

clason commented Sep 12, 2019

I think the logic for nvim positioning can be cribbed pretty much wholesale from https://github.com/ncm2/float-preview.nvim/blob/c5431b6d9bd4a8002f1a3eec42e9458ef4453ff3/autoload/float_preview.vim#L122

Bonus points for attaching the popup at the selected completion item rather than the top!

@thomasfaingnaert
Copy link
Collaborator Author

Bonus points for attaching the popup at the selected completion item rather than the top!

Should be easy if we can get the selected index of the popup menu, but I'm not sure if there is a way to do that.

@clason
Copy link
Contributor

clason commented Sep 12, 2019

I don't think so either; one could listen for cursor movements and keep track of the position oneself, but that seems fraught with complications.

Probably something neovim has to do using internal information, like vim does. Sounds like a reasonable feature request to expose this, though?

@clason
Copy link
Contributor

clason commented Sep 12, 2019

I think there should be a check for empty Definition -- it's showing a float even if there is no such information.

(It's also really slow for me -- but so is preview, so that's no big deal. float-preview.nvim is significantly faster, though -- do you have any idea why that could be the case? The implementation doesn't look too different.)

@thomasfaingnaert
Copy link
Collaborator Author

@clason
Copy link
Contributor

clason commented Sep 12, 2019

Ah, so the preview is not triggering on every CompleteChanged? But it's fast even though it shows a preview for every item as I go down the list...

@thomasfaingnaert
Copy link
Collaborator Author

Probably something neovim has to do using internal information, like vim does. Sounds like a reasonable feature request to expose this, though?

What would be even better is if we have a way to customize the popup that Vim show using completeopt. Then we would automatically have the correct positioning, and there's an option to place it at the currently selected item.

That may be possible, actually. What if I set completeopt correctly, and then in my CompleteChanged handler iterate over all windows/buffers, I think I can get the one where 'preview' is set. Do you think this is worth exploring?

@thomasfaingnaert
Copy link
Collaborator Author

Ah, so the preview is not triggering on every CompleteChanged? But it's fast even though it shows a preview for every item as I go down the list...

It is, but a previous request is cancelled whenever you change the currently selected item. Do you experience the slowdown when selecting different items quickly, or also when you do it slower?

@clason
Copy link
Contributor

clason commented Sep 12, 2019

It is, but a previous request is cancelled whenever you change the currently selected item. Do you experience the slowdown when selecting different items quickly, or also when you do it slower?

Yes; it takes a second or two to update the preview float (blocking input).

That may be possible, actually. What if I set completeopt correctly, and then in my CompleteChanged handler iterate over all windows/buffers, I think I can get the one where 'preview' is set. Do you think this is worth exploring?

Hmm, maybe create the preview buffer before creating the float and then passing that to open_window? Then you'd know the buffer ID beforehand.

(Also, maybe setting style='minimal' instead of manually unsetting number` etc. helps ?)

@clason
Copy link
Contributor

clason commented Sep 12, 2019

If there's no Description, I now get the error

Error detected while processing function <lambda>431[1]..<SNR>153_show_documentation[41]..l
sp#ui#vim#output#adjust_float_placement:
line    6:
E5555: API call: 'width' key must be a positive Integer

@thomasfaingnaert
Copy link
Collaborator Author

Hmm, maybe create the preview buffer before creating the float and then passing that to open_window? Then you'd know the buffer ID beforehand.

(Also, maybe setting style='minimal' instead of manually unsetting number` etc. helps ?)

I rather meant not calling open_window and popup_create at all, but letting Vim's completeopt+=preview handle that.

Then we can use that window (already correctly positioned) and set the content ourselves.

Ideally, we should just be able to use a buffer for a completion item's 'info' field. Might be worth creating an issue at Vim for this, or do you think this would be out of scope?

(Of course, creating a buffer for each completion item is extremely unnecessary. If something like this would be implemented in Vim, we should have a way to provide this buffer on-demand. This would immediately also implement the completionItem/resolve)

@clason
Copy link
Contributor

clason commented Sep 13, 2019

I think I have it almost working now, but for two issues:

  1. Preview floats contents are right-aligned (meaning the start is cut off rather than the end if the contents don't fit the screen)
  2. It doesn't show for large PeekDefinition.

Maybe I should open a PR about it so we can discuss there?

@thomasfaingnaert
Copy link
Collaborator Author

Sounds good; the thing is that I'm not really familiar with nvim's API. Most of my knowledge comes from just reading output.vim. One thing that immediately catched my eye was that s:adjust_float_placement is only used for Neovim, so that's why I'm guessing that in Neovim you have to position and size the floats yourself.
Anyway, mirroring Vim's popup_create-arguments would be nice (if that's doable at least).

@prabirshrestha
Copy link
Owner

Not required for this but how would function overload pop up work?

@thomasfaingnaert
Copy link
Collaborator Author

thomasfaingnaert commented Sep 13, 2019

@prabirshrestha
You love making things more complicated, don't you :p
I've made an issue at Vim to expand the API for info popups at vim/vim#4924, could you take a look at it and share your thoughts?
With the extra function complete_set_popup, overloads would be possible too, I suppose, provided we have a way to catch keypresses: just call complete_set_popup again if the user pressed <up> and <down>.

@prabirshrestha
Copy link
Owner

vim-lsp is already taken so can't create it.

I created one in discord instead. Here is the invitation link that lasts for 1 day. https://discord.gg/zpvutT

@clason
Copy link
Contributor

clason commented Sep 14, 2019

@prabirshrestha I think you can ask github to transfer the organization since the current owner is not doing anything with it -- if you want.

@prabirshrestha
Copy link
Owner

@clason We had asked that before, they do have private repos that are active.

@clason
Copy link
Contributor

clason commented Sep 14, 2019

Ah, OK, that's all right then. Thanks for letting me know!

@thomasfaingnaert
Copy link
Collaborator Author

Do you need an organisation for gitter? I think you can create prabirshrestha/vim-lsp as well.

@thomasfaingnaert
Copy link
Collaborator Author

@prabirshrestha Any update on gitter?

@clason
Copy link
Contributor

clason commented Sep 28, 2019

@thomasfaingnaert Yes, that should work -- the (short-lived) chatroom I mentioned was called clason/vim-lsp and connected to my fork.

@prabirshrestha
Copy link
Owner

I actually own this org https://github.com/vimlsp. The one without dash. So finally was able to create this. https://gitter.im/vimlsp/community.

Let me know if you want to create specific rooms. In the meantime I created https://gitter.im/vimlsp/setup for those that want to ask how to setup servers.

@prabirshrestha
Copy link
Owner

@thomasfaingnaert any updates on this?

@prabirshrestha
Copy link
Owner

@thomasfaingnaert any updated on this? Would be also good to fix merge conflicts.

@thomasfaingnaert
Copy link
Collaborator Author

@prabirshrestha I haven't had the time to work on this, unfortunately. I'll try to pick this up again in the summer.

@prabirshrestha
Copy link
Owner

@thomasfaingnaert do you have the branch with completionItem/resolve support that you pushed? Would be good to have a look into it too.

@prabirshrestha
Copy link
Owner

In the meantime doc-popup branch contains the merge conflict fixes.

@thomasfaingnaert
Copy link
Collaborator Author

@thomasfaingnaert do you have the branch with completionItem/resolve support that you pushed? Would be good to have a look into it too.

I don't think I have that branch still around, unfortunately. IIRC, there was not much to it: store the completion items in a list, and update the current completion item in that list on CompleteChanged.

for l:entry in a:data
call s:append(l:entry, a:lines, a:syntax_lines)
call lsp#ui#vim#output#append(entry, a:lines, a:syntax_lines)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[vint] reported by reviewdog 🐶
Make the scope explicit like l:entry (see Anti-pattern of vimrc (Scope of identifier))

@prabirshrestha
Copy link
Owner

@thomasfaingnaert no worries. Just wanted to know if there was support so I can review. For now will review the current one with latest fix and merge and can support completionItem/resolve later. Ideally it would had been good if neovim supported completeopt+=popup. This would had reduce lot of our logic.

Thanks for this PR.

@prabirshrestha prabirshrestha merged commit a3673dd into master Jun 20, 2020
@prabirshrestha prabirshrestha deleted the popup-documentation branch June 20, 2020 19:21
LumaKernel pushed a commit to LumaKernel/vim-lsp that referenced this pull request Aug 4, 2020
* Show documentation in Vim popup

* Use timer

* Reuse logic from output.vim

* Change default text

* Rename functions

* Refactor

* Use v:event

* Add comment

* Remove log

* Refactor

* Implement documentation in Neovim

* Cleanup Neovim popup

* Let Neovim float take all available space

* Extract get_size_info

* Reuse sizing logic from output.vim

* Fix Neovim positioning being reset

* Update autoload/lsp/ui/vim/documentation.vim

Co-Authored-By: Christian Clason <christian.clason@uni-due.de>

* Make vint happy

* Retrigger Travis CI

* add g:lsp_documentation_float flag

* fix lint issues

Co-authored-by: Christian Clason <christian.clason@uni-due.de>
Co-authored-by: Prabir Shrestha <mail@prabir.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants