-
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 all 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
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,127 @@ | ||
============================================================================== | ||
LSP-SPECIFIC API *lsp-specific-api* | ||
|
||
parse_lsp_response({data}) | ||
|
||
Parses a LSP response (be it a String, MarkedString, Markdown segment, | ||
MarkupContent, ...; from hereon just {data}) to: | ||
|
||
- A |list| of |String|s that represent the "stripped" content. E.g. | ||
markdown `*bold*` strings will be converted to just `bold`, code | ||
blocks will have the markers removed, etc. It's the "plain-text, no | ||
colour" version of the {data}. | ||
|
||
- A |list| of |Dicts| that add colour to the plaintext. Each entry | ||
essentially says: highlight this character range using this Vim | ||
syntax group. Can be used for displaying stripped `*bold*` in a bold | ||
font, or to apply syntax highlighting to a region. | ||
|
||
Example of an entry: | ||
{ | ||
'range': { | ||
'start': { | ||
'line': 5, | ||
'character': 10 | ||
}, | ||
'end': { | ||
'line': 5, | ||
'character': 15 | ||
} | ||
}, | ||
'group': 'markdownBold' | ||
} | ||
|
||
|
||
============================================================================== | ||
TOP-LEVEL API *top-level-api* | ||
|
||
All the following functions take the same initial arguments: | ||
|
||
- {lines}: A |list| of |String|s that represents the plain-text content of | ||
the popup. | ||
- {syn-ranges}: A |list| of |dict|s, each representing a syntax highlight | ||
to be applied to the popup. See parse_lsp_response for more info. | ||
You can pass an empty |list| `[]` if you don't want any additional | ||
syntax highlighting (of course, the syntax of {filetype} still applies). | ||
- {filetype}: The |'filetype'| of the popup buffer. This determines the | ||
syntax highlighting of the entire buffer, which ftplugin is used, and so | ||
on. | ||
|
||
|
||
show_cursor_tooltip({lines}, {syn-ranges}, {filetype}, {options}) | ||
|
||
Shows a tooltip at the current cursor position, either above or below, | ||
depending on where there is enough space. | ||
|
||
The preview's content is set depending on {lines}, {syn-ranges} and | ||
{filetype}, see above. | ||
|
||
Returns the window ID of the created popup. | ||
|
||
{options} is a |dict| that can contain the following keys: | ||
TODO: possibly add some options or maxwidth, close_on_cursor_move, | ||
firstline, cursor_pos, cursor_alignment | ||
|
||
|
||
show_pum_tooltip({lines}, {syn-ranges}, {filetype}, {options}) | ||
|
||
Shows a tooltip associated with the currently selected item in the popup | ||
menu. It can be either to the left/right of the item, depending on where | ||
there is enough space. Settings from |'completepopup'| is taken into | ||
account. | ||
|
||
The preview's content is set depending on {lines}, {syn-ranges} and | ||
{filetype}, see above. | ||
|
||
Returns the window ID of the created popup. | ||
|
||
{options} is a |dict| that can contain the following keys: | ||
TODO: might not make sense to have options here, because everything is in | ||
'completepopup' already? | ||
|
||
|
||
update_pum_tooltip({winid}, {lines}, {syn-ranges}, {filetype}, {options}) | ||
|
||
Changes the content of the tooltip associated with the currently selected | ||
item in the popup menu. {winid} must be the value returned by | ||
`show_pum_tooltip`. | ||
|
||
For the meaning of {options}, see `show_pum_tooltip`. | ||
|
||
============================================================================== | ||
INTERMEDIATE-LEVEL API *intermediate-level-api* | ||
|
||
These functions will be backend specific (Vim popup/Nvim float). | ||
|
||
create_tooltip() | ||
|
||
Creates a hidden floating window, with undefined position, and an empty | ||
buffer associated with it. | ||
|
||
Returns the created window ID. | ||
|
||
|
||
set_tooltip_contents({winid}, {lines}) | ||
|
||
Updates the contents of a given floating window, and unhides it. Also | ||
retriggers size calculation. | ||
|
||
|
||
set_tooltip_position({winid}, {options}) | ||
|
||
Sets the position of the given floating window, be it cursor-relative, | ||
pum-relative, etc. Also retriggers size calculation. | ||
|
||
TODO: Which {options}? | ||
|
||
|
||
close_tooltip({winid}) | ||
|
||
Closes the tooltip with the ID {winid}. | ||
|
||
============================================================================== | ||
LOW-LEVEL API *low-level-api* | ||
|
||
To be determined. | ||
|
||
vim:tw=78:ts=4:ft=help:et |
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).