youcompleteme.vim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. call s:restore_cpo()
  32. finish
  33. elseif !has( 'timers' )
  34. echohl WarningMsg |
  35. \ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
  36. \ "the timers feature" |
  37. \ echohl None
  38. call s:restore_cpo()
  39. finish
  40. elseif !has( 'python' ) && !has( 'python3' )
  41. echohl WarningMsg |
  42. \ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
  43. \ "Python (2.6+ or 3.3+) support" |
  44. \ echohl None
  45. call s:restore_cpo()
  46. finish
  47. endif
  48. let g:loaded_youcompleteme = 1
  49. " NOTE: Most defaults are in third_party/ycmd/ycmd/default_settings.json. They
  50. " are loaded into Vim globals with the 'ycm_' prefix if such a key does not
  51. " already exist; thus, the user can override the defaults.
  52. " The only defaults that are here are the ones that are only relevant to the YCM
  53. " Vim client and not the ycmd server.
  54. let g:ycm_open_loclist_on_ycm_diags =
  55. \ get( g:, 'ycm_open_loclist_on_ycm_diags', 1 )
  56. let g:ycm_add_preview_to_completeopt =
  57. \ get( g:, 'ycm_add_preview_to_completeopt', 0 )
  58. let g:ycm_autoclose_preview_window_after_completion =
  59. \ get( g:, 'ycm_autoclose_preview_window_after_completion', 0 )
  60. let g:ycm_autoclose_preview_window_after_insertion =
  61. \ get( g:, 'ycm_autoclose_preview_window_after_insertion', 0 )
  62. let g:ycm_key_list_select_completion =
  63. \ get( g:, 'ycm_key_list_select_completion', ['<TAB>', '<Down>'] )
  64. let g:ycm_key_list_previous_completion =
  65. \ get( g:, 'ycm_key_list_previous_completion', ['<S-TAB>', '<Up>'] )
  66. let g:ycm_key_invoke_completion =
  67. \ get( g:, 'ycm_key_invoke_completion', '<C-Space>' )
  68. let g:ycm_key_detailed_diagnostics =
  69. \ get( g:, 'ycm_key_detailed_diagnostics', '<leader>d' )
  70. let g:ycm_cache_omnifunc =
  71. \ get( g:, 'ycm_cache_omnifunc', 1 )
  72. let g:ycm_log_level =
  73. \ get( g:, 'ycm_log_level',
  74. \ get( g:, 'ycm_server_log_level', 'info' ) )
  75. let g:ycm_keep_logfiles =
  76. \ get( g:, 'ycm_keep_logfiles',
  77. \ get( g:, 'ycm_server_keep_logfiles', 0 ) )
  78. let g:ycm_extra_conf_vim_data =
  79. \ get( g:, 'ycm_extra_conf_vim_data', [] )
  80. let g:ycm_server_python_interpreter =
  81. \ get( g:, 'ycm_server_python_interpreter',
  82. \ get( g:, 'ycm_path_to_python_interpreter', '' ) )
  83. let g:ycm_show_diagnostics_ui =
  84. \ get( g:, 'ycm_show_diagnostics_ui', 1 )
  85. let g:ycm_enable_diagnostic_signs =
  86. \ get( g:, 'ycm_enable_diagnostic_signs',
  87. \ get( g:, 'syntastic_enable_signs', 1 ) )
  88. let g:ycm_enable_diagnostic_highlighting =
  89. \ get( g:, 'ycm_enable_diagnostic_highlighting',
  90. \ get( g:, 'syntastic_enable_highlighting', 1 ) )
  91. let g:ycm_echo_current_diagnostic =
  92. \ get( g:, 'ycm_echo_current_diagnostic',
  93. \ get( g:, 'syntastic_echo_current_error', 1 ) )
  94. let g:ycm_always_populate_location_list =
  95. \ get( g:, 'ycm_always_populate_location_list',
  96. \ get( g:, 'syntastic_always_populate_loc_list', 0 ) )
  97. let g:ycm_error_symbol =
  98. \ get( g:, 'ycm_error_symbol',
  99. \ get( g:, 'syntastic_error_symbol', '>>' ) )
  100. let g:ycm_warning_symbol =
  101. \ get( g:, 'ycm_warning_symbol',
  102. \ get( g:, 'syntastic_warning_symbol', '>>' ) )
  103. let g:ycm_goto_buffer_command =
  104. \ get( g:, 'ycm_goto_buffer_command', 'same-buffer' )
  105. let g:ycm_disable_for_files_larger_than_kb =
  106. \ get( g:, 'ycm_disable_for_files_larger_than_kb', 1000 )
  107. if has( 'vim_starting' ) " Loading at startup.
  108. " We defer loading until after VimEnter to allow the gui to fork (see
  109. " `:h gui-fork`) and avoid a deadlock situation, as explained here:
  110. " https://github.com/Valloric/YouCompleteMe/pull/2473#issuecomment-267716136
  111. augroup youcompletemeStart
  112. autocmd!
  113. autocmd VimEnter * call youcompleteme#Enable()
  114. augroup END
  115. else " Manual loading with :packadd.
  116. call youcompleteme#Enable()
  117. endif
  118. " This is basic vim plugin boilerplate
  119. call s:restore_cpo()