Skip to content

Commit

Permalink
Adds support for signature help trigger characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
mibu138 committed Mar 6, 2024
1 parent eb4266c commit 19670de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions autoload/lsc/capabilities.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ function! lsc#capabilities#normalize(capabilities) abort
endif
endif
endif
if has_key(a:capabilities, 'signatureHelpProvider') &&
\ type(a:capabilities.signatureHelpProvider) != type(v:null)
let l:signature_help_provider = a:capabilities.signatureHelpProvider
if has_key(l:signature_help_provider, 'triggerCharacters')
let l:normalized.signaturehelp.triggerCharacters =
\ l:signature_help_provider['triggerCharacters']
endif
endif
if has_key(a:capabilities, 'textDocumentSync')
let l:text_document_sync = a:capabilities['textDocumentSync']
let l:incremental = v:false
Expand Down Expand Up @@ -45,6 +53,7 @@ endfunction
function! lsc#capabilities#defaults() abort
return {
\ 'completion': {'triggerCharacters': []},
\ 'signaturehelp': {'triggerCharacters': []},
\ 'textDocumentSync': {
\ 'incremental': v:false,
\ 'sendDidSave': v:false,
Expand Down
29 changes: 29 additions & 0 deletions autoload/lsc/signaturehelp.vim
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
function! lsc#signaturehelp#insertCharPre() abort
let s:next_char = v:char
endfunction

if !exists('s:initialized')
let s:current_parameter = ''
let s:next_char = ''
let s:initialized = v:true
endif

function! lsc#signaturehelp#textChanged() abort
if &paste | return | endif
if !g:lsc_enable_autocomplete | return | endif
" This may be <BS> or similar if not due to a character typed
if empty(s:next_char) | return | endif
call s:typedCharacter()
let s:next_char = ''
endfunction

function! s:typedCharacter() abort
if s:isTrigger(s:next_char)
call lsc#signaturehelp#getSignatureHelp()
endif
endfunction

function! s:isTrigger(char) abort
for l:server in lsc#server#current()
if index(l:server.capabilities.signaturehelp.triggerCharacters, a:char) >= 0
return v:true
endif
endfor
return v:false
endfunction

function! lsc#signaturehelp#getSignatureHelp() abort
call lsc#file#flushChanges()
let l:params = lsc#params#documentPosition()
Expand Down
3 changes: 3 additions & 0 deletions plugin/lsc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ augroup LSC
\ call <SID>IfEnabled('lsc#cursor#onChangesFlushed')

autocmd TextChangedI * call <SID>IfEnabled('lsc#complete#textChanged')
autocmd TextChangedI * call <SID>IfEnabled('lsc#signaturehelp#textChanged')
autocmd TextChangedP * call <SID>IfEnabled('lsc#complete#textChanged')
autocmd TextChangedP * call <SID>IfEnabled('lsc#signaturehelp#textChanged')
autocmd InsertCharPre * call <SID>IfEnabled('lsc#complete#insertCharPre')
autocmd InsertCharPre * call <SID>IfEnabled('lsc#signaturehelp#insertCharPre')

autocmd VimLeave * call lsc#server#exit()
if exists('##ExitPre')
Expand Down

0 comments on commit 19670de

Please sign in to comment.