Skip to content

Commit 5a25f70

Browse files
committed
Support option variables
1 parent 5a93f51 commit 5a25f70

File tree

5 files changed

+53
-40
lines changed

5 files changed

+53
-40
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.

ftplugin/lsp_floatwin.vim

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function! LspFloatwinSyntaxShouldUpdate(bufnr) abort
1414
return v:true
1515
endif
1616

17-
for [l:mark, l:language] in items(s:get_language_map(s:find_marks(a:bufnr)))
18-
if !has_key(b:lsp_floatwin_state.fenced_language_syntaxes, l:language) ||
17+
for [l:mark, l:filetype] in items(s:get_filetype_map(s:find_marks(a:bufnr)))
18+
if !has_key(b:lsp_floatwin_state.fenced_filetype_syntaxes, l:filetype) ||
1919
\ !has_key(b:lsp_floatwin_state.fenced_mark_syntaxes, l:mark)
2020
return v:true
2121
endif
@@ -39,7 +39,7 @@ function! s:update()
3939
" initialize state.
4040
let b:lsp_floatwin_state = get(b:, 'lsp_floatwin_state', {
4141
\ 'markdown_syntax': v:false,
42-
\ 'fenced_language_syntaxes': {},
42+
\ 'fenced_filetype_syntaxes': {},
4343
\ 'fenced_mark_syntaxes': {},
4444
\ })
4545

@@ -52,17 +52,17 @@ function! s:update()
5252
syntax include @Markdown syntax/markdown.vim
5353
endif
5454

55-
for [l:mark, l:language] in items(s:get_language_map(s:find_marks(bufnr('%'))))
56-
let l:language_group = printf('@LspMarkdownFenced_%s', s:escape(l:language))
55+
for [l:mark, l:filetype] in items(s:get_filetype_map(s:find_marks(bufnr('%'))))
56+
let l:filetype_group = printf('@LspMarkdownFenced_%s', s:escape(l:filetype))
5757

58-
" include syntax for language.
59-
if !has_key(b:lsp_floatwin_state.fenced_language_syntaxes, l:language)
60-
let b:lsp_floatwin_state.fenced_language_syntaxes[l:language] = v:true
58+
" include syntax for filetype.
59+
if !has_key(b:lsp_floatwin_state.fenced_filetype_syntaxes, l:filetype)
60+
let b:lsp_floatwin_state.fenced_filetype_syntaxes[l:filetype] = v:true
6161

6262
try
63-
for l:syntax_path in s:find_syntax_path(l:language)
63+
for l:syntax_path in s:find_syntax_path(l:filetype)
6464
call s:clear()
65-
execute printf('syntax include %s %s', l:language_group, l:syntax_path)
65+
execute printf('syntax include %s %s', l:filetype_group, l:syntax_path)
6666
endfor
6767
catch /.*/
6868
continue
@@ -86,7 +86,7 @@ function! s:update()
8686
\ l:start_mark,
8787
\ l:mark_end_group,
8888
\ l:end_mark,
89-
\ l:language_group
89+
\ l:filetype_group
9090
\ )
9191
endif
9292
endfor
@@ -115,10 +115,10 @@ function! s:find_marks(bufnr) abort
115115
endfunction
116116

117117
"
118-
" get_syntax_map
118+
" get_filetype_map
119119
"
120-
function! s:get_language_map(marks) abort
121-
let l:language_map = {}
120+
function! s:get_filetype_map(marks) abort
121+
let l:filetype_map = {}
122122

123123
for l:mark in a:marks
124124

@@ -127,27 +127,27 @@ function! s:get_language_map(marks) abort
127127
" Supports `let g:markdown_fenced_languages = ['sh']`
128128
if l:config !~# '='
129129
if l:config ==# l:mark
130-
let l:language_map[l:mark] = l:mark
130+
let l:filetype_map[l:mark] = l:mark
131131
break
132132
endif
133133

134134
" Supports `let g:markdown_fenced_languages = ['bash=sh']`
135135
else
136136
let l:config = split(l:config, '=')
137137
if l:config[1] ==# l:mark
138-
let l:language_map[l:config[1]] = l:config[0]
138+
let l:filetype_map[l:config[1]] = l:config[0]
139139
break
140140
endif
141141
endif
142142
endfor
143143

144144
" add as-is if can't resolved.
145-
if !has_key(l:language_map, l:mark)
146-
let l:language_map[l:mark] = l:mark
145+
if !has_key(l:filetype_map, l:mark)
146+
let l:filetype_map[l:mark] = l:mark
147147
endif
148148
endfor
149149

150-
return l:language_map
150+
return l:filetype_map
151151
endfunction
152152

153153
"

0 commit comments

Comments
 (0)