Skip to content

Commit

Permalink
Merge pull request #2291 from bhcleek/lsp/completion-start
Browse files Browse the repository at this point in the history
lsp: adjust to gopls changes
  • Loading branch information
bhcleek authored May 15, 2019
2 parents b86b0d3 + a57d35c commit 5e77189
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 7 additions & 5 deletions autoload/go/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ function! go#complete#GocodeComplete(findstart, base) abort
endfunction

function! go#complete#Complete(findstart, base) abort
let l:state = {'done': 0, 'matches': []}
let l:state = {'done': 0, 'matches': [], 'start': -1}

function! s:handler(state, matches) abort dict
function! s:handler(state, start, matches) abort dict
let a:state.start = a:start
let a:state.matches = a:matches
let a:state.done = 1
endfunction
Expand All @@ -262,15 +263,16 @@ function! go#complete#Complete(findstart, base) abort
sleep 10m
endwhile

let s:completions = l:state.matches

if len(l:state.matches) == 0
" no matches. cancel and leave completion mode.
call go#util#EchoInfo("no matches")
return -3
endif

return col('.')
let s:completions = l:state.matches

return l:state.start

else "findstart = 0 when we need to return the list of completions
return s:completions
endif
Expand Down
10 changes: 7 additions & 3 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ function! s:newlsp() abort
endfunction

function! l:lsp.write(msg) dict abort
let l:body = json_encode(a:msg)
let l:data = 'Content-Length: ' . strlen(l:body) . "\r\n\r\n" . l:body
let l:body = json_encode(a:msg)
let l:data = 'Content-Length: ' . strlen(l:body) . "\r\n\r\n" . l:body

if go#util#HasDebug('lsp')
let g:go_lsp_log = add(go#config#LspLog(), "->\n" . l:data)
Expand Down Expand Up @@ -454,7 +454,11 @@ endfunction
function! s:completionHandler(next, msg) abort dict
" gopls returns a CompletionList.
let l:matches = []
let l:start = -1

for l:item in a:msg.items
let l:start = l:item.textEdit.range.start.character

let l:match = {'abbr': l:item.label, 'word': l:item.textEdit.newText, 'info': '', 'kind': go#lsp#completionitemkind#Vim(l:item.kind)}
if has_key(l:item, 'detail')
let l:match.info = l:item.detail
Expand All @@ -469,7 +473,7 @@ function! s:completionHandler(next, msg) abort dict

let l:matches = add(l:matches, l:match)
endfor
let l:args = [l:matches]
let l:args = [l:start, l:matches]
call call(a:next, l:args)
endfunction

Expand Down

0 comments on commit 5e77189

Please sign in to comment.