-
Notifications
You must be signed in to change notification settings - Fork 309
[WIP] Refactor neovim floats #509
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a10efb3
pull in PRs needed to test this
0f18974
refactor to avoid entering neovim float
45a3b4e
add missing documentation.vim (prev PR)
c2c5144
refactor get_size_info
cc4d0b7
typo
22c85ed
Initial version float-api
thomasfaingnaert 198755d
Add possible options
thomasfaingnaert 9603f3a
Add comment options pum
thomasfaingnaert 1a2c128
Document empty syn-ranges
thomasfaingnaert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
let s:use_vim_popup = has('patch-8.1.1517') && !has('nvim') | ||
let s:use_nvim_float = exists('*nvim_open_win') && has('nvim') | ||
|
||
let s:last_popup_id = -1 | ||
|
||
function! s:complete_done() abort | ||
" Use a timer to avoid textlock (see :h textlock). | ||
let l:event = deepcopy(v:event) | ||
call timer_start(0, {-> s:show_documentation(l:event)}) | ||
endfunction | ||
|
||
function! s:show_documentation(event) abort | ||
call s:close_popup() | ||
|
||
if !has_key(a:event['completed_item'], 'info') || empty(a:event['completed_item']['info']) | ||
return | ||
endif | ||
|
||
let l:right = wincol() < winwidth(0) / 2 | ||
|
||
" TODO: Neovim | ||
if l:right | ||
let l:line = a:event['row'] + 1 | ||
let l:col = a:event['col'] + a:event['width'] + 1 + (a:event['scrollbar'] ? 1 : 0) | ||
else | ||
let l:line = a:event['row'] + 1 | ||
let l:col = a:event['col'] - 1 | ||
endif | ||
|
||
" TODO: Support markdown | ||
let l:data = split(a:event['completed_item']['info'], '\n') | ||
let l:lines = [] | ||
let l:syntax_lines = [] | ||
let l:ft = lsp#ui#vim#output#append(l:data, l:lines, l:syntax_lines) | ||
|
||
let l:current_win_id = win_getid() | ||
|
||
if s:use_vim_popup | ||
let s:last_popup_id = popup_create('(no documentation available)', {'line': l:line, 'col': l:col, 'pos': l:right ? 'topleft' : 'topright', 'padding': [0, 1, 0, 1]}) | ||
elseif s:use_nvim_float | ||
let l:height = winheight(0) - l:line + 1 | ||
let l:width = l:right ? winwidth(0) - l:col + 1 : l:col | ||
let s:last_popup_id = lsp#ui#vim#output#floatingpreview([]) | ||
call nvim_win_set_config(s:last_popup_id, {'relative': 'win', 'anchor': l:right ? 'NW' : 'NE', 'row': l:line - 1, 'col': l:col - 1, 'height': l:height, 'width': l:width}) | ||
endif | ||
|
||
call setbufvar(winbufnr(s:last_popup_id), 'lsp_syntax_highlights', l:syntax_lines) | ||
call setbufvar(winbufnr(s:last_popup_id), 'lsp_do_conceal', 1) | ||
call lsp#ui#vim#output#setcontent(s:last_popup_id, l:lines, l:ft) | ||
let [l:bufferlines, l:maxwidth] = lsp#ui#vim#output#get_size_info(getline(1, '$')) | ||
|
||
call win_gotoid(l:current_win_id) | ||
|
||
if s:use_nvim_float | ||
call lsp#ui#vim#output#adjust_float_placement(l:bufferlines, l:maxwidth) | ||
call nvim_win_set_config(s:last_popup_id, {'relative': 'win', 'row': l:line - 1, 'col': l:col - 1}) | ||
endif | ||
endfunction | ||
|
||
function! s:close_popup() abort | ||
if s:last_popup_id >= 0 | ||
if s:use_vim_popup | call popup_close(s:last_popup_id) | endif | ||
if s:use_nvim_float | call nvim_win_close(s:last_popup_id, 1) | endif | ||
|
||
let s:last_popup_id = -1 | ||
endif | ||
endfunction | ||
|
||
function! lsp#ui#vim#documentation#setup() abort | ||
augroup lsp_documentation_popup | ||
autocmd! | ||
autocmd CompleteChanged * call s:complete_done() | ||
autocmd CompleteDone * call s:close_popup() | ||
augroup end | ||
endfunction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Now that we're not focusing the float, this would apply to the main buffer, I believe.
Uh oh!
There was an error while loading. Please reload this page.
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.
Ah, you're right. Didn't notice that. How weird...But even without that line, I get strange styling of the main buffer whenever a float is open (color changes in the status bar).