Handling diags pointing to content not in file
Also handling no location_extent for diags.
This commit is contained in:
parent
365f67f82c
commit
6e6e6043c3
@ -76,6 +76,12 @@ def _UpdateSquiggles( buffer_number_to_line_to_diags ):
|
|||||||
location_extent = diag[ 'location_extent' ]
|
location_extent = diag[ 'location_extent' ]
|
||||||
is_error = _DiagnosticIsError( diag )
|
is_error = _DiagnosticIsError( diag )
|
||||||
|
|
||||||
|
if location_extent[ 'start' ][ 'line_num' ] < 0:
|
||||||
|
location = diag[ 'location' ]
|
||||||
|
vimsupport.AddDiagnosticSyntaxMatch(
|
||||||
|
location[ 'line_num' ] + 1,
|
||||||
|
location[ 'column_num' ] + 1 )
|
||||||
|
else:
|
||||||
vimsupport.AddDiagnosticSyntaxMatch(
|
vimsupport.AddDiagnosticSyntaxMatch(
|
||||||
location_extent[ 'start' ][ 'line_num' ] + 1,
|
location_extent[ 'start' ][ 'line_num' ] + 1,
|
||||||
location_extent[ 'start' ][ 'column_num' ] + 1,
|
location_extent[ 'start' ][ 'column_num' ] + 1,
|
||||||
|
@ -128,6 +128,7 @@ def ClearYcmSyntaxMatches():
|
|||||||
|
|
||||||
|
|
||||||
# Returns the ID of the newly added match
|
# Returns the ID of the newly added match
|
||||||
|
# Both line and column numbers are 1-based
|
||||||
def AddDiagnosticSyntaxMatch( line_num,
|
def AddDiagnosticSyntaxMatch( line_num,
|
||||||
column_num,
|
column_num,
|
||||||
line_end_num = None,
|
line_end_num = None,
|
||||||
@ -138,6 +139,10 @@ def AddDiagnosticSyntaxMatch( line_num,
|
|||||||
if not line_end_num:
|
if not line_end_num:
|
||||||
line_end_num = line_num
|
line_end_num = line_num
|
||||||
|
|
||||||
|
line_num, column_num = LineAndColumnNumbersClamped( line_num, column_num )
|
||||||
|
line_end_num, column_end_num = LineAndColumnNumbersClamped( line_end_num,
|
||||||
|
column_end_num )
|
||||||
|
|
||||||
if not column_end_num:
|
if not column_end_num:
|
||||||
return GetIntValue(
|
return GetIntValue(
|
||||||
"matchadd('{0}', '\%{1}l\%{2}c')".format( group, line_num, column_num ) )
|
"matchadd('{0}', '\%{1}l\%{2}c')".format( group, line_num, column_num ) )
|
||||||
@ -147,6 +152,23 @@ 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 ) )
|
||||||
|
|
||||||
|
|
||||||
|
# Clamps the line and column numbers so that they are not past the contents of
|
||||||
|
# the buffer. Numbers are 1-based.
|
||||||
|
def LineAndColumnNumbersClamped( line_num, column_num ):
|
||||||
|
new_line_num = line_num
|
||||||
|
new_column_num = column_num
|
||||||
|
|
||||||
|
max_line = len( vim.current.buffer )
|
||||||
|
if line_num and line_num > max_line:
|
||||||
|
new_line_num = max_line
|
||||||
|
|
||||||
|
max_column = len( vim.current.buffer[ new_line_num - 1 ] )
|
||||||
|
if column_num and column_num > max_column:
|
||||||
|
new_column_num = max_column
|
||||||
|
|
||||||
|
return new_line_num, new_column_num
|
||||||
|
|
||||||
|
|
||||||
def SetLocationList( diagnostics ):
|
def SetLocationList( diagnostics ):
|
||||||
"""Diagnostics should be in qflist format; see ":h setqflist" for details."""
|
"""Diagnostics should be in qflist format; see ":h setqflist" for details."""
|
||||||
vim.eval( 'setloclist( 0, {0} )'.format( json.dumps( diagnostics ) ) )
|
vim.eval( 'setloclist( 0, {0} )'.format( json.dumps( diagnostics ) ) )
|
||||||
|
Loading…
Reference in New Issue
Block a user