Now can populate the loclist like Syntastic

This commit is contained in:
Strahinja Val Markovic 2014-01-08 19:09:40 -08:00
parent cb359c0b6a
commit 8090373afd
4 changed files with 34 additions and 16 deletions

View File

@ -129,6 +129,10 @@ let g:ycm_echo_current_diagnostic =
\ get( g:, 'ycm_echo_current_diagnostic', \ get( g:, 'ycm_echo_current_diagnostic',
\ get( g:, 'syntastic_echo_current_error', 1 ) ) \ get( g:, 'syntastic_echo_current_error', 1 ) )
let g:ycm_always_populate_loc_list =
\ get( g:, 'ycm_always_populate_loc_list',
\ get( g:, 'syntastic_always_populate_loc_list', 0 ) )
let g:ycm_error_symbol = let g:ycm_error_symbol =
\ get( g:, 'ycm_error_symbol', \ get( g:, 'ycm_error_symbol',
\ get( g:, 'syntastic_error_symbol', '>>' ) ) \ get( g:, 'syntastic_error_symbol', '>>' ) )

View File

@ -52,6 +52,10 @@ class DiagnosticInterface( object ):
if self._user_options[ 'enable_highlighting' ]: if self._user_options[ 'enable_highlighting' ]:
_UpdateSquiggles( self._buffer_number_to_line_to_diags ) _UpdateSquiggles( self._buffer_number_to_line_to_diags )
if self._user_options[ 'always_populate_loc_list' ]:
vimsupport.SetLocationList(
vimsupport.ConvertDiagnosticsToQfList( diags ) )
def _EchoDiagnosticForLine( self, line_num ): def _EchoDiagnosticForLine( self, line_num ):
buffer_num = vim.current.buffer.number buffer_num = vim.current.buffer.number

View File

@ -147,6 +147,30 @@ def AddDiagnosticSyntaxMatch( line_num,
group, line_num, column_num, line_end_num, column_end_num ) ) group, line_num, column_num, line_end_num, column_end_num ) )
def SetLocationList( diagnostics ):
"""Diagnostics should be in qflist format; see ":h setqflist" for details."""
vim.eval( 'setloclist( 0, {0} )'.format( json.dumps( diagnostics ) ) )
def ConvertDiagnosticsToQfList( diagnostics ):
def ConvertDiagnosticToQfFormat( 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' : GetBufferNumberForFilename( location[ 'filepath' ] ),
'lnum' : location[ 'line_num' ] + 1,
'col' : location[ 'column_num' ] + 1,
'text' : diagnostic[ 'text' ],
'type' : diagnostic[ 'kind' ],
'valid' : 1
}
return [ ConvertDiagnosticToQfFormat( x ) for x in diagnostics ]
# Given a dict like {'a': 1}, loads it into Vim as if you ran 'let g:a = 1' # Given a dict like {'a': 1}, loads it into Vim as if you ran 'let g:a = 1'
# When |overwrite| is True, overwrites the existing value in Vim. # When |overwrite| is True, overwrites the existing value in Vim.
def LoadDictIntoVimGlobals( new_globals, overwrite = True ): def LoadDictIntoVimGlobals( new_globals, overwrite = True ):

View File

@ -274,7 +274,7 @@ class YouCompleteMe( object ):
# until the next request is created. # until the next request is created.
self._latest_file_parse_request = None self._latest_file_parse_request = None
if qflist_format: if qflist_format:
return [ _ConvertDiagnosticDataToVimData( x ) for x in diagnostics ] return vimsupport.ConvertDiagnosticsToQfList( diagnostics )
else: else:
return diagnostics return diagnostics
return [] return []
@ -379,17 +379,3 @@ def _AddUltiSnipsDataIfNeeded( extra_data ):
} 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
}