youcompleteme.vim 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. if exists( "g:loaded_youcompleteme" )
  25. call s:restore_cpo()
  26. finish
  27. elseif v:version < 704 || (v:version == 704 && !has( 'patch1578' ))
  28. echohl WarningMsg |
  29. \ echomsg "YouCompleteMe unavailable: requires Vim 7.4.1578+." |
  30. \ echohl None
  31. if v:version == 704 && has( 'patch8056' )
  32. " Very very special case for users of the default Vim on macOS. For some
  33. " reason, that version of Vim contains a completely arbitrary (presumably
  34. " custom) patch '8056', which fools users (but not our has( 'patch1578' )
  35. " check) into thinking they have a sufficiently new Vim. In fact they do
  36. " not and YCM fails to initialise. So we give them a more specific warning.
  37. echohl WarningMsg
  38. \ | echomsg
  39. \ "Info: You appear to be running the default system Vim on macOS. "
  40. \ . "It reports as patch 8056, but it is really older than 1578. "
  41. \ . "Please consider MacVim, homebrew Vim or a self-built Vim that "
  42. \ . "satisfies the minimum requirement."
  43. \ | echohl None
  44. endif
  45. call s:restore_cpo()
  46. finish
  47. elseif !has( 'timers' )
  48. echohl WarningMsg |
  49. \ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
  50. \ "the timers feature." |
  51. \ echohl None
  52. call s:restore_cpo()
  53. finish
  54. elseif ( v:version > 800 || ( v:version == 800 && has( 'patch1436' ) ) ) &&
  55. \ !has( 'python3_compiled' )
  56. echohl WarningMsg |
  57. \ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
  58. \ "Python (3.5.1+) support." |
  59. \ echohl None
  60. call s:restore_cpo()
  61. finish
  62. " These calls try to load the Python 3 libraries when Vim is
  63. " compiled dynamically against them. Since only one can be loaded at a time on
  64. " some platforms, we first check if Python 3 is available.
  65. elseif !has( 'python3' )
  66. echohl WarningMsg |
  67. \ echomsg "YouCompleteMe unavailable: unable to load Python." |
  68. \ echohl None
  69. call s:restore_cpo()
  70. finish
  71. elseif &encoding !~? 'utf-\?8'
  72. echohl WarningMsg |
  73. \ echomsg "YouCompleteMe unavailable: requires UTF-8 encoding. " .
  74. \ "Put the line 'set encoding=utf-8' in your vimrc." |
  75. \ echohl None
  76. call s:restore_cpo()
  77. finish
  78. endif
  79. let g:loaded_youcompleteme = 1
  80. let s:default_options = {}
  81. if exists( '*json_decode' )
  82. let s:script_folder_path = expand( '<sfile>:p:h' )
  83. let s:option_file = s:script_folder_path .
  84. \ '/../third_party/ycmd/ycmd/default_settings.json'
  85. if filereadable( s:option_file )
  86. let s:default_options = json_decode( join( readfile( s:option_file ) ) )
  87. endif
  88. endif
  89. "
  90. " List of YCM options.
  91. "
  92. let g:ycm_filetype_whitelist =
  93. \ get( g:, 'ycm_filetype_whitelist', { "*": 1 } )
  94. let g:ycm_filetype_blacklist =
  95. \ get( g:, 'ycm_filetype_blacklist', {
  96. \ 'tagbar': 1,
  97. \ 'notes': 1,
  98. \ 'markdown': 1,
  99. \ 'netrw': 1,
  100. \ 'unite': 1,
  101. \ 'text': 1,
  102. \ 'vimwiki': 1,
  103. \ 'pandoc': 1,
  104. \ 'infolog': 1,
  105. \ 'leaderf': 1,
  106. \ 'mail': 1
  107. \ } )
  108. let g:ycm_open_loclist_on_ycm_diags =
  109. \ get( g:, 'ycm_open_loclist_on_ycm_diags', 1 )
  110. let g:ycm_add_preview_to_completeopt =
  111. \ get( g:, 'ycm_add_preview_to_completeopt', 0 )
  112. let g:ycm_autoclose_preview_window_after_completion =
  113. \ get( g:, 'ycm_autoclose_preview_window_after_completion', 0 )
  114. let g:ycm_autoclose_preview_window_after_insertion =
  115. \ get( g:, 'ycm_autoclose_preview_window_after_insertion', 0 )
  116. let g:ycm_key_list_select_completion =
  117. \ get( g:, 'ycm_key_list_select_completion', ['<TAB>', '<Down>'] )
  118. let g:ycm_key_list_previous_completion =
  119. \ get( g:, 'ycm_key_list_previous_completion', ['<S-TAB>', '<Up>'] )
  120. let g:ycm_key_list_stop_completion =
  121. \ get( g:, 'ycm_key_list_stop_completion', ['<C-y>'] )
  122. let g:ycm_key_invoke_completion =
  123. \ get( g:, 'ycm_key_invoke_completion', '<C-Space>' )
  124. let g:ycm_key_detailed_diagnostics =
  125. \ get( g:, 'ycm_key_detailed_diagnostics', '<leader>d' )
  126. let g:ycm_cache_omnifunc =
  127. \ get( g:, 'ycm_cache_omnifunc', 1 )
  128. let g:ycm_log_level =
  129. \ get( g:, 'ycm_log_level',
  130. \ get( g:, 'ycm_server_log_level', 'info' ) )
  131. let g:ycm_keep_logfiles =
  132. \ get( g:, 'ycm_keep_logfiles',
  133. \ get( g:, 'ycm_server_keep_logfiles', 0 ) )
  134. let g:ycm_extra_conf_vim_data =
  135. \ get( g:, 'ycm_extra_conf_vim_data', [] )
  136. let g:ycm_server_python_interpreter =
  137. \ get( g:, 'ycm_server_python_interpreter',
  138. \ get( g:, 'ycm_path_to_python_interpreter', '' ) )
  139. let g:ycm_show_diagnostics_ui =
  140. \ get( g:, 'ycm_show_diagnostics_ui', 1 )
  141. let g:ycm_enable_diagnostic_signs =
  142. \ get( g:, 'ycm_enable_diagnostic_signs',
  143. \ get( g:, 'syntastic_enable_signs', 1 ) )
  144. let g:ycm_enable_diagnostic_highlighting =
  145. \ get( g:, 'ycm_enable_diagnostic_highlighting',
  146. \ get( g:, 'syntastic_enable_highlighting', 1 ) )
  147. let g:ycm_echo_current_diagnostic =
  148. \ get( g:, 'ycm_echo_current_diagnostic',
  149. \ get( g:, 'syntastic_echo_current_error', 1 ) )
  150. let g:ycm_filter_diagnostics =
  151. \ get( g:, 'ycm_filter_diagnostics', {} )
  152. let g:ycm_always_populate_location_list =
  153. \ get( g:, 'ycm_always_populate_location_list',
  154. \ get( g:, 'syntastic_always_populate_loc_list', 0 ) )
  155. let g:ycm_error_symbol =
  156. \ get( g:, 'ycm_error_symbol',
  157. \ get( g:, 'syntastic_error_symbol', '>>' ) )
  158. let g:ycm_warning_symbol =
  159. \ get( g:, 'ycm_warning_symbol',
  160. \ get( g:, 'syntastic_warning_symbol', '>>' ) )
  161. let g:ycm_complete_in_comments =
  162. \ get( g:, 'ycm_complete_in_comments', 0 )
  163. let g:ycm_complete_in_strings =
  164. \ get( g:, 'ycm_complete_in_strings', 1 )
  165. let g:ycm_collect_identifiers_from_tags_files =
  166. \ get( g:, 'ycm_collect_identifiers_from_tags_files', 0 )
  167. let g:ycm_seed_identifiers_with_syntax =
  168. \ get( g:, 'ycm_seed_identifiers_with_syntax', 0 )
  169. let g:ycm_goto_buffer_command =
  170. \ get( g:, 'ycm_goto_buffer_command', 'same-buffer' )
  171. let g:ycm_disable_for_files_larger_than_kb =
  172. \ get( g:, 'ycm_disable_for_files_larger_than_kb', 1000 )
  173. "
  174. " List of ycmd options.
  175. "
  176. let g:ycm_filepath_completion_use_working_dir =
  177. \ get( g:, 'ycm_filepath_completion_use_working_dir', 0 )
  178. let g:ycm_auto_trigger =
  179. \ get( g:, 'ycm_auto_trigger', 1 )
  180. let g:ycm_min_num_of_chars_for_completion =
  181. \ get( g:, 'ycm_min_num_of_chars_for_completion', 2 )
  182. let g:ycm_min_identifier_candidate_chars =
  183. \ get( g:, 'ycm_min_num_identifier_candidate_chars', 0 )
  184. let g:ycm_semantic_triggers =
  185. \ get( g:, 'ycm_semantic_triggers', {} )
  186. let g:ycm_filetype_specific_completion_to_disable =
  187. \ get( g:, 'ycm_filetype_specific_completion_to_disable',
  188. \ { 'gitcommit': 1 } )
  189. let g:ycm_collect_identifiers_from_comments_and_strings =
  190. \ get( g:, 'ycm_collect_identifiers_from_comments_and_strings', 0 )
  191. let g:ycm_max_num_identifier_candidates =
  192. \ get( g:, 'ycm_max_num_identifier_candidates', 10 )
  193. let g:ycm_max_num_candidates =
  194. \ get( g:, 'ycm_max_num_candidates', 50 )
  195. let g:ycm_extra_conf_globlist =
  196. \ get( g:, 'ycm_extra_conf_globlist', [] )
  197. let g:ycm_global_ycm_extra_conf =
  198. \ get( g:, 'ycm_global_ycm_extra_conf', '' )
  199. let g:ycm_confirm_extra_conf =
  200. \ get( g:, 'ycm_confirm_extra_conf', 1 )
  201. let g:ycm_max_diagnostics_to_display =
  202. \ get( g:, 'ycm_max_diagnostics_to_display', 30 )
  203. let g:ycm_filepath_blacklist =
  204. \ get( g:, 'ycm_filepath_blacklist', {
  205. \ 'html': 1,
  206. \ 'jsx': 1,
  207. \ 'xml': 1
  208. \ } )
  209. let g:ycm_auto_start_csharp_server =
  210. \ get( g:, 'ycm_auto_start_csharp_server', 1 )
  211. let g:ycm_auto_stop_csharp_server =
  212. \ get( g:, 'ycm_auto_stop_csharp_server', 1 )
  213. let g:ycm_use_ultisnips_completer =
  214. \ get( g:, 'ycm_use_ultisnips_completer', 1 )
  215. let g:ycm_csharp_server_port =
  216. \ get( g:, 'ycm_csharp_server_port', 0 )
  217. let g:ycm_use_clangd =
  218. \ get( g:, 'ycm_use_clangd', 1 )
  219. let g:ycm_clangd_binary_path =
  220. \ get( g:, 'ycm_clangd_binary_path', '' )
  221. let g:ycm_clangd_args =
  222. \ get( g:, 'ycm_clangd_args', [] )
  223. let g:ycm_clangd_uses_ycmd_caching =
  224. \ get( g:, 'ycm_clangd_uses_ycmd_caching', 1 )
  225. " These options are not documented.
  226. let g:ycm_java_jdtls_extension_path =
  227. \ get( g:, 'ycm_java_jdtls_extension_path', [] )
  228. let g:ycm_java_jdtls_use_clean_workspace =
  229. \ get( g:, 'ycm_java_jdtls_use_clean_workspace', 1 )
  230. let g:ycm_java_jdtls_workspace_root_path =
  231. \ get( g:, 'ycm_java_jdtls_workspace_root_path', '' )
  232. " This option is deprecated.
  233. let g:ycm_python_binary_path =
  234. \ get( g:, 'ycm_python_binary_path', '' )
  235. " Populate any other (undocumented) options set in the ycmd
  236. " default_settings.json. This ensures that any part of ycm that uses ycmd code
  237. " will have the default set. I'm looking at you, Omni-completer.
  238. for key in keys( s:default_options )
  239. if ! has_key( g:, 'ycm_' . key )
  240. let g:[ 'ycm_' . key ] = s:default_options[ key ]
  241. endif
  242. endfor
  243. unlet key
  244. if has( 'vim_starting' ) " Loading at startup.
  245. " We defer loading until after VimEnter to allow the gui to fork (see
  246. " `:h gui-fork`) and avoid a deadlock situation, as explained here:
  247. " https://github.com/Valloric/YouCompleteMe/pull/2473#issuecomment-267716136
  248. augroup youcompletemeStart
  249. autocmd!
  250. autocmd VimEnter * call youcompleteme#Enable()
  251. augroup END
  252. else " Manual loading with :packadd.
  253. call youcompleteme#Enable()
  254. endif
  255. " This is basic vim plugin boilerplate
  256. call s:restore_cpo()