2018-01-06 07:16:30 -05:00
|
|
|
" Copyright (C) 2011-2018 YouCompleteMe contributors
|
2012-04-15 19:57:10 -04:00
|
|
|
"
|
|
|
|
" This file is part of YouCompleteMe.
|
|
|
|
"
|
|
|
|
" YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
" it under the terms of the GNU General Public License as published by
|
|
|
|
" the Free Software Foundation, either version 3 of the License, or
|
|
|
|
" (at your option) any later version.
|
|
|
|
"
|
|
|
|
" YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
" GNU General Public License for more details.
|
|
|
|
"
|
|
|
|
" You should have received a copy of the GNU General Public License
|
|
|
|
" along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
" This is basic vim plugin boilerplate
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
" This needs to be called outside of a function
|
|
|
|
let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )
|
2017-02-04 15:46:54 -05:00
|
|
|
let s:force_semantic = 0
|
2017-04-15 09:42:23 -04:00
|
|
|
let s:completion_stopped = 0
|
2017-02-04 15:46:54 -05:00
|
|
|
let s:default_completion = {
|
|
|
|
\ 'start_column': -1,
|
|
|
|
\ 'candidates': []
|
|
|
|
\ }
|
|
|
|
let s:completion = s:default_completion
|
2016-08-21 11:12:04 -04:00
|
|
|
let s:previous_allowed_buffer_number = 0
|
2017-04-11 07:46:20 -04:00
|
|
|
let s:pollers = {
|
2017-02-04 15:46:54 -05:00
|
|
|
\ 'completion': {
|
|
|
|
\ 'id': -1,
|
|
|
|
\ 'wait_milliseconds': 10
|
|
|
|
\ },
|
2017-04-11 07:46:20 -04:00
|
|
|
\ 'file_parse_response': {
|
|
|
|
\ 'id': -1,
|
|
|
|
\ 'wait_milliseconds': 100
|
2017-05-11 13:08:28 -04:00
|
|
|
\ },
|
|
|
|
\ 'server_ready': {
|
|
|
|
\ 'id': -1,
|
|
|
|
\ 'wait_milliseconds': 100
|
2017-12-21 18:23:21 -05:00
|
|
|
\ },
|
|
|
|
\ 'receive_messages': {
|
|
|
|
\ 'id': -1,
|
|
|
|
\ 'wait_milliseconds': 100
|
2017-04-11 07:46:20 -04:00
|
|
|
\ }
|
|
|
|
\ }
|
2012-05-12 18:20:03 -04:00
|
|
|
|
2016-02-29 13:26:50 -05:00
|
|
|
|
2016-10-23 22:41:36 -04:00
|
|
|
" When both versions are available, we prefer Python 3 over Python 2:
|
|
|
|
" - faster startup (no monkey-patching from python-future);
|
|
|
|
" - better Windows support (e.g. temporary paths are not returned in all
|
|
|
|
" lowercase);
|
|
|
|
" - Python 2 support will eventually be dropped.
|
|
|
|
function! s:UsingPython3()
|
|
|
|
if has('python3')
|
2016-02-28 16:54:49 -05:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
2016-02-29 13:26:50 -05:00
|
|
|
|
2016-10-23 22:41:36 -04:00
|
|
|
let s:using_python3 = s:UsingPython3()
|
|
|
|
let s:python_until_eof = s:using_python3 ? "python3 << EOF" : "python << EOF"
|
|
|
|
let s:python_command = s:using_python3 ? "py3 " : "py "
|
2016-02-28 16:54:49 -05:00
|
|
|
|
2016-02-29 13:26:50 -05:00
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
function! s:Pyeval( eval_string )
|
2016-10-23 22:41:36 -04:00
|
|
|
if s:using_python3
|
|
|
|
return py3eval( a:eval_string )
|
2016-02-28 16:54:49 -05:00
|
|
|
endif
|
2016-10-23 22:41:36 -04:00
|
|
|
return pyeval( a:eval_string )
|
2016-02-28 16:54:49 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-10-04 13:30:58 -04:00
|
|
|
|
2017-12-21 18:23:21 -05:00
|
|
|
function! s:StartMessagePoll()
|
|
|
|
if s:pollers.receive_messages.id < 0
|
|
|
|
let s:pollers.receive_messages.id = timer_start(
|
|
|
|
\ s:pollers.receive_messages.wait_milliseconds,
|
|
|
|
\ function( 's:ReceiveMessages' ) )
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:ReceiveMessages( timer_id )
|
|
|
|
let poll_again = s:Pyeval( 'ycm_state.OnPeriodicTick()' )
|
|
|
|
|
|
|
|
if poll_again
|
|
|
|
let s:pollers.receive_messages.id = timer_start(
|
|
|
|
\ s:pollers.receive_messages.wait_milliseconds,
|
|
|
|
\ function( 's:ReceiveMessages' ) )
|
|
|
|
else
|
|
|
|
" Don't poll again until we open another buffer
|
|
|
|
let s:pollers.receive_messages.id = -1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-04-15 19:57:10 -04:00
|
|
|
function! youcompleteme#Enable()
|
2013-09-02 17:45:53 -04:00
|
|
|
call s:SetUpBackwardsCompatibility()
|
|
|
|
|
2014-09-04 16:12:37 -04:00
|
|
|
" This can be 0 if YCM libs are old or -1 if an exception occured while
|
|
|
|
" executing the function.
|
|
|
|
if s:SetUpPython() != 1
|
2013-02-12 23:54:27 -05:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2015-10-12 09:27:30 -04:00
|
|
|
call s:SetUpCommands()
|
2013-09-02 14:34:18 -04:00
|
|
|
call s:SetUpCpoptions()
|
|
|
|
call s:SetUpCompleteopt()
|
|
|
|
call s:SetUpKeyMappings()
|
|
|
|
|
2014-01-04 17:28:27 -05:00
|
|
|
if g:ycm_show_diagnostics_ui
|
|
|
|
call s:TurnOffSyntasticForCFamily()
|
2013-09-02 14:34:18 -04:00
|
|
|
endif
|
|
|
|
|
2014-01-04 17:28:27 -05:00
|
|
|
call s:SetUpSigns()
|
2014-01-04 21:32:42 -05:00
|
|
|
call s:SetUpSyntaxHighlighting()
|
2014-01-04 17:28:27 -05:00
|
|
|
|
2014-09-15 15:39:05 -04:00
|
|
|
call youcompleteme#EnableCursorMovedAutocommands()
|
2012-04-15 19:57:10 -04:00
|
|
|
augroup youcompleteme
|
|
|
|
autocmd!
|
2012-07-21 18:33:59 -04:00
|
|
|
" Note that these events will NOT trigger for the file vim is started with;
|
|
|
|
" so if you do "vim foo.cc", these events will not trigger when that buffer
|
|
|
|
" is read. This is because youcompleteme#Enable() is called on VimEnter and
|
2017-05-14 08:13:36 -04:00
|
|
|
" that happens *after* FileType has already triggered for the initial file.
|
|
|
|
" We don't parse the buffer on the BufRead event since it would only be
|
|
|
|
" useful if the buffer filetype is set (we ignore the buffer if there is no
|
|
|
|
" filetype) and if so, the FileType event has triggered before and thus the
|
|
|
|
" buffer is already parsed.
|
|
|
|
autocmd FileType * call s:OnFileTypeSet()
|
2017-03-30 20:06:46 -04:00
|
|
|
autocmd BufEnter * call s:OnBufferEnter()
|
2016-09-05 11:33:30 -04:00
|
|
|
autocmd BufUnload * call s:OnBufferUnload()
|
2012-07-28 14:42:43 -04:00
|
|
|
autocmd InsertLeave * call s:OnInsertLeave()
|
2013-04-12 19:15:31 -04:00
|
|
|
autocmd VimLeave * call s:OnVimLeave()
|
2015-08-31 12:51:23 -04:00
|
|
|
autocmd CompleteDone * call s:OnCompleteDone()
|
2012-04-15 19:57:10 -04:00
|
|
|
augroup END
|
|
|
|
|
2017-05-11 13:08:28 -04:00
|
|
|
" The FileType event is not triggered for the first loaded file. We wait until
|
|
|
|
" the server is ready to manually run the s:OnFileTypeSet function.
|
|
|
|
let s:pollers.server_ready.id = timer_start(
|
|
|
|
\ s:pollers.server_ready.wait_milliseconds,
|
|
|
|
\ function( 's:PollServerReady' ) )
|
2013-02-08 21:29:36 -05:00
|
|
|
endfunction
|
|
|
|
|
2016-11-10 15:24:09 -05:00
|
|
|
|
2014-10-14 13:08:47 -04:00
|
|
|
function! youcompleteme#EnableCursorMovedAutocommands()
|
2016-01-02 18:44:36 -05:00
|
|
|
augroup ycmcompletemecursormove
|
|
|
|
autocmd!
|
|
|
|
autocmd CursorMoved * call s:OnCursorMovedNormalMode()
|
2017-04-11 07:46:20 -04:00
|
|
|
autocmd TextChanged * call s:OnTextChangedNormalMode()
|
2016-01-02 18:44:36 -05:00
|
|
|
autocmd TextChangedI * call s:OnTextChangedInsertMode()
|
2017-02-04 15:46:54 -05:00
|
|
|
" The TextChangedI event is not triggered when inserting a character while
|
|
|
|
" the completion menu is open. We handle this by closing the completion menu
|
|
|
|
" just before inserting a character.
|
|
|
|
autocmd InsertCharPre * call s:OnInsertChar()
|
2016-01-02 18:44:36 -05:00
|
|
|
augroup END
|
2014-09-15 15:39:05 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2014-10-14 13:08:47 -04:00
|
|
|
function! youcompleteme#DisableCursorMovedAutocommands()
|
2016-01-02 18:44:36 -05:00
|
|
|
autocmd! ycmcompletemecursormove
|
2014-09-15 15:39:05 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2015-12-05 12:24:15 -05:00
|
|
|
function! youcompleteme#GetErrorCount()
|
2016-02-28 16:54:49 -05:00
|
|
|
return s:Pyeval( 'ycm_state.GetErrorCount()' )
|
2015-12-05 12:24:15 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! youcompleteme#GetWarningCount()
|
2016-02-28 16:54:49 -05:00
|
|
|
return s:Pyeval( 'ycm_state.GetWarningCount()' )
|
2015-12-05 12:24:15 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2014-09-04 16:12:37 -04:00
|
|
|
function! s:SetUpPython() abort
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_until_eof
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2015-10-12 15:19:37 -04:00
|
|
|
import os
|
2015-07-01 20:43:09 -04:00
|
|
|
import sys
|
2015-10-12 15:19:37 -04:00
|
|
|
import traceback
|
2015-07-01 20:43:09 -04:00
|
|
|
import vim
|
|
|
|
|
2015-10-12 15:19:37 -04:00
|
|
|
# Add python sources folder to the system path.
|
2015-07-01 20:43:09 -04:00
|
|
|
script_folder = vim.eval( 's:script_folder_path' )
|
2015-10-12 15:19:37 -04:00
|
|
|
sys.path.insert( 0, os.path.join( script_folder, '..', 'python' ) )
|
|
|
|
|
|
|
|
from ycm.setup import SetUpSystemPaths, SetUpYCM
|
2015-07-01 20:43:09 -04:00
|
|
|
|
2015-10-12 15:19:37 -04:00
|
|
|
# We enclose this code in a try/except block to avoid backtraces in Vim.
|
|
|
|
try:
|
|
|
|
SetUpSystemPaths()
|
|
|
|
|
|
|
|
# Import the modules used in this file.
|
|
|
|
from ycm import base, vimsupport
|
|
|
|
|
|
|
|
ycm_state = SetUpYCM()
|
|
|
|
except Exception as error:
|
|
|
|
# We don't use PostVimMessage or EchoText from the vimsupport module because
|
|
|
|
# importing this module may fail.
|
|
|
|
vim.command( 'redraw | echohl WarningMsg' )
|
|
|
|
for line in traceback.format_exc().splitlines():
|
|
|
|
vim.command( "echom '{0}'".format( line.replace( "'", "''" ) ) )
|
|
|
|
|
|
|
|
vim.command( "echo 'YouCompleteMe unavailable: {0}'"
|
|
|
|
.format( str( error ).replace( "'", "''" ) ) )
|
|
|
|
vim.command( 'echohl None' )
|
|
|
|
vim.command( 'return 0' )
|
|
|
|
else:
|
|
|
|
vim.command( 'return 1' )
|
2015-07-01 20:43:09 -04:00
|
|
|
EOF
|
2014-05-14 13:35:49 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-02-08 21:29:36 -05:00
|
|
|
function! s:SetUpKeyMappings()
|
|
|
|
" The g:ycm_key_select_completion and g:ycm_key_previous_completion used to
|
|
|
|
" exist and are now here purely for the sake of backwards compatibility; we
|
|
|
|
" don't want to break users if we can avoid it.
|
|
|
|
|
|
|
|
if exists('g:ycm_key_select_completion') &&
|
|
|
|
\ index(g:ycm_key_list_select_completion,
|
|
|
|
\ g:ycm_key_select_completion) == -1
|
|
|
|
call add(g:ycm_key_list_select_completion, g:ycm_key_select_completion)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:ycm_key_previous_completion') &&
|
|
|
|
\ index(g:ycm_key_list_previous_completion,
|
|
|
|
\ g:ycm_key_previous_completion) == -1
|
|
|
|
call add(g:ycm_key_list_previous_completion, g:ycm_key_previous_completion)
|
|
|
|
endif
|
2013-01-31 21:42:12 -05:00
|
|
|
|
2013-02-08 21:29:36 -05:00
|
|
|
for key in g:ycm_key_list_select_completion
|
|
|
|
" With this command, when the completion window is visible, the tab key
|
|
|
|
" (default) will select the next candidate in the window. In vim, this also
|
|
|
|
" changes the typed-in text to that of the candidate completion.
|
|
|
|
exe 'inoremap <expr>' . key .
|
|
|
|
\ ' pumvisible() ? "\<C-n>" : "\' . key .'"'
|
|
|
|
endfor
|
2012-04-15 19:57:10 -04:00
|
|
|
|
2013-02-08 21:29:36 -05:00
|
|
|
for key in g:ycm_key_list_previous_completion
|
|
|
|
" This selects the previous candidate for shift-tab (default)
|
|
|
|
exe 'inoremap <expr>' . key .
|
|
|
|
\ ' pumvisible() ? "\<C-p>" : "\' . key .'"'
|
|
|
|
endfor
|
2012-07-23 14:15:25 -04:00
|
|
|
|
2017-04-15 09:42:23 -04:00
|
|
|
for key in g:ycm_key_list_stop_completion
|
|
|
|
" When selecting a candidate and closing the completion menu with the <C-y>
|
|
|
|
" key, the menu will automatically be reopened because of the TextChangedI
|
|
|
|
" event. We define a command to prevent that.
|
|
|
|
exe 'inoremap <expr>' . key . ' <SID>StopCompletion( "\' . key . '" )'
|
|
|
|
endfor
|
|
|
|
|
2013-03-09 22:31:00 -05:00
|
|
|
if !empty( g:ycm_key_invoke_completion )
|
2013-04-19 21:33:06 -04:00
|
|
|
let invoke_key = g:ycm_key_invoke_completion
|
|
|
|
|
|
|
|
" Inside the console, <C-Space> is passed as <Nul> to Vim
|
2015-06-03 07:33:56 -04:00
|
|
|
if invoke_key ==# '<C-Space>'
|
|
|
|
imap <Nul> <C-Space>
|
2013-04-19 21:33:06 -04:00
|
|
|
endif
|
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
silent! exe 'inoremap <unique> <silent> ' . invoke_key .
|
|
|
|
\ ' <C-R>=<SID>InvokeSemanticCompletion()<CR>'
|
2013-02-06 21:32:47 -05:00
|
|
|
endif
|
2012-07-21 18:33:59 -04:00
|
|
|
|
2013-03-09 22:31:00 -05:00
|
|
|
if !empty( g:ycm_key_detailed_diagnostics )
|
2013-03-17 16:09:55 -04:00
|
|
|
silent! exe 'nnoremap <unique> ' . g:ycm_key_detailed_diagnostics .
|
2017-02-04 15:46:54 -05:00
|
|
|
\ ' :YcmShowDetailedDiagnostic<CR>'
|
2013-02-06 21:32:47 -05:00
|
|
|
endif
|
2017-02-04 15:46:54 -05:00
|
|
|
|
|
|
|
" The TextChangedI event is not triggered when deleting a character while the
|
|
|
|
" completion menu is open. We handle this by closing the completion menu on
|
|
|
|
" the keys that delete a character in insert mode.
|
|
|
|
for key in [ "<BS>", "<C-h>" ]
|
|
|
|
silent! exe 'inoremap <unique> <expr> ' . key .
|
|
|
|
\ ' <SID>OnDeleteChar( "\' . key . '" )'
|
|
|
|
endfor
|
2013-02-08 21:29:36 -05:00
|
|
|
endfunction
|
2012-08-15 22:39:03 -04:00
|
|
|
|
2013-01-26 21:45:27 -05:00
|
|
|
|
2014-01-04 17:28:27 -05:00
|
|
|
function! s:SetUpSigns()
|
|
|
|
" We try to ensure backwards compatibility with Syntastic if the user has
|
|
|
|
" already defined styling for Syntastic highlight groups.
|
|
|
|
|
|
|
|
if !hlexists( 'YcmErrorSign' )
|
|
|
|
if hlexists( 'SyntasticErrorSign')
|
|
|
|
highlight link YcmErrorSign SyntasticErrorSign
|
|
|
|
else
|
|
|
|
highlight link YcmErrorSign error
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !hlexists( 'YcmWarningSign' )
|
|
|
|
if hlexists( 'SyntasticWarningSign')
|
|
|
|
highlight link YcmWarningSign SyntasticWarningSign
|
|
|
|
else
|
|
|
|
highlight link YcmWarningSign todo
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !hlexists( 'YcmErrorLine' )
|
|
|
|
highlight link YcmErrorLine SyntasticErrorLine
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !hlexists( 'YcmWarningLine' )
|
|
|
|
highlight link YcmWarningLine SyntasticWarningLine
|
|
|
|
endif
|
|
|
|
|
|
|
|
exe 'sign define YcmError text=' . g:ycm_error_symbol .
|
|
|
|
\ ' texthl=YcmErrorSign linehl=YcmErrorLine'
|
|
|
|
exe 'sign define YcmWarning text=' . g:ycm_warning_symbol .
|
|
|
|
\ ' texthl=YcmWarningSign linehl=YcmWarningLine'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2014-01-04 21:32:42 -05:00
|
|
|
function! s:SetUpSyntaxHighlighting()
|
|
|
|
" We try to ensure backwards compatibility with Syntastic if the user has
|
|
|
|
" already defined styling for Syntastic highlight groups.
|
|
|
|
|
|
|
|
if !hlexists( 'YcmErrorSection' )
|
|
|
|
if hlexists( 'SyntasticError' )
|
|
|
|
highlight link YcmErrorSection SyntasticError
|
|
|
|
else
|
|
|
|
highlight link YcmErrorSection SpellBad
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !hlexists( 'YcmWarningSection' )
|
|
|
|
if hlexists( 'SyntasticWarning' )
|
|
|
|
highlight link YcmWarningSection SyntasticWarning
|
|
|
|
else
|
|
|
|
highlight link YcmWarningSection SpellCap
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-04-25 02:15:13 -04:00
|
|
|
function! s:SetUpBackwardsCompatibility()
|
|
|
|
let complete_in_comments_and_strings =
|
|
|
|
\ get( g:, 'ycm_complete_in_comments_and_strings', 0 )
|
|
|
|
|
|
|
|
if complete_in_comments_and_strings
|
|
|
|
let g:ycm_complete_in_strings = 1
|
|
|
|
let g:ycm_complete_in_comments = 1
|
|
|
|
endif
|
2013-10-04 15:23:33 -04:00
|
|
|
|
|
|
|
" ycm_filetypes_to_completely_ignore is the old name for fileype_blacklist
|
|
|
|
if has_key( g:, 'ycm_filetypes_to_completely_ignore' )
|
|
|
|
let g:filetype_blacklist = g:ycm_filetypes_to_completely_ignore
|
|
|
|
endif
|
2013-04-25 02:15:13 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2014-01-04 17:28:27 -05:00
|
|
|
" Needed so that YCM is used instead of Syntastic
|
|
|
|
function! s:TurnOffSyntasticForCFamily()
|
|
|
|
let g:syntastic_cpp_checkers = []
|
|
|
|
let g:syntastic_c_checkers = []
|
|
|
|
let g:syntastic_objc_checkers = []
|
|
|
|
let g:syntastic_objcpp_checkers = []
|
2013-10-29 16:00:36 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-03-26 19:34:07 -04:00
|
|
|
function! s:DisableOnLargeFile( buffer )
|
|
|
|
if exists( 'b:ycm_largefile' )
|
|
|
|
return b:ycm_largefile
|
|
|
|
endif
|
|
|
|
|
|
|
|
let threshold = g:ycm_disable_for_files_larger_than_kb * 1024
|
|
|
|
let b:ycm_largefile =
|
|
|
|
\ threshold > 0 && getfsize( expand( a:buffer ) ) > threshold
|
|
|
|
if b:ycm_largefile
|
|
|
|
exec s:python_command "vimsupport.PostVimMessage(" .
|
|
|
|
\ "'YouCompleteMe is disabled in this buffer; " .
|
|
|
|
\ "the file exceeded the max size (see YCM options).' )"
|
|
|
|
endif
|
|
|
|
return b:ycm_largefile
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-09-05 11:33:30 -04:00
|
|
|
function! s:AllowedToCompleteInBuffer( buffer )
|
|
|
|
let buffer_filetype = getbufvar( a:buffer, '&filetype' )
|
|
|
|
|
|
|
|
if empty( buffer_filetype ) ||
|
2017-01-01 07:57:03 -05:00
|
|
|
\ getbufvar( a:buffer, '&buftype' ) ==# 'nofile' ||
|
|
|
|
\ buffer_filetype ==# 'qf'
|
2013-03-09 23:30:10 -05:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2017-03-26 19:34:07 -04:00
|
|
|
if s:DisableOnLargeFile( a:buffer )
|
2014-12-03 04:38:02 -05:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2013-03-09 23:30:10 -05:00
|
|
|
let whitelist_allows = has_key( g:ycm_filetype_whitelist, '*' ) ||
|
2016-09-05 11:33:30 -04:00
|
|
|
\ has_key( g:ycm_filetype_whitelist, buffer_filetype )
|
|
|
|
let blacklist_allows = !has_key( g:ycm_filetype_blacklist, buffer_filetype )
|
2013-03-09 23:30:10 -05:00
|
|
|
|
2017-05-14 08:26:01 -04:00
|
|
|
let allowed = whitelist_allows && blacklist_allows
|
|
|
|
if allowed
|
|
|
|
let s:previous_allowed_buffer_number = bufnr( a:buffer )
|
|
|
|
endif
|
|
|
|
return allowed
|
2012-08-13 22:01:55 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-09-05 11:33:30 -04:00
|
|
|
function! s:AllowedToCompleteInCurrentBuffer()
|
|
|
|
return s:AllowedToCompleteInBuffer( '%' )
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-08-21 11:12:04 -04:00
|
|
|
function! s:VisitedBufferRequiresReparse()
|
2017-05-14 08:26:01 -04:00
|
|
|
if bufnr( '%' ) ==# s:previous_allowed_buffer_number
|
2016-08-21 11:12:04 -04:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2017-05-14 08:26:01 -04:00
|
|
|
return s:AllowedToCompleteInCurrentBuffer()
|
2016-08-21 11:12:04 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-04-04 20:48:45 -04:00
|
|
|
function! s:SetUpCpoptions()
|
|
|
|
" Without this flag in cpoptions, critical YCM mappings do not work. There's
|
|
|
|
" no way to not have this and have YCM working, so force the flag.
|
|
|
|
set cpoptions+=B
|
2014-01-10 18:01:30 -05:00
|
|
|
|
|
|
|
" This prevents the display of "Pattern not found" & similar messages during
|
2017-04-11 07:46:20 -04:00
|
|
|
" completion.
|
|
|
|
set shortmess+=c
|
2013-04-04 20:48:45 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-08-13 23:47:45 -04:00
|
|
|
function! s:SetUpCompleteopt()
|
|
|
|
" Some plugins (I'm looking at you, vim-notes) change completeopt by for
|
|
|
|
" instance adding 'longest'. This breaks YCM. So we force our settings.
|
|
|
|
" There's no two ways about this: if you want to use YCM then you have to
|
|
|
|
" have these completeopt settings, otherwise YCM won't work at all.
|
|
|
|
|
|
|
|
" We need menuone in completeopt, otherwise when there's only one candidate
|
|
|
|
" for completion, the menu doesn't show up.
|
|
|
|
set completeopt-=menu
|
|
|
|
set completeopt+=menuone
|
|
|
|
|
|
|
|
" This is unnecessary with our features. People use this option to insert
|
|
|
|
" the common prefix of all the matches and then add more differentiating chars
|
|
|
|
" so that they can select a more specific match. With our features, they
|
|
|
|
" don't need to insert the prefix; they just type the differentiating chars.
|
|
|
|
" Also, having this option set breaks the plugin.
|
|
|
|
set completeopt-=longest
|
|
|
|
|
|
|
|
if g:ycm_add_preview_to_completeopt
|
|
|
|
set completeopt+=preview
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-08-03 18:05:25 -04:00
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
function! s:SetCompleteFunc()
|
|
|
|
let &completefunc = 'youcompleteme#CompleteFunc'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-12-12 15:16:06 -05:00
|
|
|
function! s:OnVimLeave()
|
|
|
|
exec s:python_command "ycm_state.OnVimLeave()"
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:OnCompleteDone()
|
|
|
|
exec s:python_command "ycm_state.OnCompleteDone()"
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-05-14 08:13:36 -04:00
|
|
|
function! s:OnFileTypeSet()
|
2017-03-30 20:06:46 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentBuffer()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:SetUpCompleteopt()
|
|
|
|
call s:SetCompleteFunc()
|
2017-12-21 18:23:21 -05:00
|
|
|
call s:StartMessagePoll()
|
2017-03-30 20:06:46 -04:00
|
|
|
|
|
|
|
exec s:python_command "ycm_state.OnBufferVisit()"
|
2017-04-12 13:07:00 -04:00
|
|
|
call s:OnFileReadyToParse( 1 )
|
2017-03-30 20:06:46 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:OnBufferEnter()
|
2017-03-26 19:34:07 -04:00
|
|
|
if !s:VisitedBufferRequiresReparse()
|
2012-08-13 22:01:55 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-08-13 23:47:45 -04:00
|
|
|
call s:SetUpCompleteopt()
|
2012-05-12 18:23:45 -04:00
|
|
|
call s:SetCompleteFunc()
|
2017-12-21 18:23:21 -05:00
|
|
|
call s:StartMessagePoll()
|
2015-11-13 08:26:04 -05:00
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnBufferVisit()"
|
2017-04-12 13:07:00 -04:00
|
|
|
" Last parse may be outdated because of changes from other buffers. Force a
|
|
|
|
" new parse.
|
|
|
|
call s:OnFileReadyToParse( 1 )
|
2012-05-12 18:23:45 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-09-05 11:33:30 -04:00
|
|
|
function! s:OnBufferUnload()
|
|
|
|
" Expanding <abuf> returns the unloaded buffer number as a string but we want
|
|
|
|
" it as a true number for the getbufvar function.
|
2018-01-06 07:16:30 -05:00
|
|
|
let buffer_number = str2nr( expand( '<abuf>' ) )
|
|
|
|
if !s:AllowedToCompleteInBuffer( buffer_number )
|
2013-03-14 23:39:44 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2018-01-06 07:16:30 -05:00
|
|
|
exec s:python_command "ycm_state.OnBufferUnload( " . buffer_number . " )"
|
2013-03-14 23:39:44 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-05-11 13:08:28 -04:00
|
|
|
function! s:PollServerReady( timer_id )
|
2017-07-04 23:15:33 -04:00
|
|
|
if !s:Pyeval( 'ycm_state.IsServerAlive()' )
|
2017-09-23 10:37:24 -04:00
|
|
|
exec s:python_command "ycm_state.NotifyUserIfServerCrashed()"
|
2017-07-04 23:15:33 -04:00
|
|
|
" Server crashed. Don't poll it again.
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-06-04 04:09:49 -04:00
|
|
|
if !s:Pyeval( 'ycm_state.CheckIfServerIsReady()' )
|
2017-05-11 13:08:28 -04:00
|
|
|
let s:pollers.server_ready.id = timer_start(
|
|
|
|
\ s:pollers.server_ready.wait_milliseconds,
|
|
|
|
\ function( 's:PollServerReady' ) )
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:OnFileTypeSet()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-04-12 13:07:00 -04:00
|
|
|
function! s:OnFileReadyToParse( ... )
|
|
|
|
" Accepts an optional parameter that is either 0 or 1. If 1, send a
|
|
|
|
" FileReadyToParse event notification, whether the buffer has changed or not;
|
|
|
|
" effectively forcing a parse of the buffer. Default is 0.
|
|
|
|
let force_parsing = a:0 > 0 && a:1
|
|
|
|
|
2017-03-06 01:32:03 -05:00
|
|
|
" We only want to send a new FileReadyToParse event notification if the buffer
|
2017-04-12 13:07:00 -04:00
|
|
|
" has changed since the last time we sent one, or if forced.
|
2017-05-21 10:26:50 -04:00
|
|
|
if force_parsing || s:Pyeval( "ycm_state.NeedsReparse()" )
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnFileReadyToParse()"
|
2017-04-11 07:46:20 -04:00
|
|
|
|
|
|
|
call timer_stop( s:pollers.file_parse_response.id )
|
|
|
|
let s:pollers.file_parse_response.id = timer_start(
|
|
|
|
\ s:pollers.file_parse_response.wait_milliseconds,
|
|
|
|
\ function( 's:PollFileParseResponse' ) )
|
2013-08-03 18:47:11 -04:00
|
|
|
endif
|
2012-07-26 23:50:56 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-07-28 01:16:23 -04:00
|
|
|
|
2017-04-11 07:46:20 -04:00
|
|
|
function! s:PollFileParseResponse( ... )
|
|
|
|
if !s:Pyeval( "ycm_state.FileParseRequestReady()" )
|
|
|
|
let s:pollers.file_parse_response.id = timer_start(
|
|
|
|
\ s:pollers.file_parse_response.wait_milliseconds,
|
|
|
|
\ function( 's:PollFileParseResponse' ) )
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
exec s:python_command "ycm_state.HandleFileParseRequest()"
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-07-31 04:58:40 -04:00
|
|
|
function! s:SendKeys( keys )
|
|
|
|
" By default keys are added to the end of the typeahead buffer. If there are
|
|
|
|
" already keys in the buffer, they will be processed first and may change the
|
|
|
|
" state that our keys combination was sent for (e.g. <C-X><C-U><C-P> in normal
|
|
|
|
" mode instead of insert mode or <C-e> outside of completion mode). We avoid
|
|
|
|
" that by inserting the keys at the start of the typeahead buffer with the 'i'
|
|
|
|
" option. Also, we don't want the keys to be remapped to something else so we
|
|
|
|
" add the 'n' option.
|
|
|
|
call feedkeys( a:keys, 'in' )
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-10-06 19:44:13 -04:00
|
|
|
function! s:CloseCompletionMenu()
|
2017-02-04 15:46:54 -05:00
|
|
|
if pumvisible()
|
2017-07-31 04:58:40 -04:00
|
|
|
call s:SendKeys( "\<C-e>" )
|
2017-02-04 15:46:54 -05:00
|
|
|
endif
|
2015-06-11 16:10:40 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-07-28 01:16:23 -04:00
|
|
|
|
2017-10-06 19:44:13 -04:00
|
|
|
function! s:OnInsertChar()
|
|
|
|
call timer_stop( s:pollers.completion.id )
|
|
|
|
call s:CloseCompletionMenu()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
function! s:OnDeleteChar( key )
|
|
|
|
call timer_stop( s:pollers.completion.id )
|
|
|
|
if pumvisible()
|
|
|
|
return "\<C-y>" . a:key
|
2012-07-28 01:16:23 -04:00
|
|
|
endif
|
2017-02-04 15:46:54 -05:00
|
|
|
return a:key
|
2012-04-15 19:57:10 -04:00
|
|
|
endfunction
|
|
|
|
|
2016-01-02 18:44:36 -05:00
|
|
|
|
2017-04-15 09:42:23 -04:00
|
|
|
function! s:StopCompletion( key )
|
|
|
|
call timer_stop( s:pollers.completion.id )
|
|
|
|
if pumvisible()
|
|
|
|
let s:completion_stopped = 1
|
|
|
|
return "\<C-y>"
|
|
|
|
endif
|
|
|
|
return a:key
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-04-11 07:46:20 -04:00
|
|
|
function! s:OnCursorMovedNormalMode()
|
|
|
|
if !s:AllowedToCompleteInCurrentBuffer()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
exec s:python_command "ycm_state.OnCursorMoved()"
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:OnTextChangedNormalMode()
|
|
|
|
if !s:AllowedToCompleteInCurrentBuffer()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:OnFileReadyToParse()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-01-02 18:44:36 -05:00
|
|
|
function! s:OnTextChangedInsertMode()
|
2016-08-21 11:12:04 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentBuffer()
|
2012-08-13 22:01:55 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-04-15 09:42:23 -04:00
|
|
|
if s:completion_stopped
|
|
|
|
let s:completion_stopped = 0
|
|
|
|
let s:completion = s:default_completion
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-07-28 01:16:23 -04:00
|
|
|
call s:IdentifierFinishedOperations()
|
2017-02-04 15:46:54 -05:00
|
|
|
|
|
|
|
" We have to make sure we correctly leave semantic mode even when the user
|
|
|
|
" inserts something like a "operator[]" candidate string which fails
|
|
|
|
" CurrentIdentifierFinished check.
|
|
|
|
if s:force_semantic && !s:Pyeval( 'base.LastEnteredCharIsIdentifierChar()' )
|
|
|
|
let s:force_semantic = 0
|
2013-03-15 14:43:09 -04:00
|
|
|
endif
|
2013-12-02 19:36:53 -05:00
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
if &completefunc == "youcompleteme#CompleteFunc" &&
|
|
|
|
\ ( g:ycm_auto_trigger || s:force_semantic ) &&
|
|
|
|
\ !s:InsideCommentOrStringAndShouldStop() &&
|
|
|
|
\ !s:OnBlankLine()
|
|
|
|
" Immediately call previous completion to avoid flickers.
|
|
|
|
call s:Complete()
|
2013-12-02 19:36:53 -05:00
|
|
|
call s:InvokeCompletion()
|
|
|
|
endif
|
2013-12-03 17:38:23 -05:00
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
exec s:python_command "ycm_state.OnCursorMoved()"
|
|
|
|
|
|
|
|
if g:ycm_autoclose_preview_window_after_completion
|
|
|
|
call s:ClosePreviewWindowIfNeeded()
|
2013-12-03 17:38:23 -05:00
|
|
|
endif
|
2012-04-15 19:57:10 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-05-12 18:20:03 -04:00
|
|
|
|
2012-07-28 14:42:43 -04:00
|
|
|
function! s:OnInsertLeave()
|
2016-08-21 11:12:04 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentBuffer()
|
2012-08-13 22:01:55 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-07-04 22:32:13 -04:00
|
|
|
call timer_stop( s:pollers.completion.id )
|
2017-02-04 15:46:54 -05:00
|
|
|
let s:force_semantic = 0
|
|
|
|
let s:completion = s:default_completion
|
2017-07-04 22:32:13 -04:00
|
|
|
|
2013-08-12 23:11:41 -04:00
|
|
|
call s:OnFileReadyToParse()
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnInsertLeave()"
|
2013-03-15 14:43:09 -04:00
|
|
|
if g:ycm_autoclose_preview_window_after_completion ||
|
|
|
|
\ g:ycm_autoclose_preview_window_after_insertion
|
|
|
|
call s:ClosePreviewWindowIfNeeded()
|
|
|
|
endif
|
2012-08-07 00:29:56 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:ClosePreviewWindowIfNeeded()
|
2013-03-23 17:11:48 -04:00
|
|
|
let current_buffer_name = bufname('')
|
|
|
|
|
|
|
|
" We don't want to try to close the preview window in special buffers like
|
|
|
|
" "[Command Line]"; if we do, Vim goes bonkers. Special buffers always start
|
|
|
|
" with '['.
|
|
|
|
if current_buffer_name[ 0 ] == '['
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2014-07-25 20:01:26 -04:00
|
|
|
" This command does the actual closing of the preview window. If no preview
|
|
|
|
" window is shown, nothing happens.
|
|
|
|
pclose
|
2012-07-30 01:08:02 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-07-28 01:16:23 -04:00
|
|
|
function! s:IdentifierFinishedOperations()
|
2016-02-28 16:54:49 -05:00
|
|
|
if !s:Pyeval( 'base.CurrentIdentifierFinished()' )
|
2012-07-28 01:16:23 -04:00
|
|
|
return
|
2012-05-12 18:20:03 -04:00
|
|
|
endif
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnCurrentIdentifierFinished()"
|
2017-02-04 15:46:54 -05:00
|
|
|
let s:force_semantic = 0
|
|
|
|
let s:completion = s:default_completion
|
2012-05-12 18:20:03 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-04-25 02:15:13 -04:00
|
|
|
" Returns 1 when inside comment and 2 when inside string
|
2012-06-24 15:04:45 -04:00
|
|
|
function! s:InsideCommentOrString()
|
|
|
|
" Has to be col('.') -1 because col('.') doesn't exist at this point. We are
|
|
|
|
" in insert mode when this func is called.
|
2016-02-28 16:54:49 -05:00
|
|
|
let syntax_group = synIDattr(
|
|
|
|
\ synIDtrans( synID( line( '.' ), col( '.' ) - 1, 1 ) ), 'name')
|
2013-04-25 02:15:13 -04:00
|
|
|
|
|
|
|
if stridx(syntax_group, 'Comment') > -1
|
2012-06-24 15:04:45 -04:00
|
|
|
return 1
|
|
|
|
endif
|
2013-04-25 02:15:13 -04:00
|
|
|
|
|
|
|
if stridx(syntax_group, 'String') > -1
|
|
|
|
return 2
|
|
|
|
endif
|
|
|
|
|
2012-06-24 15:04:45 -04:00
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-04-25 02:15:13 -04:00
|
|
|
function! s:InsideCommentOrStringAndShouldStop()
|
|
|
|
let retval = s:InsideCommentOrString()
|
|
|
|
let inside_comment = retval == 1
|
|
|
|
let inside_string = retval == 2
|
|
|
|
|
|
|
|
if inside_comment && g:ycm_complete_in_comments ||
|
|
|
|
\ inside_string && g:ycm_complete_in_strings
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
return retval
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-02-06 22:01:12 -05:00
|
|
|
function! s:OnBlankLine()
|
2016-02-28 16:54:49 -05:00
|
|
|
return s:Pyeval( 'not vim.current.line or vim.current.line.isspace()' )
|
2013-02-06 22:01:12 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-04-15 19:57:10 -04:00
|
|
|
function! s:InvokeCompletion()
|
2017-02-04 15:46:54 -05:00
|
|
|
exec s:python_command "ycm_state.SendCompletionRequest(" .
|
|
|
|
\ "vimsupport.GetBoolValue( 's:force_semantic' ) )"
|
2012-04-15 19:57:10 -04:00
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
call s:PollCompletion()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:InvokeSemanticCompletion()
|
2017-07-20 07:38:13 -04:00
|
|
|
if &completefunc == "youcompleteme#CompleteFunc"
|
|
|
|
let s:force_semantic = 1
|
|
|
|
exec s:python_command "ycm_state.SendCompletionRequest( True )"
|
|
|
|
|
|
|
|
call s:PollCompletion()
|
|
|
|
endif
|
2012-06-24 15:04:45 -04:00
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
" Since this function is called in a mapping through the expression register
|
|
|
|
" <C-R>=, its return value is inserted (see :h c_CTRL-R_=). We don't want to
|
|
|
|
" insert anything so we return an empty string.
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:PollCompletion( ... )
|
|
|
|
if !s:Pyeval( 'ycm_state.CompletionRequestReady()' )
|
|
|
|
let s:pollers.completion.id = timer_start(
|
|
|
|
\ s:pollers.completion.wait_milliseconds,
|
|
|
|
\ function( 's:PollCompletion' ) )
|
2012-04-15 19:57:10 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
let response = s:Pyeval( 'ycm_state.GetCompletionResponse()' )
|
|
|
|
let s:completion = {
|
|
|
|
\ 'start_column': response.completion_start_column,
|
|
|
|
\ 'candidates': response.completions
|
|
|
|
\ }
|
|
|
|
call s:Complete()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:Complete()
|
2017-10-06 19:44:13 -04:00
|
|
|
" Do not call user's completion function if the start column is after the
|
|
|
|
" current column or if there are no candidates. Close the completion menu
|
|
|
|
" instead. This avoids keeping the user in completion mode.
|
|
|
|
if s:completion.start_column > col( '.' ) || empty( s:completion.candidates )
|
|
|
|
call s:CloseCompletionMenu()
|
|
|
|
else
|
|
|
|
" <c-x><c-u> invokes the user's completion function (which we have set to
|
|
|
|
" youcompleteme#CompleteFunc), and <c-p> tells Vim to select the previous
|
|
|
|
" completion candidate. This is necessary because by default, Vim selects the
|
|
|
|
" first candidate when completion is invoked, and selecting a candidate
|
|
|
|
" automatically replaces the current text with it. Calling <c-p> forces Vim to
|
|
|
|
" deselect the first candidate and in turn preserve the user's current text
|
|
|
|
" until he explicitly chooses to replace it with a completion.
|
|
|
|
call s:SendKeys( "\<C-X>\<C-U>\<C-P>" )
|
|
|
|
endif
|
2012-04-15 19:57:10 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-05-12 18:20:03 -04:00
|
|
|
|
2017-02-04 15:46:54 -05:00
|
|
|
function! youcompleteme#CompleteFunc( findstart, base )
|
2012-07-10 18:26:07 -04:00
|
|
|
if a:findstart
|
2017-02-04 15:46:54 -05:00
|
|
|
return s:completion.start_column - 1
|
2012-07-28 01:16:23 -04:00
|
|
|
endif
|
2017-02-04 15:46:54 -05:00
|
|
|
return s:completion.candidates
|
2012-07-28 01:16:23 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-07-28 18:27:30 -04:00
|
|
|
|
2013-10-22 13:51:37 -04:00
|
|
|
function! youcompleteme#ServerPid()
|
2016-02-28 16:54:49 -05:00
|
|
|
return s:Pyeval( 'ycm_state.ServerPid()' )
|
2013-10-22 13:51:37 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-02-19 08:03:50 -05:00
|
|
|
function! s:SetUpCommands()
|
|
|
|
command! YcmRestartServer call s:RestartServer()
|
|
|
|
command! YcmDebugInfo call s:DebugInfo()
|
|
|
|
command! -nargs=* -complete=custom,youcompleteme#LogsComplete
|
|
|
|
\ YcmToggleLogs call s:ToggleLogs(<f-args>)
|
|
|
|
command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete
|
|
|
|
\ YcmCompleter call s:CompleterCommand(<f-args>)
|
|
|
|
command! YcmDiags call s:ShowDiagnostics()
|
|
|
|
command! YcmShowDetailedDiagnostic call s:ShowDetailedDiagnostic()
|
|
|
|
command! YcmForceCompileAndDiagnostics call s:ForceCompileAndDiagnostics()
|
2013-10-15 18:27:54 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-02-19 08:03:50 -05:00
|
|
|
function! s:RestartServer()
|
|
|
|
exec s:python_command "ycm_state.RestartServer()"
|
2017-12-21 18:23:21 -05:00
|
|
|
|
|
|
|
call timer_stop( s:pollers.receive_messages.id )
|
|
|
|
let s:pollers.receive_messages.id = -1
|
|
|
|
|
2017-05-11 13:08:28 -04:00
|
|
|
call timer_stop( s:pollers.server_ready.id )
|
|
|
|
let s:pollers.server_ready.id = timer_start(
|
|
|
|
\ s:pollers.server_ready.wait_milliseconds,
|
|
|
|
\ function( 's:PollServerReady' ) )
|
2012-08-15 22:39:03 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-01-26 14:44:42 -05:00
|
|
|
function! s:DebugInfo()
|
|
|
|
echom "Printing YouCompleteMe debug information..."
|
2016-02-28 16:54:49 -05:00
|
|
|
let debug_info = s:Pyeval( 'ycm_state.DebugInfo()' )
|
2013-01-26 14:44:42 -05:00
|
|
|
for line in split( debug_info, "\n" )
|
|
|
|
echom '-- ' . line
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2013-09-27 16:52:04 -04:00
|
|
|
|
2015-10-27 12:00:11 -04:00
|
|
|
function! s:ToggleLogs(...)
|
2016-05-06 01:52:04 -04:00
|
|
|
exec s:python_command "ycm_state.ToggleLogs( *vim.eval( 'a:000' ) )"
|
2015-10-27 12:00:11 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-02-19 08:03:50 -05:00
|
|
|
function! youcompleteme#LogsComplete( arglead, cmdline, cursorpos )
|
|
|
|
return join( s:Pyeval( 'list( ycm_state.GetLogfiles() )' ), "\n" )
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-02-25 09:14:01 -05:00
|
|
|
function! s:CompleterCommand(...)
|
2017-12-21 18:23:21 -05:00
|
|
|
" CompleterCommand will call the OnUserCommand function of a completer. If
|
|
|
|
" the first arguments is of the form "ft=..." it can be used to specify the
|
|
|
|
" completer to use (for example "ft=cpp"). Else the native filetype
|
|
|
|
" completer of the current buffer is used. If no native filetype completer
|
|
|
|
" is found and no completer was specified this throws an error. You can use
|
2013-09-27 16:52:04 -04:00
|
|
|
" "ft=ycm:ident" to select the identifier completer.
|
|
|
|
" The remaining arguments will be passed to the completer.
|
2013-02-25 09:14:01 -05:00
|
|
|
let arguments = copy(a:000)
|
2013-09-06 02:43:14 -04:00
|
|
|
let completer = ''
|
2013-02-25 09:14:01 -05:00
|
|
|
|
|
|
|
if a:0 > 0 && strpart(a:1, 0, 3) == 'ft='
|
2013-09-27 16:52:04 -04:00
|
|
|
if a:1 == 'ft=ycm:ident'
|
2013-09-06 02:43:14 -04:00
|
|
|
let completer = 'identifier'
|
2013-02-25 09:14:01 -05:00
|
|
|
endif
|
|
|
|
let arguments = arguments[1:]
|
|
|
|
endif
|
|
|
|
|
2017-01-01 07:57:03 -05:00
|
|
|
exec s:python_command "ycm_state.SendCommandRequest(" .
|
|
|
|
\ "vim.eval( 'l:arguments' ), vim.eval( 'l:completer' ) )"
|
2013-02-25 09:14:01 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-05-09 23:28:04 -04:00
|
|
|
|
2017-02-19 08:03:50 -05:00
|
|
|
function! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos )
|
|
|
|
return join( s:Pyeval( 'ycm_state.GetDefinedSubcommands()' ), "\n" )
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-05-03 19:11:10 -04:00
|
|
|
function! youcompleteme#OpenGoToList()
|
2017-01-01 07:57:03 -05:00
|
|
|
exec s:python_command "vimsupport.PostVimMessage(" .
|
|
|
|
\ "'WARNING: youcompleteme#OpenGoToList function is deprecated. " .
|
|
|
|
\ "Do NOT use it.' )"
|
2016-05-31 04:40:25 -04:00
|
|
|
exec s:python_command "vimsupport.OpenQuickFixList( True, True )"
|
2013-05-03 19:11:10 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-05-09 23:28:04 -04:00
|
|
|
|
2017-02-19 08:03:50 -05:00
|
|
|
function! s:ShowDiagnostics()
|
|
|
|
exec s:python_command "ycm_state.ShowDiagnostics()"
|
2013-09-27 19:20:35 -04:00
|
|
|
endfunction
|
2013-01-26 14:44:42 -05:00
|
|
|
|
2013-05-09 23:28:04 -04:00
|
|
|
|
2017-02-19 08:03:50 -05:00
|
|
|
function! s:ShowDetailedDiagnostic()
|
|
|
|
exec s:python_command "ycm_state.ShowDetailedDiagnostic()"
|
2013-01-31 22:21:11 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-01-30 17:46:58 -05:00
|
|
|
|
2013-01-31 22:21:11 -05:00
|
|
|
function! s:ForceCompileAndDiagnostics()
|
2017-02-19 08:03:50 -05:00
|
|
|
exec s:python_command "ycm_state.ForceCompileAndDiagnostics()"
|
2013-01-31 22:21:11 -05:00
|
|
|
endfunction
|
|
|
|
|
2014-09-12 16:09:11 -04:00
|
|
|
|
2012-04-15 19:57:10 -04:00
|
|
|
" This is basic vim plugin boilerplate
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|