diff --git a/CHANGELOG.md b/CHANGELOG.md index 245b2a67..08063ef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Bug fix: Don't leave an extra character when completing after typing 3 characters. - Filter completions after typing 3 characters. + - Add configuration to disable autocomplete. # 0.2.1 diff --git a/README.md b/README.md index f235ab88..42a460d1 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ nnoremap gd :LSClientGoToDefinition nnoremap gr :LSClientFindReferences ``` +To disable autocomplete in favor of manual completion also add + +```viml +let g:lsc_enable_autocomplete = v:false +set completefunc=lsc#complete#complete +``` + ## Features The protocol does not require that every language server supports every feature @@ -65,6 +72,10 @@ the documentation window use the following: autocmd CompleteDone * silent! pclose ``` +Disable autocomplete with `let g:lsc_enable_autocomplete = v:false`. When using +manual completion the `completefunc` may have no results if completion is +requested before the server responds with suggestions. + ### Jump to definition While the cursor is on any identifier call `LSClientGoToDefinition` to jump to diff --git a/autoload/lsc/complete.vim b/autoload/lsc/complete.vim index a6dbd766..06c84d5c 100644 --- a/autoload/lsc/complete.vim +++ b/autoload/lsc/complete.vim @@ -61,6 +61,7 @@ endfunction augroup LscCompletion autocmd! autocmd CompleteDone * let b:lsc_is_completing = v:false + \ | silent! unlet b:lsc_completion augroup END " TODO: Make this customizable @@ -96,10 +97,14 @@ function! s:startCompletion() abort let data = {'old_pos': getcurpos(), \ 'completion_id': s:completion_id, \ 'filetype': &filetype} - function data.trigger(completions) + function data.trigger(completion) call s:MarkNotCompleting(self.filetype) if s:isCompletionValid(self.old_pos, self.completion_id) - call s:SuggestCompletions(a:completions) + if (g:lsc_enable_autocomplete) + call s:SuggestCompletions(a:completion) + else + let b:lsc_completion = a:completion + endif else let b:lsc_is_completing = v:false endif @@ -120,6 +125,16 @@ function! s:SuggestCompletions(completion) abort call complete(start, suggestions) endfunction +function! lsc#complete#complete(findstart, base) abort + if !exists('b:lsc_completion') | return -1 | endif + if a:findstart + if len(b:lsc_completion.items) == 0 | return -3 | endif + return s:FindStart(b:lsc_completion) - 1 + else + return s:FindSuggestions(a:base, b:lsc_completion) + endif +endfunction + function! s:FindStart(completion) abort if has_key(a:completion, 'start_col') return a:completion.start_col diff --git a/plugin/lsc.vim b/plugin/lsc.vim index fae4eb24..5f18b8bd 100644 --- a/plugin/lsc.vim +++ b/plugin/lsc.vim @@ -7,6 +7,9 @@ if !exists('g:lsc_server_commands') let g:lsc_server_commands = {} endif +if !exists('g:lsc_enable_autocomplete') + let g:lsc_enable_autocomplete = v:true +endif command! LSClientGoToDefinition call lsc#reference#goToDefinition() command! LSClientFindReferences call lsc#reference#findReferences()