From 209d22cfdb9da133ffc48419c42cb027f000055c Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sun, 5 Jan 2014 12:58:13 -0800 Subject: [PATCH] DiagnosticInterface now uses server diag objects --- autoload/youcompleteme.vim | 3 ++- python/ycm/client/event_notification.py | 23 +---------------------- python/ycm/diagnostic_interface.py | 18 ++++++++++++------ python/ycm/youcompleteme.py | 25 ++++++++++++++++++++++--- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index dc4d5460..7480dda9 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -771,7 +771,8 @@ function! s:ShowDiagnostics() return endif - let diags = pyeval( 'ycm_state.GetDiagnosticsFromStoredRequest()' ) + let diags = pyeval( + \ 'ycm_state.GetDiagnosticsFromStoredRequest( qflist_format = True )' ) if !empty( diags ) call setloclist( 0, diags ) lopen diff --git a/python/ycm/client/event_notification.py b/python/ycm/client/event_notification.py index 1c13226e..59444015 100644 --- a/python/ycm/client/event_notification.py +++ b/python/ycm/client/event_notification.py @@ -63,28 +63,7 @@ class EventNotification( BaseRequest ): except Exception as e: vimsupport.PostVimMessage( str( e ) ) - if not self._cached_response: - return [] - - self._cached_response = [ _ConvertDiagnosticDataToVimData( x ) - for x in self._cached_response ] - return self._cached_response - - -def _ConvertDiagnosticDataToVimData( diagnostic ): - # see :h getqflist for a description of the dictionary fields - # Note that, as usual, Vim is completely inconsistent about whether - # line/column numbers are 1 or 0 based in its various APIs. Here, it wants - # them to be 1-based. - location = diagnostic[ 'location' ] - return { - 'bufnr' : vimsupport.GetBufferNumberForFilename( location[ 'filepath' ] ), - 'lnum' : location[ 'line_num' ] + 1, - 'col' : location[ 'column_num' ] + 1, - 'text' : diagnostic[ 'text' ], - 'type' : diagnostic[ 'kind' ], - 'valid' : 1 - } + return self._cached_response if self._cached_response else [] def SendEventNotificationAsync( event_name, extra_data = None ): diff --git a/python/ycm/diagnostic_interface.py b/python/ycm/diagnostic_interface.py index 2084c76e..a7d765fd 100644 --- a/python/ycm/diagnostic_interface.py +++ b/python/ycm/diagnostic_interface.py @@ -18,7 +18,6 @@ # along with YouCompleteMe. If not, see . from collections import defaultdict -from operator import itemgetter from ycm import vimsupport import vim @@ -63,8 +62,9 @@ def _UpdateSquiggles( buffer_number_to_line_to_diags ): for diags in line_to_diags.itervalues(): for diag in diags: - vimsupport.AddDiagnosticSyntaxMatch( diag[ 'lnum' ], - diag[ 'col' ], + location = diag[ 'location' ] + vimsupport.AddDiagnosticSyntaxMatch( location[ 'line_num' ] + 1, + location[ 'column_num' ] + 1, _DiagnosticIsError( diag ) ) @@ -88,15 +88,21 @@ def _UpdateSigns( buffer_number_to_line_to_diags, next_sign_id ): def _ConvertDiagListToDict( diag_list ): buffer_to_line_to_diags = defaultdict( lambda: defaultdict( list ) ) for diag in diag_list: - buffer_to_line_to_diags[ diag[ 'bufnr' ] ][ diag[ 'lnum' ] ].append( diag ) + location = diag[ 'location' ] + buffer_number = vimsupport.GetBufferNumberForFilename( + location[ 'filepath' ] ) + line_number = location[ 'line_num' ] + 1 + buffer_to_line_to_diags[ buffer_number ][ line_number ].append( diag ) + for line_to_diags in buffer_to_line_to_diags.itervalues(): for diags in line_to_diags.itervalues(): # We also want errors to be listed before warnings so that errors aren't # hidden by the warnings; Vim won't place a sign oven an existing one. - diags.sort( key = lambda diag: itemgetter( 'col', 'type' ) ) + diags.sort( key = lambda diag: ( diag[ 'location' ][ 'column_num' ], + diag[ 'kind' ] ) ) return buffer_to_line_to_diags def _DiagnosticIsError( diag ): - return diag[ 'type' ] == 'E' + return diag[ 'kind' ] == 'E' diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 78b4a973..8d8a8cbe 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -265,15 +265,18 @@ class YouCompleteMe( object ): self._latest_file_parse_request.Done() ) - def GetDiagnosticsFromStoredRequest( self ): + def GetDiagnosticsFromStoredRequest( self, qflist_format = False ): if self.DiagnosticsForCurrentFileReady(): - to_return = self._latest_file_parse_request.Response() + diagnostics = self._latest_file_parse_request.Response() # We set the diagnostics request to None because we want to prevent # Syntastic from repeatedly refreshing the buffer with the same diags. # Setting this to None makes DiagnosticsForCurrentFileReady return False # until the next request is created. self._latest_file_parse_request = None - return to_return + if qflist_format: + return [ _ConvertDiagnosticDataToVimData( x ) for x in diagnostics ] + else: + return diagnostics return [] @@ -374,3 +377,19 @@ def _AddUltiSnipsDataIfNeeded( extra_data ): extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger, 'description': x.description } for x in rawsnips ] + + +def _ConvertDiagnosticDataToVimData( diagnostic ): + # see :h getqflist for a description of the dictionary fields + # Note that, as usual, Vim is completely inconsistent about whether + # line/column numbers are 1 or 0 based in its various APIs. Here, it wants + # them to be 1-based. + location = diagnostic[ 'location' ] + return { + 'bufnr' : vimsupport.GetBufferNumberForFilename( location[ 'filepath' ] ), + 'lnum' : location[ 'line_num' ] + 1, + 'col' : location[ 'column_num' ] + 1, + 'text' : diagnostic[ 'text' ], + 'type' : diagnostic[ 'kind' ], + 'valid' : 1 + }