Skip to content

Commit

Permalink
Support option variables
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th committed Nov 20, 2019
1 parent 5a93f51 commit 5a25f70
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 40 deletions.
14 changes: 6 additions & 8 deletions autoload/lsp/ui/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,12 @@ function! s:handle_location(ctx, server, type, data) abort "ctx = {counter, list
else
let l:lines = readfile(fnameescape(l:loc['filename']))
if has_key(l:loc,'viewstart') " showing a locationLink
let l:view = l:lines[l:loc['viewstart'] : l:loc['viewend']]
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
call s:floatwin.show(l:screenpos, lsp#utils#normalize_markup_content({
\ 'language': &filetype,
\ 'value': join(l:view, "\n")
\ }))
else " showing a location
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
let l:lines = l:lines[l:loc['viewstart'] : l:loc['viewend']]
endif
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
if s:floatwin.is_showing()
call s:floatwin.enter()
else
call s:floatwin.show(l:screenpos, lsp#utils#normalize_markup_content({
\ 'language': &filetype,
\ 'value': join(l:lines, "\n")
Expand Down
26 changes: 16 additions & 10 deletions autoload/lsp/ui/vim/floatwin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function! s:Floatwin.new(option) abort
return extend(deepcopy(s:Floatwin), {
\ 'id': s:floatwin_id,
\ 'bufnr': l:bufnr,
\ 'max_width': get(a:option, 'max_width', &columns / 3),
\ 'max_height': get(a:option, 'max_height', &lines / 2),
\ 'max_width': get(a:option, 'max_width', g:lsp_preview_max_width),
\ 'max_height': get(a:option, 'max_height', g:lsp_preview_max_height),
\ 'close_on': get(a:option, 'close_on', []),
\ 'screenpos': [0, 0],
\ 'contents': []
Expand Down Expand Up @@ -88,7 +88,9 @@ function! s:Floatwin.show(screenpos, contents) abort
" show or move
call lsp#ui#vim#floatwin#{s:namespace}#show(self)
call setwinvar(self.winid(), '&wrap', 1)
call setwinvar(self.winid(), '&conceallevel', 3)
if g:lsp_hover_conceal
call setwinvar(self.winid(), '&conceallevel', 3)
endif

" write lines
call lsp#ui#vim#floatwin#{s:namespace}#write(self, l:lines)
Expand All @@ -115,7 +117,9 @@ endfunction
" enter
"
function! s:Floatwin.enter() abort
call lsp#ui#vim#floatwin#{s:namespace}#enter(self)
if g:lsp_preview_doubletap
call lsp#ui#vim#floatwin#{s:namespace}#enter(self)
endif
endfunction

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

augroup printf('lsp#ui#vim#floatwin#hide_%s', self.id)
autocmd!
for l:event in self.close_on
execute printf('autocmd %s <buffer> call b:%s()', l:event, l:close_fn)
endfor
augroup END
if g:lsp_preview_autoclose
augroup printf('lsp#ui#vim#floatwin#hide_%s', self.id)
autocmd!
for l:event in self.close_on
execute printf('autocmd %s <buffer> call b:%s()', l:event, l:close_fn)
endfor
augroup END
endif
endfunction

"
Expand Down
8 changes: 6 additions & 2 deletions autoload/lsp/ui/vim/hover.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ function! s:handle_hover(server, data) abort
endif

if !empty(a:data['response']['result']) && !empty(a:data['response']['result']['contents'])
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
call s:floatwin.show_tooltip(l:screenpos, lsp#utils#normalize_markup_content(a:data['response']['result']['contents']))
if s:floatwin.is_showing()
call s:floatwin.enter()
else
let l:screenpos = lsp#ui#vim#floatwin#screenpos(line('.'), col('.'))
call s:floatwin.show_tooltip(l:screenpos, lsp#utils#normalize_markup_content(a:data['response']['result']['contents']))
endif
return
else
call lsp#utils#error('No hover information found')
Expand Down
7 changes: 6 additions & 1 deletion autoload/lsp/ui/vim/signature_help.vim
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ function! s:handle_signature_help(server, data) abort
let l:contents = lsp#utils#normalize_markup_content(l:contents)
if mode()[0] == 'i'
let s:floatwin.close_on = ['InsertLeave', 'CursorMovedI', 'CursorMovedP']
call s:floatwin.show_tooltip(l:screenpos, l:contents)
else
let s:floatwin.close_on = ['InsertEnter', 'CursorMoved']
if s:floatwin.is_showing()
call s:floatwin.enter()
else
call s:floatwin.show_tooltip(l:screenpos, l:contents)
endif
endif
call s:floatwin.show(l:screenpos, l:contents)
return
else
" signature help is used while inserting. So this must be graceful.
Expand Down
38 changes: 19 additions & 19 deletions ftplugin/lsp_floatwin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function! LspFloatwinSyntaxShouldUpdate(bufnr) abort
return v:true
endif

for [l:mark, l:language] in items(s:get_language_map(s:find_marks(a:bufnr)))
if !has_key(b:lsp_floatwin_state.fenced_language_syntaxes, l:language) ||
for [l:mark, l:filetype] in items(s:get_filetype_map(s:find_marks(a:bufnr)))
if !has_key(b:lsp_floatwin_state.fenced_filetype_syntaxes, l:filetype) ||
\ !has_key(b:lsp_floatwin_state.fenced_mark_syntaxes, l:mark)
return v:true
endif
Expand All @@ -39,7 +39,7 @@ function! s:update()
" initialize state.
let b:lsp_floatwin_state = get(b:, 'lsp_floatwin_state', {
\ 'markdown_syntax': v:false,
\ 'fenced_language_syntaxes': {},
\ 'fenced_filetype_syntaxes': {},
\ 'fenced_mark_syntaxes': {},
\ })

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

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

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

try
for l:syntax_path in s:find_syntax_path(l:language)
for l:syntax_path in s:find_syntax_path(l:filetype)
call s:clear()
execute printf('syntax include %s %s', l:language_group, l:syntax_path)
execute printf('syntax include %s %s', l:filetype_group, l:syntax_path)
endfor
catch /.*/
continue
Expand All @@ -86,7 +86,7 @@ function! s:update()
\ l:start_mark,
\ l:mark_end_group,
\ l:end_mark,
\ l:language_group
\ l:filetype_group
\ )
endif
endfor
Expand Down Expand Up @@ -115,10 +115,10 @@ function! s:find_marks(bufnr) abort
endfunction

"
" get_syntax_map
" get_filetype_map
"
function! s:get_language_map(marks) abort
let l:language_map = {}
function! s:get_filetype_map(marks) abort
let l:filetype_map = {}

for l:mark in a:marks

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

" Supports `let g:markdown_fenced_languages = ['bash=sh']`
else
let l:config = split(l:config, '=')
if l:config[1] ==# l:mark
let l:language_map[l:config[1]] = l:config[0]
let l:filetype_map[l:config[1]] = l:config[0]
break
endif
endif
endfor

" add as-is if can't resolved.
if !has_key(l:language_map, l:mark)
let l:language_map[l:mark] = l:mark
if !has_key(l:filetype_map, l:mark)
let l:filetype_map[l:mark] = l:mark
endif
endfor

return l:language_map
return l:filetype_map
endfunction

"
Expand Down

0 comments on commit 5a25f70

Please sign in to comment.