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
18" This is basic vim plugin boilerplate
19let s:save_cpo = &cpo
20set cpo&vim
21
22function! s:restore_cpo()
23  let &cpo = s:save_cpo
24  unlet s:save_cpo
25endfunction
26
27" NOTE: The minimum supported version is 8.1.2269, but neovim always reports as
28" v:version 800, but will largely work.
29let s:is_neovim = has( 'nvim' )
30
31if exists( "g:loaded_youcompleteme" )
32  call s:restore_cpo()
33  finish
34elseif ( v:version < 801 || (v:version == 801 && !has( 'patch2269' )) ) &&
35      \ !s:is_neovim
36  echohl WarningMsg |
37        \ echomsg "YouCompleteMe unavailable: requires Vim 8.1.2269+." |
38        \ echohl None
39  call s:restore_cpo()
40  finish
41elseif !has( 'timers' )
42  echohl WarningMsg |
43        \ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
44        \ "the timers feature." |
45        \ echohl None
46  call s:restore_cpo()
47  finish
48elseif !has( 'python3_compiled' )
49  echohl WarningMsg |
50        \ echomsg "YouCompleteMe unavailable: requires Vim compiled with " .
51        \ "Python (3.6.0+) support." |
52        \ echohl None
53  call s:restore_cpo()
54  finish
55" These calls try to load the Python 3 libraries when Vim is
56" compiled dynamically against them. Since only one can be loaded at a time on
57" some platforms, we first check if Python 3 is available.
58elseif !has( 'python3' )
59  echohl WarningMsg |
60        \ echomsg "YouCompleteMe unavailable: unable to load Python." |
61        \ echohl None
62  call s:restore_cpo()
63  finish
64elseif &encoding !~? 'utf-\?8'
65  echohl WarningMsg |
66        \ echomsg "YouCompleteMe unavailable: requires UTF-8 encoding. " .
67        \ "Put the line 'set encoding=utf-8' in your vimrc." |
68        \ echohl None
69  call s:restore_cpo()
70  finish
71endif
72
73let g:loaded_youcompleteme = 1
74
75"
76" List of YCM options.
77"
78let g:ycm_filetype_whitelist =
79      \ get( g:, 'ycm_filetype_whitelist', { "*": 1 } )
80
81let g:ycm_filetype_blacklist =
82      \ get( g:, 'ycm_filetype_blacklist', {
83      \   'tagbar': 1,
84      \   'notes': 1,
85      \   'markdown': 1,
86      \   'netrw': 1,
87      \   'unite': 1,
88      \   'text': 1,
89      \   'vimwiki': 1,
90      \   'pandoc': 1,
91      \   'infolog': 1,
92      \   'leaderf': 1,
93      \   'mail': 1
94      \ } )
95
96" Blacklist empty buffers unless explicity whitelisted; workaround for
97" https://github.com/ycm-core/YouCompleteMe/issues/3781
98if !has_key( g:ycm_filetype_whitelist, 'ycm_nofiletype' )
99  let g:ycm_filetype_blacklist.ycm_nofiletype = 1
100endif
101
102let g:ycm_open_loclist_on_ycm_diags =
103      \ get( g:, 'ycm_open_loclist_on_ycm_diags', 1 )
104
105let g:ycm_add_preview_to_completeopt =
106      \ get( g:, 'ycm_add_preview_to_completeopt', 0 )
107
108let g:ycm_autoclose_preview_window_after_completion =
109      \ get( g:, 'ycm_autoclose_preview_window_after_completion', 0 )
110
111let g:ycm_autoclose_preview_window_after_insertion =
112      \ get( g:, 'ycm_autoclose_preview_window_after_insertion', 0 )
113
114let g:ycm_key_list_select_completion =
115      \ get( g:, 'ycm_key_list_select_completion', ['<TAB>', '<Down>'] )
116
117let g:ycm_key_list_previous_completion =
118      \ get( g:, 'ycm_key_list_previous_completion', ['<S-TAB>', '<Up>'] )
119
120let g:ycm_key_list_stop_completion =
121      \ get( g:, 'ycm_key_list_stop_completion', ['<C-y>'] )
122
123let g:ycm_key_invoke_completion =
124      \ get( g:, 'ycm_key_invoke_completion', '<C-Space>' )
125
126let g:ycm_key_detailed_diagnostics =
127      \ get( g:, 'ycm_key_detailed_diagnostics', '<leader>d' )
128
129let g:ycm_cache_omnifunc =
130      \ get( g:, 'ycm_cache_omnifunc', 1 )
131
132let g:ycm_log_level =
133      \ get( g:, 'ycm_log_level',
134      \ get( g:, 'ycm_server_log_level', 'info' ) )
135
136let g:ycm_keep_logfiles =
137      \ get( g:, 'ycm_keep_logfiles',
138      \ get( g:, 'ycm_server_keep_logfiles', 0 ) )
139
140let g:ycm_extra_conf_vim_data =
141      \ get( g:, 'ycm_extra_conf_vim_data', [] )
142
143let g:ycm_server_python_interpreter =
144      \ get( g:, 'ycm_server_python_interpreter',
145      \ get( g:, 'ycm_path_to_python_interpreter', '' ) )
146
147let g:ycm_show_diagnostics_ui =
148      \ get( g:, 'ycm_show_diagnostics_ui', 1 )
149
150let g:ycm_enable_diagnostic_signs =
151      \ get( g:, 'ycm_enable_diagnostic_signs',
152      \ get( g:, 'syntastic_enable_signs', 1 ) )
153
154let g:ycm_enable_diagnostic_highlighting =
155      \ get( g:, 'ycm_enable_diagnostic_highlighting',
156      \ get( g:, 'syntastic_enable_highlighting', 1 ) )
157
158let g:ycm_echo_current_diagnostic =
159      \ get( g:, 'ycm_echo_current_diagnostic',
160      \ get( g:, 'syntastic_echo_current_error', 1 ) )
161
162let g:ycm_filter_diagnostics =
163      \ get( g:, 'ycm_filter_diagnostics', {} )
164
165let g:ycm_always_populate_location_list =
166      \ get( g:, 'ycm_always_populate_location_list',
167      \ get( g:, 'syntastic_always_populate_loc_list', 0 ) )
168
169let g:ycm_error_symbol =
170      \ get( g:, 'ycm_error_symbol',
171      \ get( g:, 'syntastic_error_symbol', '>>' ) )
172
173let g:ycm_warning_symbol =
174      \ get( g:, 'ycm_warning_symbol',
175      \ get( g:, 'syntastic_warning_symbol', '>>' ) )
176
177let g:ycm_complete_in_comments =
178      \ get( g:, 'ycm_complete_in_comments', 0 )
179
180let g:ycm_complete_in_strings =
181      \ get( g:, 'ycm_complete_in_strings', 1 )
182
183let g:ycm_collect_identifiers_from_tags_files =
184      \ get( g:, 'ycm_collect_identifiers_from_tags_files', 0 )
185
186let g:ycm_seed_identifiers_with_syntax =
187      \ get( g:, 'ycm_seed_identifiers_with_syntax', 0 )
188
189let g:ycm_goto_buffer_command =
190      \ get( g:, 'ycm_goto_buffer_command', 'same-buffer' )
191
192let g:ycm_disable_for_files_larger_than_kb =
193      \ get( g:, 'ycm_disable_for_files_larger_than_kb', 1000 )
194
195let g:ycm_auto_hover =
196      \ get( g:, 'ycm_auto_hover', 'CursorHold' )
197
198"
199" List of ycmd options.
200"
201let g:ycm_filepath_completion_use_working_dir =
202      \ get( g:, 'ycm_filepath_completion_use_working_dir', 0 )
203
204let g:ycm_auto_trigger =
205      \ get( g:, 'ycm_auto_trigger', 1 )
206
207let g:ycm_min_num_of_chars_for_completion =
208      \ get( g:, 'ycm_min_num_of_chars_for_completion', 2 )
209
210let g:ycm_min_identifier_candidate_chars =
211      \ get( g:, 'ycm_min_num_identifier_candidate_chars', 0 )
212
213let g:ycm_semantic_triggers =
214      \ get( g:, 'ycm_semantic_triggers', {} )
215
216let g:ycm_filetype_specific_completion_to_disable =
217      \ get( g:, 'ycm_filetype_specific_completion_to_disable',
218      \      { 'gitcommit': 1 } )
219
220let g:ycm_collect_identifiers_from_comments_and_strings =
221      \ get( g:, 'ycm_collect_identifiers_from_comments_and_strings', 0 )
222
223let g:ycm_max_num_identifier_candidates =
224      \ get( g:, 'ycm_max_num_identifier_candidates', 10 )
225
226let g:ycm_max_num_candidates =
227      \ get( g:, 'ycm_max_num_candidates', 50 )
228
229let g:ycm_extra_conf_globlist =
230      \ get( g:, 'ycm_extra_conf_globlist', [] )
231
232let g:ycm_global_ycm_extra_conf =
233      \ get( g:, 'ycm_global_ycm_extra_conf', '' )
234
235let g:ycm_confirm_extra_conf =
236      \ get( g:, 'ycm_confirm_extra_conf', 1 )
237
238let g:ycm_max_diagnostics_to_display =
239      \ get( g:, 'ycm_max_diagnostics_to_display', 30 )
240
241let g:ycm_filepath_blacklist =
242      \ get( g:, 'ycm_filepath_blacklist', {
243      \   'html': 1,
244      \   'jsx': 1,
245      \   'xml': 1
246      \ } )
247
248let g:ycm_auto_start_csharp_server =
249      \ get( g:, 'ycm_auto_start_csharp_server', 1 )
250
251let g:ycm_auto_stop_csharp_server =
252      \ get( g:, 'ycm_auto_stop_csharp_server', 1 )
253
254let g:ycm_use_ultisnips_completer =
255      \ get( g:, 'ycm_use_ultisnips_completer', 1 )
256
257let g:ycm_csharp_server_port =
258      \ get( g:, 'ycm_csharp_server_port', 0 )
259
260let g:ycm_use_clangd =
261      \ get( g:, 'ycm_use_clangd', 1 )
262
263let g:ycm_clangd_binary_path =
264      \ get( g:, 'ycm_clangd_binary_path', '' )
265
266let g:ycm_clangd_args =
267      \ get( g:, 'ycm_clangd_args', [] )
268
269let g:ycm_clangd_uses_ycmd_caching =
270      \ get( g:, 'ycm_clangd_uses_ycmd_caching', 1 )
271
272" These options are not documented.
273let g:ycm_java_jdtls_extension_path =
274      \ get( g:, 'ycm_java_jdtls_extension_path', [] )
275
276let g:ycm_java_jdtls_use_clean_workspace =
277      \ get( g:, 'ycm_java_jdtls_use_clean_workspace', 1 )
278
279let g:ycm_java_jdtls_workspace_root_path =
280      \ get( g:, 'ycm_java_jdtls_workspace_root_path', '' )
281
282" This option is deprecated.
283let g:ycm_python_binary_path =
284      \ get( g:, 'ycm_python_binary_path', '' )
285
286let g:ycm_refilter_workspace_symbols =
287      \ get( g:, 'ycm_refilter_workspace_symbols', 1 )
288
289if has( 'vim_starting' ) " Loading at startup.
290  " We defer loading until after VimEnter to allow the gui to fork (see
291  " `:h gui-fork`) and avoid a deadlock situation, as explained here:
292  " https://github.com/Valloric/YouCompleteMe/pull/2473#issuecomment-267716136
293  augroup youcompletemeStart
294    autocmd!
295    autocmd VimEnter * call youcompleteme#Enable()
296  augroup END
297else " Manual loading with :packadd.
298  call youcompleteme#Enable()
299endif
300
301" This is basic vim plugin boilerplate
302call s:restore_cpo()
303