Skip to content

Launch one thread per file. #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 50 additions & 25 deletions plugin/clang_complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ function! s:ClangCompleteInit()
call LoadUserOptions()

inoremap <expr> <buffer> <C-X><C-U> <SID>LaunchCompletion()
inoremap <expr> <buffer> . <SID>CompleteDot()
inoremap <expr> <buffer> > <SID>CompleteArrow()
inoremap <expr> <buffer> : <SID>CompleteColon()
"inoremap <expr> <buffer> . <SID>CompleteDot()
"inoremap <expr> <buffer> > <SID>CompleteArrow()
"inoremap <expr> <buffer> : <SID>CompleteColon()
inoremap <expr> <buffer> <CR> <SID>HandlePossibleSelectionEnter()

if g:clang_snippets == 1
Expand Down Expand Up @@ -162,6 +162,9 @@ function! s:ClangCompleteInit()
augroup end
endif

au CursorMovedI <buffer> call <SID>ReLaunchCompletion()
"au InsertCharPre <buffer> call <SID>ReLaunchCompletion()

if !exists('g:clang_use_library') || g:clang_use_library == 1
" Try to use libclang. On failure, we fall back to the clang executable.
let l:initialized = s:initClangCompletePython(exists('g:clang_use_library'))
Expand Down Expand Up @@ -276,6 +279,7 @@ function! s:initClangCompletePython(user_requested)
if l:res == 0
return 0
endif
au VimLeavePre * python FinishClangComplete()
let s:libclang_loaded = 1
endif
python WarmupCache()
Expand Down Expand Up @@ -589,6 +593,9 @@ function! ClangComplete(findstart, base)
while l:start > 0 && l:line[l:start - 1] =~ '\i'
let l:start -= 1
endwhile
if l:start == 0
return -1
endif
if l:line[l:start - 2:] =~ '->' || l:line[l:start - 1] == '.'
let b:clang_complete_type = 0
endif
Expand All @@ -604,37 +611,45 @@ function! ClangComplete(findstart, base)
endif

if g:clang_use_library == 1
python completions, timer = getCurrentCompletions(vim.eval('a:base'))
python thread = getThread(vim.current.buffer.name)
python vim.command('let l:shouldRetry = ' + str(tryComplete(thread, vim.eval('b:col'), vim.eval("a:base"))))
if l:shouldRetry == 1
return []
endif

python completions, timer = getCurrentCompletions(thread)
python vim.command('let l:res = ' + completions)
python timer.registerEvent("Load into vimscript")
else
let l:res = s:ClangCompleteBinary(a:base)
endif

for item in l:res
if g:clang_snippets == 1
let item['word'] = b:AddSnip(item['info'], item['args_pos'])
else
let item['word'] = item['abbr']
endif
endfor
if l:res != []
for item in l:res
if g:clang_snippets == 1
let item['word'] = b:AddSnip(item['info'], item['args_pos'])
else
let item['word'] = item['abbr']
endif
endfor

inoremap <expr> <buffer> <C-Y> <SID>HandlePossibleSelectionCtrlY()
augroup ClangComplete
au CursorMovedI <buffer> call <SID>TriggerSnippet()
augroup end
let b:snippet_chosen = 0
inoremap <expr> <buffer> <C-Y> <SID>HandlePossibleSelectionCtrlY()
augroup ClangComplete
au CursorMovedI <buffer> call <SID>TriggerSnippet()
augroup end
let b:snippet_chosen = 0

if g:clang_use_library == 1
python timer.registerEvent("vimscript + snippets")
python timer.finish()
endif
if g:clang_use_library == 1
python timer.registerEvent("vimscript + snippets")
python timer.finish()
endif

if g:clang_debug == 1
echom 'clang_complete: completion time (' . (g:clang_use_library == 1 ? 'library' : 'binary') . ') '. split(reltimestr(reltime(l:time_start)))[0]
if g:clang_debug == 1
echom 'clang_complete: completion time (' . (g:clang_use_library == 1 ? 'library' : 'binary') . ') '. split(reltimestr(reltime(l:time_start)))[0]
endif
endif
return l:res
endif
return l:res
endif
endfunction

function! s:HandlePossibleSelectionEnter()
Expand Down Expand Up @@ -726,9 +741,19 @@ function! s:CompleteColon()
return ':' . s:LaunchCompletion()
endfunction

let b:prev_line = ""

function! s:ReLaunchCompletion()
if s:ShouldComplete() && b:prev_line != getline('.')
let b:prev_line = getline('.')
call feedkeys("\<C-X>\<C-U>")
endif
return ''
endfunction

" May be used in a mapping to update the quickfix window.
function! g:ClangUpdateQuickFix()
call s:DoPeriodicQuickFix()
"call s:DoPeriodicQuickFix()
return ''
endfunction

Expand Down
Loading