DiagnosticInterface now uses server diag objects

This commit is contained in:
Strahinja Val Markovic 2014-01-05 12:58:13 -08:00
parent a9ea9d648d
commit 209d22cfdb
4 changed files with 37 additions and 32 deletions

View File

@ -771,7 +771,8 @@ function! s:ShowDiagnostics()
return return
endif endif
let diags = pyeval( 'ycm_state.GetDiagnosticsFromStoredRequest()' ) let diags = pyeval(
\ 'ycm_state.GetDiagnosticsFromStoredRequest( qflist_format = True )' )
if !empty( diags ) if !empty( diags )
call setloclist( 0, diags ) call setloclist( 0, diags )
lopen lopen

View File

@ -63,28 +63,7 @@ class EventNotification( BaseRequest ):
except Exception as e: except Exception as e:
vimsupport.PostVimMessage( str( e ) ) vimsupport.PostVimMessage( str( e ) )
if not self._cached_response: return self._cached_response if self._cached_response else []
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
}
def SendEventNotificationAsync( event_name, extra_data = None ): def SendEventNotificationAsync( event_name, extra_data = None ):

View File

@ -18,7 +18,6 @@
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from collections import defaultdict from collections import defaultdict
from operator import itemgetter
from ycm import vimsupport from ycm import vimsupport
import vim import vim
@ -63,8 +62,9 @@ def _UpdateSquiggles( buffer_number_to_line_to_diags ):
for diags in line_to_diags.itervalues(): for diags in line_to_diags.itervalues():
for diag in diags: for diag in diags:
vimsupport.AddDiagnosticSyntaxMatch( diag[ 'lnum' ], location = diag[ 'location' ]
diag[ 'col' ], vimsupport.AddDiagnosticSyntaxMatch( location[ 'line_num' ] + 1,
location[ 'column_num' ] + 1,
_DiagnosticIsError( diag ) ) _DiagnosticIsError( diag ) )
@ -88,15 +88,21 @@ def _UpdateSigns( buffer_number_to_line_to_diags, next_sign_id ):
def _ConvertDiagListToDict( diag_list ): def _ConvertDiagListToDict( diag_list ):
buffer_to_line_to_diags = defaultdict( lambda: defaultdict( list ) ) buffer_to_line_to_diags = defaultdict( lambda: defaultdict( list ) )
for diag in diag_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 line_to_diags in buffer_to_line_to_diags.itervalues():
for diags in 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 # 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. # 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 return buffer_to_line_to_diags
def _DiagnosticIsError( diag ): def _DiagnosticIsError( diag ):
return diag[ 'type' ] == 'E' return diag[ 'kind' ] == 'E'

View File

@ -265,15 +265,18 @@ class YouCompleteMe( object ):
self._latest_file_parse_request.Done() ) self._latest_file_parse_request.Done() )
def GetDiagnosticsFromStoredRequest( self ): def GetDiagnosticsFromStoredRequest( self, qflist_format = False ):
if self.DiagnosticsForCurrentFileReady(): 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 # We set the diagnostics request to None because we want to prevent
# Syntastic from repeatedly refreshing the buffer with the same diags. # Syntastic from repeatedly refreshing the buffer with the same diags.
# Setting this to None makes DiagnosticsForCurrentFileReady return False # Setting this to None makes DiagnosticsForCurrentFileReady return False
# until the next request is created. # until the next request is created.
self._latest_file_parse_request = None self._latest_file_parse_request = None
return to_return if qflist_format:
return [ _ConvertDiagnosticDataToVimData( x ) for x in diagnostics ]
else:
return diagnostics
return [] return []
@ -374,3 +377,19 @@ def _AddUltiSnipsDataIfNeeded( extra_data ):
extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger, extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger,
'description': x.description 'description': x.description
} for x in rawsnips ] } 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
}