-
Notifications
You must be signed in to change notification settings - Fork 306
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
preview information shown in hover at the cursor #395
preview information shown in hover at the cursor #395
Conversation
Strage, I'll have to look into it as width and height are determined by first using all available space and then shrinking it to the actually required space.
Already thought about that myself! Something like (lsp-focus-hover) or (lsp-hover-focus)?
It does stay open when using the mouse if in focus. At least for me =(
This is currently not possible as far as I can see, as floating windows is a neovim unique feature.
Diagnostics is a nice idea! As soon as I worked out the quirks with this PR, I'll work on that. |
Integrated vim8.1 popup feature (thanks to @mattn). vim8.1 popups are very much crippled in comparison to neovim floats, as there is no focus and/or keyinput available for popup-windows. Therefore keeping focus and copy using the keyboard and scrolling won't be possible in the current implementation of popup-windows. Features like keeping it open and having dedicated closing mappings will be possible for both vim8 and nvim. |
Implemented focus and close for floating nvim windows. Vim8.1 still gives me quirks for close (telling me the window is no popup window...), which have to be investigated further. Added an option to disable automatic closing of floating windows (nvim only currently, when I fix above mentioned bugs, I'll do that for vim8.1 as well) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great and seems to work both in vim8 and neovim. @mattn Can you also have a look at this PR.
- Can we request vim to add support for focusing on popup so I can navigate on large hovers? Otherwise it doesn't become so useful for these scenarios. My primary reason for this is because I do work on lot of other projects and it is very useful scroll through the docs inline in the editor. One workaround is to have a binding for floating window to force preview window.
- I don't use neovim as the primary editor but would be good to have request on neovim to add support for borders.
As for autocomplete I don't think we need to worry about it yet. Hopefully completeopt+=popup
will solve this (vim/vim#4544) as I definitely don't want to be having two codepath to support both vim-lsp omnifunc and asyncomplete.vim
I personally would like to map |
autocmd sounds great. Implemented. |
Guess we should open a request. Could not find something similar in a quick scan.
There is already a feature request for neovim to implement it (and when I remember correctly somebody is working on it). Have to search for it later. |
@jerdna-regeiz could you resolve the merge conflicts? |
sure. Had to first figure out why closing a popup was a problem in vim 8.1... |
91128e9
to
71ae724
Compare
Added a imo cool feature to have a doubetap on the preview. |
Is there anything that I should try to include into this pull request? Following features are still in my mind, but I guess they should be handled in a separate PR:
|
This is great. Thanks for the PR. It is not merged in master. |
Floating window for neovim always located top left corner, is it by design or a bug? |
Great feature, thanks! One question: Is it meant/possible to have multiline boxes with automatic linewrapping? One language server returns a single, long, line on a specific hover, and most of that is truncated now. |
@clason If you're using Vim, something like this should work: diff --git a/autoload/lsp/ui/vim/output.vim b/autoload/lsp/ui/vim/output.vim
index 7b52f4c..ebcdfeb 100644
--- a/autoload/lsp/ui/vim/output.vim
+++ b/autoload/lsp/ui/vim/output.vim
@@ -116,6 +116,7 @@ function! lsp#ui#vim#output#floatingpreview(data) abort
let s:winid = popup_atcursor('...', {
\ 'moved': 'any',
\ 'border': [1, 1, 1, 1],
+ \ 'maxwidth': 80
\})
endif
return s:winid I'll see if I can create a PR for this as well. |
I'm using neovim (latest master), sorry, should have mentioned this. |
@clason I think Neovim uses a different API, so you may want to check the help. I'm actually compiling Neovim at the moment, so I'll be able to check in couple minutes. |
@clason diff --git a/autoload/lsp/ui/vim/output.vim b/autoload/lsp/ui/vim/output.vim
index 7b52f4c..7e32491 100644
--- a/autoload/lsp/ui/vim/output.vim
+++ b/autoload/lsp/ui/vim/output.vim
@@ -99,6 +99,7 @@ function! lsp#ui#vim#output#floatingpreview(data) abort
" Try to get as much pace right-bolow the cursor, but at least 10x10
let l:width = max([s:bufwidth(), 10])
let l:height = max([&lines - winline() + 1, 10])
+ let l:width = min([l:width, 80])
let l:opts = s:get_float_positioning(l:height, l:width) |
Bug. Should be at the cursor. Can you provide a minimal config where it happens, as I can't reproduce it. |
Neovim uses real buffers, thus we can enable soft line wrap in the buffer/window. |
No, sorry, that just shifts the floating window to the right? From the documentation ( let buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(buf, 0, -1, v:true, ["test", "text"])
let opts = {'relative': 'cursor', 'width': 10, 'height': 2, 'col': 0,
\ 'row': 1, 'anchor': 'NW'}
let win = nvim_open_win(buf, 0, opts) |
Found that |
Ahh have not checked that for quite some time. I'll try it later |
@clason Hmm, I don't have a language server with sufficiently long hovers, so I tested with max_width = 10 in |
I tested maxwidth=10 as well; this truncates correctly, but doesn't wrap (or maybe it does, the point is that it's still a single line high). But I'll open a new issue, no problem. (The vim fix works, by the way.) |
Yes, that works nicely, thank you very much! |
Fixed in #419 |
#419 is merged. |
@jerdna-regeiz I'm trying to refactor your code to avoid entering the buffer on float creation, and I'm running into a few issues. Do you have time for talking about this a bit? |
Sure. What questions do you have? |
That's pretty much it; my changes break hover (but only on the first line of the buffer) and preview (if the preview contains too many lines). Maybe I'll create a WIP preview and ask for your suggestions? |
@jerdna-regeiz my WIP PR is at #509, would appreciate any comments. |
Uses floating window support of nvim 0.4.0 to show hover information in an unobtrusive way.
Implemented it and then found #347 . While it is good work I did create a pull request anyway as I saw some flaws in other request.
Thought about commenting on #347, but the last activity has been some time.
My approach does not aim at only hover, but at preview (yeah I know only hover uses it).
It is Implemented such that most of the code for preview is used, including "text rendering",
filetype/syntax and the option for keeping focus.
If the hover is not focused, it is closed on cursor move. If it is focused, it may be closed with
, which is only mapped in the scratch buffer.
This makes it a lot less obstusive and does not intrude the workflow.
As #347 seems to stand still currently, I offer to create any fusion of the two approached which
works best and fits the most with vim-lsp. So any comment is welcome.