From b4beed49399808930aa94ac761bb712eeddc7e82 Mon Sep 17 00:00:00 2001 From: Andrea Cedraro Date: Fri, 13 Nov 2015 14:26:04 +0100 Subject: [PATCH 1/2] Defer setting the omnifunc only the first time Fix #1769 --- autoload/youcompleteme.vim | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 8836b275..7e4c8488 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -22,6 +22,7 @@ set cpo&vim " This needs to be called outside of a function let s:script_folder_path = escape( expand( ':p:h' ), '\' ) let s:omnifunc_mode = 0 +let s:defer_omnifunc = 1 let s:old_cursor_position = [] let s:cursor_moved = 0 @@ -88,6 +89,15 @@ function! youcompleteme#Enable() autocmd CompleteDone * call s:OnCompleteDone() augroup END + 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 + " 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! @@ -412,6 +422,11 @@ function! s:OnBufferVisit() call s:SetUpCompleteopt() call s:SetCompleteFunc() + + if !s:defer_omnifunc + call s:SetOmnicompleteFunc() + endif + py ycm_state.OnBufferVisit() call s:OnFileReadyToParse() endfunction @@ -544,11 +559,6 @@ function! s:OnInsertEnter() return endif - if !get( b:, 'ycm_omnicomplete', 0 ) - let b:ycm_omnicomplete = 1 - call s:SetOmnicompleteFunc() - endif - let s:old_cursor_position = [] endfunction From ad4091635ea22b1a08aa8281a1e6c5a6538482b2 Mon Sep 17 00:00:00 2001 From: Andrea Cedraro Date: Thu, 31 Dec 2015 00:12:38 +0100 Subject: [PATCH 2/2] Add comment expaning why we defer setting the omnifunc --- autoload/youcompleteme.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 7e4c8488..20902939 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -89,6 +89,12 @@ function! youcompleteme#Enable() autocmd CompleteDone * call s:OnCompleteDone() augroup END + " 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. if s:defer_omnifunc augroup ycm_defer_omnifunc autocmd!