DiagnosticInterface now uses server diag objects
This commit is contained in:
parent
a9ea9d648d
commit
209d22cfdb
@ -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
|
||||
|
@ -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 ):
|
||||
|
@ -18,7 +18,6 @@
|
||||
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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'
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user