youcompleteme.vim 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. " Copyright (C) 2011, 2012 Google Inc.
  2. "
  3. " This file is part of YouCompleteMe.
  4. "
  5. " YouCompleteMe is free software: you can redistribute it and/or modify
  6. " it under the terms of the GNU General Public License as published by
  7. " the Free Software Foundation, either version 3 of the License, or
  8. " (at your option) any later version.
  9. "
  10. " YouCompleteMe is distributed in the hope that it will be useful,
  11. " but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. " GNU General Public License for more details.
  14. "
  15. " You should have received a copy of the GNU General Public License
  16. " along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. " This is basic vim plugin boilerplate
  18. let s:save_cpo = &cpo
  19. set cpo&vim
  20. function! s:restore_cpo()
  21. let &cpo = s:save_cpo
  22. unlet s:save_cpo
  23. endfunction
  24. " NOTE: The minimum supported version is 8.2.3995, but neovim always reports as
  25. " v:version 800, but will largely work.
  26. let s:is_neovim = has( 'nvim' )
  27. if exists( "g:loaded_youcompleteme" )
  28. call s:restore_cpo()
  29. finish
  30. elseif ( v:version < 901 || (v:version == 901 && !has( 'patch0016' )) ) &&
  31. \ !s:is_neovim
  32. echohl WarningMsg |
  33. \ echomsg "YouCompleteMe unavailable: requires Vim 9.1.0016+." |
  34. \ echohl None
  35. call s:restore_cpo()
  36. finish
  37. elseif !has( 'timers' )
  38. echohl WarningMsg |
  39. \ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
  40. \ "the timers feature." |
  41. \ echohl None
  42. call s:restore_cpo()
  43. finish
  44. elseif !has( 'python3_compiled' )
  45. echohl WarningMsg |
  46. \ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
  47. \ "Python (3.8.0+) support." |
  48. \ echohl None
  49. call s:restore_cpo()
  50. finish
  51. " These calls try to load the Python 3 libraries when Vim is
  52. " compiled dynamically against them. Since only one can be loaded at a time on
  53. " some platforms, we first check if Python 3 is available.
  54. elseif !has( 'python3' )
  55. echohl WarningMsg |
  56. \ echomsg "YouCompleteMe unavailable: unable to load Python." |
  57. \ echohl None
  58. call s:restore_cpo()
  59. finish
  60. elseif &encoding !~? 'utf-\?8'
  61. echohl WarningMsg |
  62. \ echomsg "YouCompleteMe unavailable: requires UTF-8 encoding. " .
  63. \ "Put the line 'set encoding=utf-8' in your vimrc." |
  64. \ echohl None
  65. call s:restore_cpo()
  66. finish
  67. endif
  68. let g:loaded_youcompleteme = 1
  69. "
  70. " List of YCM options.
  71. "
  72. let g:ycm_filetype_whitelist =
  73. \ get( g:, 'ycm_filetype_whitelist', { "*": 1 } )
  74. let g:ycm_filetype_blacklist =
  75. \ get( g:, 'ycm_filetype_blacklist', {
  76. \ 'tagbar': 1,
  77. \ 'notes': 1,
  78. \ 'markdown': 1,
  79. \ 'netrw': 1,
  80. \ 'unite': 1,
  81. \ 'text': 1,
  82. \ 'vimwiki': 1,
  83. \ 'pandoc': 1,
  84. \ 'infolog': 1,
  85. \ 'leaderf': 1,
  86. \ 'mail': 1
  87. \ } )
  88. " Blacklist empty buffers unless explicity whitelisted; workaround for
  89. " https://github.com/ycm-core/YouCompleteMe/issues/3781
  90. if !has_key( g:ycm_filetype_whitelist, 'ycm_nofiletype' )
  91. let g:ycm_filetype_blacklist.ycm_nofiletype = 1
  92. endif
  93. let g:ycm_open_loclist_on_ycm_diags =
  94. \ get( g:, 'ycm_open_loclist_on_ycm_diags', 1 )
  95. let g:ycm_add_preview_to_completeopt =
  96. \ get( g:, 'ycm_add_preview_to_completeopt', 0 )
  97. let g:ycm_autoclose_preview_window_after_completion =
  98. \ get( g:, 'ycm_autoclose_preview_window_after_completion', 0 )
  99. let g:ycm_autoclose_preview_window_after_insertion =
  100. \ get( g:, 'ycm_autoclose_preview_window_after_insertion', 0 )
  101. let g:ycm_key_list_select_completion =
  102. \ get( g:, 'ycm_key_list_select_completion', ['<TAB>', '<Down>'] )
  103. let g:ycm_key_list_previous_completion =
  104. \ get( g:, 'ycm_key_list_previous_completion', ['<S-TAB>', '<Up>'] )
  105. let g:ycm_key_list_stop_completion =
  106. \ get( g:, 'ycm_key_list_stop_completion', ['<C-y>'] )
  107. let g:ycm_key_invoke_completion =
  108. \ get( g:, 'ycm_key_invoke_completion', '<C-Space>' )
  109. let g:ycm_key_detailed_diagnostics =
  110. \ get( g:, 'ycm_key_detailed_diagnostics', '<leader>d' )
  111. let g:ycm_cache_omnifunc =
  112. \ get( g:, 'ycm_cache_omnifunc', 1 )
  113. let g:ycm_log_level =
  114. \ get( g:, 'ycm_log_level',
  115. \ get( g:, 'ycm_server_log_level', 'info' ) )
  116. let g:ycm_keep_logfiles =
  117. \ get( g:, 'ycm_keep_logfiles',
  118. \ get( g:, 'ycm_server_keep_logfiles', 0 ) )
  119. let g:ycm_extra_conf_vim_data =
  120. \ get( g:, 'ycm_extra_conf_vim_data', [] )
  121. let g:ycm_server_python_interpreter =
  122. \ get( g:, 'ycm_server_python_interpreter',
  123. \ get( g:, 'ycm_path_to_python_interpreter', '' ) )
  124. let g:ycm_show_diagnostics_ui =
  125. \ get( g:, 'ycm_show_diagnostics_ui', 1 )
  126. let g:ycm_enable_diagnostic_signs =
  127. \ get( g:, 'ycm_enable_diagnostic_signs',
  128. \ get( g:, 'syntastic_enable_signs', 1 ) )
  129. let g:ycm_enable_diagnostic_highlighting =
  130. \ get( g:, 'ycm_enable_diagnostic_highlighting',
  131. \ get( g:, 'syntastic_enable_highlighting', 1 ) )
  132. let g:ycm_echo_current_diagnostic =
  133. \ get( g:, 'ycm_echo_current_diagnostic',
  134. \ get( g:, 'syntastic_echo_current_error', 1 ) )
  135. let g:ycm_filter_diagnostics =
  136. \ get( g:, 'ycm_filter_diagnostics', {} )
  137. let g:ycm_always_populate_location_list =
  138. \ get( g:, 'ycm_always_populate_location_list',
  139. \ get( g:, 'syntastic_always_populate_loc_list', 0 ) )
  140. let g:ycm_error_symbol =
  141. \ get( g:, 'ycm_error_symbol',
  142. \ get( g:, 'syntastic_error_symbol', '>>' ) )
  143. let g:ycm_warning_symbol =
  144. \ get( g:, 'ycm_warning_symbol',
  145. \ get( g:, 'syntastic_warning_symbol', '>>' ) )
  146. let g:ycm_complete_in_comments =
  147. \ get( g:, 'ycm_complete_in_comments', 0 )
  148. let g:ycm_complete_in_strings =
  149. \ get( g:, 'ycm_complete_in_strings', 1 )
  150. let g:ycm_collect_identifiers_from_tags_files =
  151. \ get( g:, 'ycm_collect_identifiers_from_tags_files', 0 )
  152. let g:ycm_seed_identifiers_with_syntax =
  153. \ get( g:, 'ycm_seed_identifiers_with_syntax', 0 )
  154. let g:ycm_goto_buffer_command =
  155. \ get( g:, 'ycm_goto_buffer_command', 'same-buffer' )
  156. let g:ycm_disable_for_files_larger_than_kb =
  157. \ get( g:, 'ycm_disable_for_files_larger_than_kb', 1000 )
  158. let g:ycm_auto_hover =
  159. \ get( g:, 'ycm_auto_hover', 'CursorHold' )
  160. let g:ycm_update_diagnostics_in_insert_mode =
  161. \ get( g:, 'ycm_update_diagnostics_in_insert_mode', 1 )
  162. "
  163. " List of ycmd options.
  164. "
  165. let g:ycm_filepath_completion_use_working_dir =
  166. \ get( g:, 'ycm_filepath_completion_use_working_dir', 0 )
  167. let g:ycm_auto_trigger =
  168. \ get( g:, 'ycm_auto_trigger', 1 )
  169. let g:ycm_min_num_of_chars_for_completion =
  170. \ get( g:, 'ycm_min_num_of_chars_for_completion', 2 )
  171. let g:ycm_min_identifier_candidate_chars =
  172. \ get( g:, 'ycm_min_num_identifier_candidate_chars', 0 )
  173. let g:ycm_semantic_triggers =
  174. \ get( g:, 'ycm_semantic_triggers', {} )
  175. let g:ycm_filetype_specific_completion_to_disable =
  176. \ get( g:, 'ycm_filetype_specific_completion_to_disable',
  177. \ { 'gitcommit': 1 } )
  178. let g:ycm_collect_identifiers_from_comments_and_strings =
  179. \ get( g:, 'ycm_collect_identifiers_from_comments_and_strings', 0 )
  180. let g:ycm_max_num_identifier_candidates =
  181. \ get( g:, 'ycm_max_num_identifier_candidates', 10 )
  182. let g:ycm_max_num_candidates =
  183. \ get( g:, 'ycm_max_num_candidates', 50 )
  184. let g:ycm_extra_conf_globlist =
  185. \ get( g:, 'ycm_extra_conf_globlist', [] )
  186. let g:ycm_global_ycm_extra_conf =
  187. \ get( g:, 'ycm_global_ycm_extra_conf', '' )
  188. let g:ycm_confirm_extra_conf =
  189. \ get( g:, 'ycm_confirm_extra_conf', 1 )
  190. let g:ycm_max_diagnostics_to_display =
  191. \ get( g:, 'ycm_max_diagnostics_to_display', 30 )
  192. let g:ycm_filepath_blacklist =
  193. \ get( g:, 'ycm_filepath_blacklist', {
  194. \ 'html': 1,
  195. \ 'jsx': 1,
  196. \ 'xml': 1
  197. \ } )
  198. let g:ycm_auto_start_csharp_server =
  199. \ get( g:, 'ycm_auto_start_csharp_server', 1 )
  200. let g:ycm_auto_stop_csharp_server =
  201. \ get( g:, 'ycm_auto_stop_csharp_server', 1 )
  202. let g:ycm_use_ultisnips_completer =
  203. \ get( g:, 'ycm_use_ultisnips_completer', 1 )
  204. let g:ycm_csharp_server_port =
  205. \ get( g:, 'ycm_csharp_server_port', 0 )
  206. let g:ycm_use_clangd =
  207. \ get( g:, 'ycm_use_clangd', 1 )
  208. let g:ycm_clangd_binary_path =
  209. \ get( g:, 'ycm_clangd_binary_path', '' )
  210. let g:ycm_clangd_args =
  211. \ get( g:, 'ycm_clangd_args', [] )
  212. let g:ycm_clangd_uses_ycmd_caching =
  213. \ get( g:, 'ycm_clangd_uses_ycmd_caching', 1 )
  214. " These options are not documented.
  215. let g:ycm_java_jdtls_extension_path =
  216. \ get( g:, 'ycm_java_jdtls_extension_path', [] )
  217. let g:ycm_java_jdtls_use_clean_workspace =
  218. \ get( g:, 'ycm_java_jdtls_use_clean_workspace', 1 )
  219. let g:ycm_java_jdtls_workspace_root_path =
  220. \ get( g:, 'ycm_java_jdtls_workspace_root_path', '' )
  221. " This option is deprecated.
  222. let g:ycm_python_binary_path =
  223. \ get( g:, 'ycm_python_binary_path', '' )
  224. let g:ycm_refilter_workspace_symbols =
  225. \ get( g:, 'ycm_refilter_workspace_symbols', 1 )
  226. if has( 'vim_starting' ) " Loading at startup.
  227. " We defer loading until after VimEnter to allow the gui to fork (see
  228. " `:h gui-fork`) and avoid a deadlock situation, as explained here:
  229. " https://github.com/Valloric/YouCompleteMe/pull/2473#issuecomment-267716136
  230. augroup youcompletemeStart
  231. autocmd!
  232. autocmd VimEnter * call youcompleteme#Enable()
  233. augroup END
  234. else " Manual loading with :packadd.
  235. call youcompleteme#Enable()
  236. endif
  237. " This is basic vim plugin boilerplate
  238. call s:restore_cpo()