Skip to content

Commit

Permalink
Add option to disable autocomplete
Browse files Browse the repository at this point in the history
Fixes natebosch#15

- Add a global variable to configure autocomplete behavior.
- When autocomplete is disabled store suggestions in a buffer local
  variable instead of popping open the completion menu.
- Add a function which can serve as a `completefunc` reading from the
  stored suggestions.
- Update the README with new configuration option.
  • Loading branch information
natebosch committed Jun 17, 2017
1 parent a15e6da commit e6688fa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ nnoremap gd :LSClientGoToDefinition<CR>
nnoremap gr :LSClientFindReferences<CR>
```

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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions autoload/lsc/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions plugin/lsc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e6688fa

Please sign in to comment.