2014-01-13 14:08:43 -05:00
|
|
|
" Copyright (C) 2011, 2012 Google Inc.
|
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' ), '\' )
|
2012-07-28 01:16:23 -04:00
|
|
|
let s:omnifunc_mode = 0
|
2015-11-13 08:26:04 -05:00
|
|
|
let s:defer_omnifunc = 1
|
2012-08-20 23:55:25 -04:00
|
|
|
|
2012-08-12 00:20:17 -04:00
|
|
|
let s:old_cursor_position = []
|
|
|
|
let s:cursor_moved = 0
|
2013-08-03 21:42:16 -04:00
|
|
|
let s:moved_vertically_in_insert_mode = 0
|
2015-07-22 16:03:13 -04:00
|
|
|
let s:previous_num_chars_on_current_line = strlen( getline('.') )
|
2012-05-12 18:20:03 -04:00
|
|
|
|
2016-02-29 13:26:50 -05:00
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
function! s:UsingPython2()
|
|
|
|
" I'm willing to bet quite a bit that sooner or later, somebody will ask us to
|
|
|
|
" make it configurable which version of Python we use.
|
|
|
|
if has('python')
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
2016-02-29 13:26:50 -05:00
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
let s:using_python2 = s:UsingPython2()
|
|
|
|
let s:python_until_eof = s:using_python2 ? "python << EOF" : "python3 << EOF"
|
|
|
|
let s:python_command = s:using_python2 ? "py " : "py3 "
|
|
|
|
|
2016-02-29 13:26:50 -05:00
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
function! s:Pyeval( eval_string )
|
|
|
|
if s:using_python2
|
|
|
|
return pyeval( a:eval_string )
|
|
|
|
endif
|
|
|
|
return py3eval( a:eval_string )
|
|
|
|
endfunction
|
|
|
|
|
2013-10-04 13:30:58 -04:00
|
|
|
|
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-02-15 19:56:34 -05:00
|
|
|
if g:ycm_allow_changing_updatetime && &updatetime > 2000
|
2013-09-02 14:34:18 -04:00
|
|
|
set ut=2000
|
|
|
|
endif
|
|
|
|
|
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
|
|
|
|
" that happens *after" BufRead/BufEnter has already triggered for the
|
|
|
|
" initial file.
|
2013-10-06 22:45:47 -04:00
|
|
|
" We also need to trigger buf init code on the FileType event because when
|
|
|
|
" the user does :enew and then :set ft=something, we need to run buf init
|
|
|
|
" code again.
|
2014-12-03 04:38:02 -05:00
|
|
|
autocmd BufReadPre * call s:OnBufferReadPre( expand( '<afile>:p' ) )
|
2013-10-06 22:45:47 -04:00
|
|
|
autocmd BufRead,BufEnter,FileType * call s:OnBufferVisit()
|
2013-05-11 16:49:48 -04:00
|
|
|
autocmd BufUnload * call s:OnBufferUnload( expand( '<afile>:p' ) )
|
2012-05-12 18:26:04 -04:00
|
|
|
autocmd CursorHold,CursorHoldI * call s:OnCursorHold()
|
2012-07-28 14:42:43 -04:00
|
|
|
autocmd InsertLeave * call s:OnInsertLeave()
|
2012-08-12 00:20:17 -04:00
|
|
|
autocmd InsertEnter * call s:OnInsertEnter()
|
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
|
|
|
|
|
2015-12-30 18:12:38 -05:00
|
|
|
" Setting the omnifunc require us to ask the server if it has a Native
|
|
|
|
" Semantic Completer for the current buffer's filetype. When vim first start
|
|
|
|
" this mean that we have to wait for the server to be up and running which
|
|
|
|
" would block vim's GUI. To avoid this we defer setting the omnifunc the
|
|
|
|
" first time to when we enter Insert mode and then update it on every
|
|
|
|
" BufferVisit as normal.
|
2015-11-13 08:26:04 -05:00
|
|
|
if s:defer_omnifunc
|
|
|
|
augroup ycm_defer_omnifunc
|
|
|
|
autocmd!
|
|
|
|
autocmd InsertEnter * call s:SetOmnicompleteFunc()
|
|
|
|
\ | let s:defer_omnifunc = 0
|
|
|
|
\ | autocmd! ycm_defer_omnifunc
|
|
|
|
augroup END
|
|
|
|
endif
|
|
|
|
|
2014-12-03 04:38:02 -05:00
|
|
|
" Calling these once solves the problem of BufReadPre/BufRead/BufEnter not
|
|
|
|
" triggering for the first loaded file. This should be the last commands
|
|
|
|
" executed in this function!
|
|
|
|
call s:OnBufferReadPre( expand( '<afile>:p' ) )
|
2013-02-08 21:29:36 -05:00
|
|
|
call s:OnBufferVisit()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2014-10-14 13:08:47 -04:00
|
|
|
function! youcompleteme#EnableCursorMovedAutocommands()
|
2014-09-15 15:39:05 -04:00
|
|
|
augroup ycmcompletemecursormove
|
|
|
|
autocmd!
|
|
|
|
autocmd CursorMovedI * call s:OnCursorMovedInsertMode()
|
|
|
|
autocmd CursorMoved * call s:OnCursorMovedNormalMode()
|
|
|
|
augroup END
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2014-10-14 13:08:47 -04:00
|
|
|
function! youcompleteme#DisableCursorMovedAutocommands()
|
2014-09-15 15:39:05 -04:00
|
|
|
autocmd! ycmcompletemecursormove CursorMoved *
|
|
|
|
autocmd! ycmcompletemecursormove CursorMovedI *
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2013-02-06 21:32:47 -05:00
|
|
|
" <c-x><c-o> trigger omni completion, <c-p> deselects the first completion
|
|
|
|
" candidate that vim selects by default
|
2013-04-19 21:33:06 -04:00
|
|
|
silent! exe 'inoremap <unique> ' . invoke_key . ' <C-X><C-O><C-P>'
|
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 .
|
2013-02-06 21:32:47 -05:00
|
|
|
\ ' :YcmShowDetailedDiagnostic<cr>'
|
|
|
|
endif
|
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
|
|
|
|
|
|
|
|
|
2012-08-13 22:01:55 -04:00
|
|
|
function! s:AllowedToCompleteInCurrentFile()
|
2013-11-16 13:31:34 -05:00
|
|
|
if empty( &filetype ) ||
|
|
|
|
\ getbufvar( winbufnr( winnr() ), "&buftype" ) ==# 'nofile' ||
|
|
|
|
\ &filetype ==# 'qf'
|
2013-03-09 23:30:10 -05:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2014-12-03 04:38:02 -05:00
|
|
|
if exists( 'b:ycm_largefile' )
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2013-03-09 23:30:10 -05:00
|
|
|
let whitelist_allows = has_key( g:ycm_filetype_whitelist, '*' ) ||
|
|
|
|
\ has_key( g:ycm_filetype_whitelist, &filetype )
|
|
|
|
let blacklist_allows = !has_key( g:ycm_filetype_blacklist, &filetype )
|
|
|
|
|
|
|
|
return whitelist_allows && blacklist_allows
|
2012-08-13 22:01:55 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2015-10-12 09:27:30 -04:00
|
|
|
function! s:SetUpCommands()
|
|
|
|
command! YcmRestartServer call s:RestartServer()
|
|
|
|
command! YcmShowDetailedDiagnostic call s:ShowDetailedDiagnostic()
|
|
|
|
command! YcmDebugInfo call s:DebugInfo()
|
2015-10-27 12:00:11 -04:00
|
|
|
command! -nargs=? -complete=custom,youcompleteme#LogsComplete
|
|
|
|
\ YcmToggleLogs call s:ToggleLogs(<f-args>)
|
2015-10-12 09:27:30 -04:00
|
|
|
command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete
|
|
|
|
\ YcmCompleter call s:CompleterCommand(<f-args>)
|
|
|
|
command! YcmForceCompileAndDiagnostics call s:ForceCompileAndDiagnostics()
|
|
|
|
command! YcmDiags call s:ShowDiagnostics()
|
|
|
|
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
|
2014-05-28 18:48:49 -04:00
|
|
|
" completion. This is only available since Vim 7.4.314
|
2016-02-28 16:54:49 -05:00
|
|
|
if s:Pyeval( 'vimsupport.VimVersionAtLeast("7.4.314")' )
|
2014-01-10 18:01:30 -05:00
|
|
|
set shortmess+=c
|
2014-05-28 18:48:49 -04:00
|
|
|
endif
|
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
|
|
|
|
|
|
|
" For various functions/use-cases, we want to keep track of whether the buffer
|
|
|
|
" has changed since the last time they were invoked. We keep the state of
|
|
|
|
" b:changedtick of the last time the specific function was called in
|
|
|
|
" b:ycm_changedtick.
|
|
|
|
function! s:SetUpYcmChangedTick()
|
|
|
|
let b:ycm_changedtick =
|
|
|
|
\ get( b:, 'ycm_changedtick', {
|
|
|
|
\ 'file_ready_to_parse' : -1,
|
|
|
|
\ } )
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-04-12 19:15:31 -04:00
|
|
|
function! s:OnVimLeave()
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnVimLeave()"
|
2013-04-12 19:15:31 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-08-13 23:47:45 -04:00
|
|
|
|
2015-08-28 10:26:18 -04:00
|
|
|
function! s:OnCompleteDone()
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnCompleteDone()"
|
2015-08-28 10:26:18 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2014-12-03 04:38:02 -05:00
|
|
|
function! s:OnBufferReadPre(filename)
|
|
|
|
let threshold = g:ycm_disable_for_files_larger_than_kb * 1024
|
|
|
|
|
|
|
|
if threshold > 0 && getfsize( a:filename ) > threshold
|
|
|
|
echohl WarningMsg |
|
|
|
|
\ echomsg "YouCompleteMe is disabled in this buffer; " .
|
|
|
|
\ "the file exceeded the max size (see YCM options)." |
|
|
|
|
\ echohl None
|
|
|
|
let b:ycm_largefile = 1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2012-05-12 18:23:45 -04:00
|
|
|
function! s:OnBufferVisit()
|
2013-08-07 19:54:14 -04:00
|
|
|
" We need to do this even when we are not allowed to complete in the current
|
|
|
|
" file because we might be allowed to complete in the future! The canonical
|
|
|
|
" example is creating a new buffer with :enew and then setting a filetype.
|
|
|
|
call s:SetUpYcmChangedTick()
|
|
|
|
|
2012-08-13 22:01:55 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentFile()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-08-13 23:47:45 -04:00
|
|
|
call s:SetUpCompleteopt()
|
2012-05-12 18:23:45 -04:00
|
|
|
call s:SetCompleteFunc()
|
2015-11-13 08:26:04 -05:00
|
|
|
|
|
|
|
if !s:defer_omnifunc
|
|
|
|
call s:SetOmnicompleteFunc()
|
|
|
|
endif
|
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnBufferVisit()"
|
2012-08-04 20:46:54 -04:00
|
|
|
call s:OnFileReadyToParse()
|
2012-05-12 18:23:45 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-05-11 16:49:48 -04:00
|
|
|
function! s:OnBufferUnload( deleted_buffer_file )
|
2013-03-14 23:39:44 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentFile() || empty( a:deleted_buffer_file )
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnBufferUnload("
|
|
|
|
\ "vim.eval( 'a:deleted_buffer_file' ) )"
|
2013-03-14 23:39:44 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-05-12 18:26:04 -04:00
|
|
|
function! s:OnCursorHold()
|
2012-08-13 22:01:55 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentFile()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-08-13 23:47:45 -04:00
|
|
|
call s:SetUpCompleteopt()
|
2012-08-12 17:36:36 -04:00
|
|
|
call s:OnFileReadyToParse()
|
2012-05-12 18:26:04 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-08-04 20:46:54 -04:00
|
|
|
function! s:OnFileReadyToParse()
|
2013-08-13 13:02:59 -04:00
|
|
|
" We need to call this just in case there is no b:ycm_changetick; this can
|
|
|
|
" happen for special buffers.
|
|
|
|
call s:SetUpYcmChangedTick()
|
|
|
|
|
2016-01-11 14:16:49 -05:00
|
|
|
" Order is important here; we need to extract any information before
|
2013-10-03 16:15:43 -04:00
|
|
|
" reparsing the file again. If we sent the new parse request first, then
|
|
|
|
" the response would always be pending when we called
|
2016-01-11 14:16:49 -05:00
|
|
|
" HandleFileParseRequest.
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.HandleFileParseRequest()"
|
2013-10-03 16:15:43 -04:00
|
|
|
|
2013-08-03 18:47:11 -04:00
|
|
|
let buffer_changed = b:changedtick != b:ycm_changedtick.file_ready_to_parse
|
|
|
|
if buffer_changed
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnFileReadyToParse()"
|
2013-08-03 18:47:11 -04:00
|
|
|
endif
|
|
|
|
let b:ycm_changedtick.file_ready_to_parse = b:changedtick
|
2012-07-26 23:50:56 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-07-28 01:16:23 -04:00
|
|
|
|
2012-04-15 19:57:10 -04:00
|
|
|
function! s:SetCompleteFunc()
|
|
|
|
let &completefunc = 'youcompleteme#Complete'
|
|
|
|
let &l:completefunc = 'youcompleteme#Complete'
|
2015-06-11 16:10:40 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-07-28 01:16:23 -04:00
|
|
|
|
2015-06-11 16:10:40 -04:00
|
|
|
function! s:SetOmnicompleteFunc()
|
2016-02-28 16:54:49 -05:00
|
|
|
if s:Pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' )
|
2012-08-04 20:46:54 -04:00
|
|
|
let &omnifunc = 'youcompleteme#OmniComplete'
|
|
|
|
let &l:omnifunc = 'youcompleteme#OmniComplete'
|
2013-02-12 00:45:42 -05:00
|
|
|
|
|
|
|
" If we don't have native filetype support but the omnifunc is set to YCM's
|
|
|
|
" omnifunc because the previous file the user was editing DID have native
|
|
|
|
" support, we remove our omnifunc.
|
|
|
|
elseif &omnifunc == 'youcompleteme#OmniComplete'
|
|
|
|
let &omnifunc = ''
|
|
|
|
let &l:omnifunc = ''
|
2012-07-28 01:16:23 -04:00
|
|
|
endif
|
2012-04-15 19:57:10 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-07-30 01:08:02 -04:00
|
|
|
function! s:OnCursorMovedInsertMode()
|
2012-08-13 22:01:55 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentFile()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnCursorMoved()"
|
2012-08-12 00:20:17 -04:00
|
|
|
call s:UpdateCursorMoved()
|
2012-08-20 23:55:25 -04:00
|
|
|
|
|
|
|
" Basically, we need to only trigger the completion menu when the user has
|
|
|
|
" inserted or deleted a character, NOT just when the user moves in insert mode
|
|
|
|
" (with, say, the arrow keys). If we trigger the menu even on pure moves, then
|
|
|
|
" it's impossible to move in insert mode since the up/down arrows start moving
|
|
|
|
" the selected completion in the completion menu. Yeah, people shouldn't be
|
|
|
|
" moving in insert mode at all (that's what normal mode is for) but explain
|
|
|
|
" that to the users who complain...
|
|
|
|
if !s:BufferTextChangedSinceLastMoveInInsertMode()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-07-28 01:16:23 -04:00
|
|
|
call s:IdentifierFinishedOperations()
|
2013-03-15 14:43:09 -04:00
|
|
|
if g:ycm_autoclose_preview_window_after_completion
|
|
|
|
call s:ClosePreviewWindowIfNeeded()
|
|
|
|
endif
|
2013-12-02 19:36:53 -05:00
|
|
|
|
2013-12-03 15:55:05 -05:00
|
|
|
if g:ycm_auto_trigger || s:omnifunc_mode
|
2013-12-02 19:36:53 -05:00
|
|
|
call s:InvokeCompletion()
|
|
|
|
endif
|
2013-12-03 17:38:23 -05:00
|
|
|
|
|
|
|
" We have to make sure we correctly leave omnifunc mode even when the user
|
|
|
|
" inserts something like a "operator[]" candidate string which fails
|
|
|
|
" CurrentIdentifierFinished check.
|
2016-02-28 16:54:49 -05:00
|
|
|
if s:omnifunc_mode && !s:Pyeval( 'base.LastEnteredCharIsIdentifierChar()')
|
2013-12-03 17:38:23 -05:00
|
|
|
let s:omnifunc_mode = 0
|
|
|
|
endif
|
2012-04-15 19:57:10 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-05-12 18:20:03 -04:00
|
|
|
|
2012-07-30 22:42:41 -04:00
|
|
|
function! s:OnCursorMovedNormalMode()
|
2012-08-13 22:01:55 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentFile()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-08-13 17:03:57 -04:00
|
|
|
call s:OnFileReadyToParse()
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnCursorMoved()"
|
2012-07-30 22:42:41 -04:00
|
|
|
endfunction
|
2012-07-30 01:08:02 -04:00
|
|
|
|
|
|
|
|
2012-07-28 14:42:43 -04:00
|
|
|
function! s:OnInsertLeave()
|
2012-08-13 22:01:55 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentFile()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-07-28 14:42:43 -04:00
|
|
|
let s:omnifunc_mode = 0
|
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
|
|
|
|
|
|
|
|
|
2012-08-12 00:20:17 -04:00
|
|
|
function! s:OnInsertEnter()
|
2015-07-22 16:03:13 -04:00
|
|
|
let s:previous_num_chars_on_current_line = strlen( getline('.') )
|
|
|
|
|
2012-08-13 22:01:55 -04:00
|
|
|
if !s:AllowedToCompleteInCurrentFile()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-08-12 00:20:17 -04:00
|
|
|
let s:old_cursor_position = []
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:UpdateCursorMoved()
|
|
|
|
let current_position = getpos('.')
|
|
|
|
let s:cursor_moved = current_position != s:old_cursor_position
|
2012-08-20 23:55:25 -04:00
|
|
|
|
|
|
|
let s:moved_vertically_in_insert_mode = s:old_cursor_position != [] &&
|
|
|
|
\ current_position[ 1 ] != s:old_cursor_position[ 1 ]
|
|
|
|
|
2012-08-12 00:20:17 -04:00
|
|
|
let s:old_cursor_position = current_position
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-08-20 23:55:25 -04:00
|
|
|
function! s:BufferTextChangedSinceLastMoveInInsertMode()
|
2013-08-03 21:42:16 -04:00
|
|
|
let num_chars_in_current_cursor_line = strlen( getline('.') )
|
|
|
|
|
2015-07-22 16:03:13 -04:00
|
|
|
if s:moved_vertically_in_insert_mode
|
2013-08-03 21:42:16 -04:00
|
|
|
let s:previous_num_chars_on_current_line = num_chars_in_current_cursor_line
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
let changed_text_on_current_line = num_chars_in_current_cursor_line !=
|
|
|
|
\ s:previous_num_chars_on_current_line
|
|
|
|
let s:previous_num_chars_on_current_line = num_chars_in_current_cursor_line
|
|
|
|
|
|
|
|
return changed_text_on_current_line
|
2012-08-20 23:55:25 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-08-07 00:29:56 -04:00
|
|
|
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()"
|
2012-07-28 01:16:23 -04:00
|
|
|
let s:omnifunc_mode = 0
|
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()
|
|
|
|
if &completefunc != "youcompleteme#Complete"
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-04-25 02:15:13 -04:00
|
|
|
if s:InsideCommentOrStringAndShouldStop() || s:OnBlankLine()
|
2012-06-24 15:04:45 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-07-10 18:26:07 -04:00
|
|
|
" This is tricky. First, having 'refresh' set to 'always' in the dictionary
|
|
|
|
" that our completion function returns makes sure that our completion function
|
2013-01-13 23:56:10 -05:00
|
|
|
" is called on every keystroke. Second, when the sequence of characters the
|
2012-08-13 22:01:55 -04:00
|
|
|
" user typed produces no results in our search an infinite loop can occur. The
|
|
|
|
" problem is that our feedkeys call triggers the OnCursorMovedI event which we
|
|
|
|
" are tied to. We prevent this infinite loop from starting by making sure that
|
|
|
|
" the user has moved the cursor since the last time we provided completion
|
|
|
|
" results.
|
2012-08-12 00:20:17 -04:00
|
|
|
if !s:cursor_moved
|
2012-04-15 19:57:10 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" <c-x><c-u> invokes the user's completion function (which we have set to
|
2012-07-10 18:26:07 -04:00
|
|
|
" youcompleteme#Complete), and <c-p> tells Vim to select the previous
|
|
|
|
" completion candidate. This is necessary because by default, Vim selects the
|
2012-04-15 19:57:10 -04:00
|
|
|
" first candidate when completion is invoked, and selecting a candidate
|
2012-07-10 18:26:07 -04:00
|
|
|
" automatically replaces the current text with it. Calling <c-p> forces Vim to
|
2012-04-15 19:57:10 -04:00
|
|
|
" deselect the first candidate and in turn preserve the user's current text
|
|
|
|
" until he explicitly chooses to replace it with a completion.
|
|
|
|
call feedkeys( "\<C-X>\<C-U>\<C-P>", 'n' )
|
|
|
|
endfunction
|
|
|
|
|
2012-05-12 18:20:03 -04:00
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_until_eof
|
2014-05-27 17:29:19 -04:00
|
|
|
def GetCompletionsInner():
|
2013-09-02 22:46:30 -04:00
|
|
|
request = ycm_state.GetCurrentCompletionRequest()
|
2014-05-27 17:29:19 -04:00
|
|
|
request.Start()
|
2013-10-01 19:21:17 -04:00
|
|
|
while not request.Done():
|
2013-09-02 22:46:30 -04:00
|
|
|
if bool( int( vim.eval( 'complete_check()' ) ) ):
|
|
|
|
return { 'words' : [], 'refresh' : 'always'}
|
2012-07-10 18:26:07 -04:00
|
|
|
|
2013-10-01 19:21:17 -04:00
|
|
|
results = base.AdjustCandidateInsertionText( request.Response() )
|
2013-09-02 22:46:30 -04:00
|
|
|
return { 'words' : results, 'refresh' : 'always' }
|
|
|
|
EOF
|
2012-07-15 23:49:56 -04:00
|
|
|
|
|
|
|
|
2014-05-27 17:29:19 -04:00
|
|
|
function! s:GetCompletions()
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "results = GetCompletionsInner()"
|
|
|
|
let results = s:Pyeval( 'results' )
|
2013-09-02 22:46:30 -04:00
|
|
|
return results
|
2012-07-10 18:26:07 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
" This is our main entry point. This is what vim calls to get completions.
|
|
|
|
function! youcompleteme#Complete( findstart, base )
|
2012-08-04 20:46:54 -04:00
|
|
|
" After the user types one character after the call to the omnifunc, the
|
2012-07-28 01:16:23 -04:00
|
|
|
" completefunc will be called because of our mapping that calls the
|
|
|
|
" completefunc on every keystroke. Therefore we need to delegate the call we
|
|
|
|
" 'stole' back to the omnifunc
|
|
|
|
if s:omnifunc_mode
|
2012-08-04 20:46:54 -04:00
|
|
|
return youcompleteme#OmniComplete( a:findstart, a:base )
|
2012-07-28 01:16:23 -04:00
|
|
|
endif
|
|
|
|
|
2012-07-10 18:26:07 -04:00
|
|
|
if a:findstart
|
2012-08-12 00:20:17 -04:00
|
|
|
" InvokeCompletion has this check but we also need it here because of random
|
|
|
|
" Vim bugs and unfortunate interactions with the autocommands of other
|
|
|
|
" plugins
|
|
|
|
if !s:cursor_moved
|
|
|
|
" for vim, -2 means not found but don't trigger an error message
|
|
|
|
" see :h complete-functions
|
|
|
|
return -2
|
|
|
|
endif
|
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
if !s:Pyeval( 'ycm_state.IsServerAlive()' )
|
2013-10-15 18:27:54 -04:00
|
|
|
return -2
|
|
|
|
endif
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.CreateCompletionRequest()"
|
|
|
|
return s:Pyeval( 'base.CompletionStartColumn()' )
|
2012-07-10 18:26:07 -04:00
|
|
|
else
|
2014-05-27 17:29:19 -04:00
|
|
|
return s:GetCompletions()
|
2012-04-15 19:57:10 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2012-07-28 01:16:23 -04:00
|
|
|
|
2012-08-04 20:46:54 -04:00
|
|
|
function! youcompleteme#OmniComplete( findstart, base )
|
2012-07-28 01:16:23 -04:00
|
|
|
if a:findstart
|
2016-02-28 16:54:49 -05:00
|
|
|
if !s:Pyeval( 'ycm_state.IsServerAlive()' )
|
2014-05-27 20:38:34 -04:00
|
|
|
return -2
|
|
|
|
endif
|
2012-07-28 01:16:23 -04:00
|
|
|
let s:omnifunc_mode = 1
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.CreateCompletionRequest("
|
|
|
|
\ "force_semantic = True )"
|
|
|
|
return s:Pyeval( 'base.CompletionStartColumn()' )
|
2012-07-28 01:16:23 -04:00
|
|
|
else
|
2014-05-27 17:29:19 -04:00
|
|
|
return s:GetCompletions()
|
2012-07-28 01:16:23 -04:00
|
|
|
endif
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2013-10-15 18:27:54 -04:00
|
|
|
function! s:RestartServer()
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.RestartServer()"
|
2013-10-15 18:27:54 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2012-08-15 22:39:03 -04:00
|
|
|
function! s:ShowDetailedDiagnostic()
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.ShowDetailedDiagnostic()"
|
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(...)
|
2015-11-11 08:15:01 -05:00
|
|
|
let stderr = a:0 == 0 || a:1 !=? 'stdout'
|
|
|
|
let stdout = a:0 == 0 || a:1 !=? 'stderr'
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.ToggleLogs("
|
|
|
|
\ "stdout = vimsupport.GetBoolValue( 'l:stdout' ),"
|
|
|
|
\ "stderr = vimsupport.GetBoolValue( 'l:stderr' ) )"
|
2015-10-27 12:00:11 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-02-25 09:14:01 -05:00
|
|
|
function! s:CompleterCommand(...)
|
|
|
|
" 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
|
2013-09-27 16:52:04 -04:00
|
|
|
" no completer was specified this throws an error. You can use
|
|
|
|
" "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
|
|
|
|
|
2016-02-28 16:54:49 -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
|
|
|
|
2013-05-03 19:11:10 -04:00
|
|
|
function! youcompleteme#OpenGoToList()
|
2016-05-31 04:40:25 -04:00
|
|
|
exec s:python_command "vimsupport.PostVimMessage("
|
|
|
|
\ "'WARNING: youcompleteme#OpenGoToList function is deprecated."
|
|
|
|
\ "Do NOT use it.')"
|
|
|
|
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
|
|
|
|
2015-10-27 12:00:11 -04:00
|
|
|
function! youcompleteme#LogsComplete( arglead, cmdline, cursorpos )
|
2015-11-11 08:15:01 -05:00
|
|
|
return "stdout\nstderr"
|
2015-10-27 12:00:11 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-09-27 19:20:35 -04:00
|
|
|
function! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos )
|
2016-02-28 16:54:49 -05:00
|
|
|
return join( s:Pyeval( 'ycm_state.GetDefinedSubcommands()' ),
|
2013-09-27 19:20:35 -04:00
|
|
|
\ "\n")
|
|
|
|
endfunction
|
2013-01-26 14:44:42 -05:00
|
|
|
|
2013-05-09 23:28:04 -04:00
|
|
|
|
2013-01-31 22:21:11 -05:00
|
|
|
function! s:ForceCompile()
|
2016-02-28 16:54:49 -05:00
|
|
|
if !s:Pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' )
|
2013-02-12 23:30:14 -05:00
|
|
|
echom "Native filetype completion not supported for current file, "
|
2013-01-30 17:46:58 -05:00
|
|
|
\ . "cannot force recompilation."
|
2013-02-12 23:54:27 -05:00
|
|
|
return 0
|
2013-01-30 17:46:58 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
echom "Forcing compilation, this will block Vim until done."
|
2016-02-28 16:54:49 -05:00
|
|
|
exec s:python_command "ycm_state.OnFileReadyToParse()"
|
|
|
|
exec s:python_command "ycm_state.HandleFileParseRequest( True )"
|
2013-02-06 00:22:50 -05:00
|
|
|
|
|
|
|
return 1
|
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()
|
2013-02-06 00:22:50 -05:00
|
|
|
let compilation_succeeded = s:ForceCompile()
|
|
|
|
if !compilation_succeeded
|
|
|
|
return
|
|
|
|
endif
|
2013-01-30 17:46:58 -05:00
|
|
|
echom "Diagnostics refreshed."
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2013-01-31 22:21:11 -05:00
|
|
|
function! s:ShowDiagnostics()
|
2013-03-17 21:52:42 -04:00
|
|
|
let compilation_succeeded = s:ForceCompile()
|
|
|
|
if !compilation_succeeded
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-02-28 16:54:49 -05:00
|
|
|
if s:Pyeval( 'ycm_state.PopulateLocationListWithLatestDiagnostics()' )
|
2014-01-29 13:59:15 -05:00
|
|
|
if g:ycm_open_loclist_on_ycm_diags
|
|
|
|
lopen
|
|
|
|
endif
|
2013-01-31 22:21:11 -05:00
|
|
|
else
|
|
|
|
echom "No warnings or errors detected"
|
|
|
|
endif
|
|
|
|
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
|