Skip to content

Commit 085a666

Browse files
committed
Refactor completion plugins to pass opts dict
1 parent 3e53d1a commit 085a666

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

autoload/OmniSharp.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function! OmniSharp#Complete(findstart, base) abort
5252
endwhile
5353
return start
5454
else
55-
return OmniSharp#actions#complete#Get(a:base)
55+
let opts = { 'startcol': col('.') - 1 }
56+
return OmniSharp#actions#complete#Get(a:base, opts)
5657
endif
5758
endfunction
5859

autoload/OmniSharp/actions/complete.vim

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ set cpoptions&vim
44
let s:generated_snippets = get(s:, 'generated_snippets', {})
55
let s:last_completion_dictionary = get(s:, 'last_completion_dictionary', {})
66

7-
function! OmniSharp#actions#complete#Get(partial, ...) abort
8-
let opts = a:0 ? { 'Callback': a:1 } : {}
7+
function! OmniSharp#actions#complete#Get(partial, opts) abort
98
if !OmniSharp#IsServerRunning()
109
return []
1110
endif
1211
if g:OmniSharp_server_stdio
1312
let s:complete_pending = 1
14-
call s:StdioGetCompletions(a:partial, function('s:CBGet', [opts]))
15-
if !has_key(opts, 'Callback')
13+
call s:StdioGetCompletions(a:partial, a:opts, function('s:CBGet', [a:opts]))
14+
if !has_key(a:opts, 'Callback')
1615
" No callback has been passed in, so this function should return
1716
" synchronously, so it can be used as an omnifunc
1817
let starttime = reltime()
@@ -27,7 +26,7 @@ function! OmniSharp#actions#complete#Get(partial, ...) abort
2726
let completions = OmniSharp#py#Eval(
2827
\ printf('getCompletions(%s)', string(a:partial)))
2928
if OmniSharp#py#CheckForError() | let completions = [] | endif
30-
return s:CBGet(opts, completions)
29+
return s:CBGet(a:opts, completions)
3130
endif
3231
endfunction
3332

@@ -63,14 +62,16 @@ function! OmniSharp#actions#complete#ExpandSnippet() abort
6362
endfunction
6463

6564

66-
function! s:StdioGetCompletions(partial, Callback) abort
65+
function! s:StdioGetCompletions(partial, opts, Callback) abort
6766
let wantDocPopup = OmniSharp#popup#Enabled()
6867
\ && g:omnicomplete_fetch_full_documentation
6968
\ && &completeopt =~# 'popup'
7069
let wantDoc = wantDocPopup ? 'false'
7170
\ : g:omnicomplete_fetch_full_documentation ? 'true' : 'false'
7271
let wantSnippet = g:OmniSharp_want_snippet ? 'true' : 'false'
73-
let s:last_startcol = col('.') - len(a:partial) - 1
72+
let s:last_startcol = has_key(a:opts, 'startcol')
73+
\ ? a:opts.startcol
74+
\ : col('.') - len(a:partial) - 1
7475
let parameters = {
7576
\ 'WordToComplete': a:partial,
7677
\ 'WantDocumentationForEveryCompletionResult': wantDoc,

autoload/asyncomplete/sources/OmniSharp.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ function! asyncomplete#sources#OmniSharp#completor(opt, ctx) abort
77

88
let startcol = column - kwlen
99

10-
call OmniSharp#actions#complete#Get(kw, {results->
11-
\ asyncomplete#complete(a:opt['name'], a:ctx, startcol, results)})
10+
let opts = {
11+
\ 'startcol': startcol - 1,
12+
\ 'Callback': {results->
13+
\ asyncomplete#complete(a:opt['name'], a:ctx, startcol, results)}
14+
\}
15+
call OmniSharp#actions#complete#Get(kw, opts)
1216
endfunction
1317

1418
" vim:et:sw=2:sts=2

autoload/coc/source/OmniSharp.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ function! coc#source#OmniSharp#init() abort
77
endfunction
88

99
function! coc#source#OmniSharp#complete(options, callback) abort
10-
call OmniSharp#actions#complete#Get(a:options.input, a:callback)
10+
let opts = { 'Callback': a:callback }
11+
call OmniSharp#actions#complete#Get(a:options.input, opts)
1112
endfunction
1213

1314
" vim:et:sw=2:sts=2

autoload/deoplete/source/omnisharp.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ endfunction
1212
function! deoplete#source#omnisharp#sendRequest(lhs, partial) abort
1313
let s:currentLhsRequest = a:lhs
1414
let g:deoplete#source#omnisharp#_results = v:null
15-
call OmniSharp#actions#complete#Get(a:partial, {results -> s:onReceivedResponse(a:lhs, results)})
15+
let opts = {
16+
\ 'Callback': {results -> s:onReceivedResponse(a:lhs, results)}
17+
\}
18+
call OmniSharp#actions#complete#Get(a:partial, opts)
1619
endfunction

autoload/ncm2/sources/OmniSharp.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ let s:loaded = 1
55

66
function! ncm2#sources#OmniSharp#on_complete(ctx) abort
77
let kw = matchstr(a:ctx['typed'], '\(\w*\W\)*\zs\w\+$')
8-
call OmniSharp#actions#complete#Get(kw, {
9-
\ results -> ncm2#complete(a:ctx, a:ctx['startccol'], results)
10-
\})
8+
let opts = {
9+
\ 'Callback': {results -> ncm2#complete(a:ctx, a:ctx['startccol'], results)}
10+
\}
11+
call OmniSharp#actions#complete#Get(kw, opts)
1112
endfunction
1213

1314
" vim:et:sw=2:sts=2

test/complete.vader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Given cs():
77
Execute ():
88
" Need to set a filename for OmniSharp-roslyn
99
call OmniSharpTestInitializeBuffer('Complete')
10-
call OmniSharpWarmup('OmniSharp#actions#complete#Get', ['usi'])
10+
let opts = { 'startcol': 0 }
11+
call OmniSharpWarmup('OmniSharp#actions#complete#Get', ['usi'], opts)
1112

1213
Do (invoke omnicomplete on 'usi'):
1314
A\<c-x>\<c-o>

0 commit comments

Comments
 (0)