Skip to content

Commit 40b5349

Browse files
committed
Support option variables
1 parent 5a93f51 commit 40b5349

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

autoload/lsp/ui/vim.vim

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,12 @@ function! s:handle_location(ctx, server, type, data) abort "ctx = {counter, list
509509
else
510510
let l:lines = readfile(fnameescape(l:loc['filename']))
511511
if has_key(l:loc,'viewstart') " showing a locationLink
512-
let l:view = l:lines[l:loc['viewstart'] : l:loc['viewend']]
513-
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
514-
call s:floatwin.show(l:screenpos, lsp#utils#normalize_markup_content({
515-
\ 'language': &filetype,
516-
\ 'value': join(l:view, "\n")
517-
\ }))
518-
else " showing a location
519-
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
512+
let l:lines = l:lines[l:loc['viewstart'] : l:loc['viewend']]
513+
endif
514+
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
515+
if s:floatwin.is_showing()
516+
call s:floatwin.enter()
517+
else
520518
call s:floatwin.show(l:screenpos, lsp#utils#normalize_markup_content({
521519
\ 'language': &filetype,
522520
\ 'value': join(l:lines, "\n")

autoload/lsp/ui/vim/floatwin.vim

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function! s:Floatwin.new(option) abort
3535
return extend(deepcopy(s:Floatwin), {
3636
\ 'id': s:floatwin_id,
3737
\ 'bufnr': l:bufnr,
38-
\ 'max_width': get(a:option, 'max_width', &columns / 3),
39-
\ 'max_height': get(a:option, 'max_height', &lines / 2),
38+
\ 'max_width': get(a:option, 'max_width', g:lsp_preview_max_width),
39+
\ 'max_height': get(a:option, 'max_height', g:lsp_preview_max_height),
4040
\ 'close_on': get(a:option, 'close_on', []),
4141
\ 'screenpos': [0, 0],
4242
\ 'contents': []
@@ -88,7 +88,9 @@ function! s:Floatwin.show(screenpos, contents) abort
8888
" show or move
8989
call lsp#ui#vim#floatwin#{s:namespace}#show(self)
9090
call setwinvar(self.winid(), '&wrap', 1)
91-
call setwinvar(self.winid(), '&conceallevel', 3)
91+
if g:lsp_hover_conceal
92+
call setwinvar(self.winid(), '&conceallevel', 3)
93+
endif
9294

9395
" write lines
9496
call lsp#ui#vim#floatwin#{s:namespace}#write(self, l:lines)
@@ -115,7 +117,9 @@ endfunction
115117
" enter
116118
"
117119
function! s:Floatwin.enter() abort
118-
call lsp#ui#vim#floatwin#{s:namespace}#enter(self)
120+
if g:lsp_preview_doubletap
121+
call lsp#ui#vim#floatwin#{s:namespace}#enter(self)
122+
endif
119123
endfunction
120124

121125
"
@@ -139,12 +143,14 @@ function! s:Floatwin.set_close_events() abort
139143
let l:close_fn = printf('lsp_floatwin_close_%s', self.id)
140144
let b:[l:close_fn] = { -> self.hide() }
141145

142-
augroup printf('lsp#ui#vim#floatwin#hide_%s', self.id)
143-
autocmd!
144-
for l:event in self.close_on
145-
execute printf('autocmd %s <buffer> call b:%s()', l:event, l:close_fn)
146-
endfor
147-
augroup END
146+
if g:lsp_preview_autoclose
147+
augroup printf('lsp#ui#vim#floatwin#hide_%s', self.id)
148+
autocmd!
149+
for l:event in self.close_on
150+
execute printf('autocmd %s <buffer> call b:%s()', l:event, l:close_fn)
151+
endfor
152+
augroup END
153+
endif
148154
endfunction
149155

150156
"

autoload/lsp/ui/vim/hover.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ function! s:handle_hover(server, data) abort
4040
endif
4141

4242
if !empty(a:data['response']['result']) && !empty(a:data['response']['result']['contents'])
43-
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
44-
call s:floatwin.show_tooltip(l:screenpos, lsp#utils#normalize_markup_content(a:data['response']['result']['contents']))
43+
if s:floatwin.is_showing()
44+
call s:floatwin.enter()
45+
else
46+
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
47+
call s:floatwin.show_tooltip(l:screenpos, lsp#utils#normalize_markup_content(a:data['response']['result']['contents']))
48+
endif
4549
return
4650
else
4751
call lsp#utils#error('No hover information found')

autoload/lsp/ui/vim/signature_help.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ function! s:handle_signature_help(server, data) abort
8282
let l:contents = lsp#utils#normalize_markup_content(l:contents)
8383
if mode()[0] == 'i'
8484
let s:floatwin.close_on = ['InsertLeave', 'CursorMovedI', 'CursorMovedP']
85+
call s:floatwin.show_tooltip(l:screenpos, l:contents)
8586
else
8687
let s:floatwin.close_on = ['InsertEnter', 'CursorMoved']
88+
if s:floatwin.is_showing()
89+
call s:floatwin.enter()
90+
else
91+
call s:floatwin.show_tooltip(l:screenpos, l:contents)
92+
endif
8793
endif
88-
call s:floatwin.show(l:screenpos, l:contents)
8994
return
9095
else
9196
" signature help is used while inserting. So this must be graceful.

0 commit comments

Comments
 (0)