Skip to content

Commit

Permalink
Auto merge of ycm-core#1905 - davits:easy_handler, r=Valloric
Browse files Browse the repository at this point in the history
[READY] Simplify parse request handling

Moved file parse request handling into python, trying to simplify the overall flow, and allow easier additions of additional post handlers such as semantic token extraction.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/1905)
<!-- Reviewable:end -->
  • Loading branch information
homu committed Feb 21, 2016
2 parents 8ad4044 + 4d97437 commit 7b8b1ac
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 239 deletions.
49 changes: 5 additions & 44 deletions autoload/youcompleteme.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ let s:cursor_moved = 0
let s:moved_vertically_in_insert_mode = 0
let s:previous_num_chars_on_current_line = strlen( getline('.') )

let s:diagnostic_ui_filetypes = {
\ 'cpp': 1,
\ 'cs': 1,
\ 'c': 1,
\ 'objc': 1,
\ 'objcpp': 1,
\ }


function! youcompleteme#Enable()
" When vim is in diff mode, don't run
Expand Down Expand Up @@ -308,11 +300,6 @@ function! s:TurnOffSyntasticForCFamily()
endfunction


function! s:DiagnosticUiSupportedForCurrentFiletype()
return get( s:diagnostic_ui_filetypes, &filetype, 0 )
endfunction


function! s:AllowedToCompleteInCurrentFile()
if empty( &filetype ) ||
\ getbufvar( winbufnr( winnr() ), "&buftype" ) ==# 'nofile' ||
Expand Down Expand Up @@ -462,11 +449,11 @@ function! s:OnFileReadyToParse()
" happen for special buffers.
call s:SetUpYcmChangedTick()

" Order is important here; we need to extract any done diagnostics before
" Order is important here; we need to extract any information before
" reparsing the file again. If we sent the new parse request first, then
" the response would always be pending when we called
" UpdateDiagnosticNotifications.
call s:UpdateDiagnosticNotifications()
" HandleFileParseRequest.
py ycm_state.HandleFileParseRequest()

let buffer_changed = b:changedtick != b:ycm_changedtick.file_ready_to_parse
if buffer_changed
Expand Down Expand Up @@ -612,19 +599,6 @@ function! s:ClosePreviewWindowIfNeeded()
endfunction


function! s:UpdateDiagnosticNotifications()
let should_display_diagnostics = g:ycm_show_diagnostics_ui &&
\ s:DiagnosticUiSupportedForCurrentFiletype()

if !should_display_diagnostics
py ycm_state.ValidateParseRequest()
return
endif

py ycm_state.UpdateDiagnosticInterface()
endfunction


function! s:IdentifierFinishedOperations()
if !pyeval( 'base.CurrentIdentifierFinished()' )
return
Expand Down Expand Up @@ -853,15 +827,8 @@ function! s:ForceCompile()

echom "Forcing compilation, this will block Vim until done."
py ycm_state.OnFileReadyToParse()
while 1
let diagnostics_ready = pyeval(
\ 'ycm_state.DiagnosticsForCurrentFileReady()' )
if diagnostics_ready
break
endif
py ycm_state.HandleFileParseRequest( True )

sleep 100m
endwhile
return 1
endfunction

Expand All @@ -871,8 +838,6 @@ function! s:ForceCompileAndDiagnostics()
if !compilation_succeeded
return
endif

call s:UpdateDiagnosticNotifications()
echom "Diagnostics refreshed."
endfunction

Expand All @@ -883,11 +848,7 @@ function! s:ShowDiagnostics()
return
endif

let diags = pyeval(
\ 'ycm_state.GetDiagnosticsFromStoredRequest( qflist_format = True )' )
if !empty( diags )
call setloclist( 0, diags )

if pyeval( 'ycm_state.PopulateLocationListWithLatestDiagnostics()' )
if g:ycm_open_loclist_on_ycm_diags
lopen
endif
Expand Down
8 changes: 6 additions & 2 deletions python/ycm/diagnostic_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def GetWarningCount( self ):
return len( self._FilterDiagnostics( _DiagnosticIsWarning ) )


def PopulateLocationList( self, diags ):
vimsupport.SetLocationList(
vimsupport.ConvertDiagnosticsToQfList( diags ) )


def UpdateWithNewDiagnostics( self, diags ):
normalized_diags = [ _NormalizeDiagnostic( x ) for x in diags ]
self._buffer_number_to_line_to_diags = _ConvertDiagListToDict(
Expand All @@ -65,8 +70,7 @@ def UpdateWithNewDiagnostics( self, diags ):
_UpdateSquiggles( self._buffer_number_to_line_to_diags )

if self._user_options[ 'always_populate_location_list' ]:
vimsupport.SetLocationList(
vimsupport.ConvertDiagnosticsToQfList( normalized_diags ) )
self.PopulateLocationList( normalized_diags )

def _EchoDiagnosticForLine( self, line_num ):
buffer_num = vim.current.buffer.number
Expand Down
Loading

0 comments on commit 7b8b1ac

Please sign in to comment.