summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-05-17 00:57:52 +0100
committerw0rp <devw0rp@gmail.com>2019-05-17 00:57:52 +0100
commite5ea809094fd1d521ac88516f5b4b6870e656f3a (patch)
tree942fcf578f129ca4801757fcd82f211751d159c0 /autoload
parent8cb6d043b4b2052ad6e5973b2a5804791511fed4 (diff)
downloadale-e5ea809094fd1d521ac88516f5b4b6870e656f3a.zip
Close #2285 - Add a function for use with omnifunc
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/completion.vim40
1 files changed, 36 insertions, 4 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim
index 03cc6471..9a8b76c7 100644
--- a/autoload/ale/completion.vim
+++ b/autoload/ale/completion.vim
@@ -169,7 +169,7 @@ function! s:ReplaceCompletionOptions() abort
let b:ale_old_omnifunc = &l:omnifunc
endif
- let &l:omnifunc = 'ale#completion#OmniFunc'
+ let &l:omnifunc = 'ale#completion#AutomaticOmniFunc'
endif
if l:source is# 'ale-automatic'
@@ -235,7 +235,7 @@ function! ale#completion#GetCompletionResult() abort
return v:null
endfunction
-function! ale#completion#OmniFunc(findstart, base) abort
+function! ale#completion#AutomaticOmniFunc(findstart, base) abort
if a:findstart
return ale#completion#GetCompletionPosition()
else
@@ -279,6 +279,7 @@ function! s:CompletionStillValid(request_id) abort
\&& (
\ b:ale_completion_info.column == l:column
\ || b:ale_completion_info.source is# 'deoplete'
+ \ || b:ale_completion_info.source is# 'ale-omnifunc'
\)
endfunction
@@ -570,7 +571,7 @@ function! ale#completion#GetCompletions(source) abort
let l:prefix = ale#completion#GetPrefix(&filetype, l:line, l:column)
if a:source is# 'ale-automatic' && empty(l:prefix)
- return
+ return 0
endif
let l:line_length = len(getline('.'))
@@ -584,16 +585,47 @@ function! ale#completion#GetCompletions(source) abort
\ 'request_id': 0,
\ 'source': a:source,
\}
+ unlet! b:ale_completion_response
+ unlet! b:ale_completion_parser
unlet! b:ale_completion_result
let l:buffer = bufnr('')
let l:Callback = function('s:OnReady')
+ let l:started = 0
+
for l:linter in ale#linter#Get(&filetype)
if !empty(l:linter.lsp)
- call ale#lsp_linter#StartLSP(l:buffer, l:linter, l:Callback)
+ if ale#lsp_linter#StartLSP(l:buffer, l:linter, l:Callback)
+ let l:started = 1
+ endif
endif
endfor
+
+ return l:started
+endfunction
+
+function! ale#completion#OmniFunc(findstart, base) abort
+ if a:findstart
+ let l:started = ale#completion#GetCompletions('ale-omnifunc')
+
+ if !l:started
+ " This is the special value for cancelling completions silently.
+ " See :help complete-functions
+ return -3
+ endif
+
+ return ale#completion#GetCompletionPosition()
+ else
+ let l:result = ale#completion#GetCompletionResult()
+
+ while l:result is v:null && !complete_check()
+ sleep 2ms
+ let l:result = ale#completion#GetCompletionResult()
+ endwhile
+
+ return l:result isnot v:null ? l:result : []
+ endif
endfunction
function! s:TimerHandler(...) abort