Преглед на файлове

Merge pull request #4091 from Chilledheart/accept_invalid_end_lnum_field

Accept invalid end_lnum field in diagnose parse
mergify[bot] преди 2 години
родител
ревизия
7620d87fe1
променени са 2 файла, в които са добавени 77 реда и са изтрити 1 реда
  1. 3 0
      python/ycm/diagnostic_interface.py
  2. 74 1
      python/ycm/tests/diagnostic_interface_test.py

+ 3 - 0
python/ycm/diagnostic_interface.py

@@ -312,6 +312,9 @@ def _ConvertDiagnosticToTextProperties( bufnr, diagnostic ):
         'end_col': end_column } ) )
 
   for diagnostic_range in diagnostic[ 'ranges' ]:
+    if ( diagnostic_range[ 'start' ][ 'line_num' ] == 0 or
+         diagnostic_range[ 'end' ][ 'line_num' ] == 0 ):
+      continue
     start_line, start_column = vimsupport.LineAndColumnNumbersClamped(
       bufnr,
       diagnostic_range[ 'start' ][ 'line_num' ],

+ 74 - 1
python/ycm/tests/diagnostic_interface_test.py

@@ -54,6 +54,46 @@ def SimpleDiagnosticToJson( start_line, start_col, end_line, end_col ):
   }
 
 
+def SimpleDiagnosticToJsonWithInvalidLineNum( start_line, start_col,
+                                              end_line, end_col ):
+  return {
+    'kind': 'ERROR',
+    'location': { 'line_num': start_line, 'column_num': start_col },
+    'location_extent': {
+      'start': {
+        'line_num': start_line,
+        'column_num': start_col
+      },
+      'end': {
+        'line_num': end_line,
+        'column_num': end_col
+      }
+    },
+    'ranges': [
+      {
+        'start': {
+          'line_num': 0,
+          'column_num': 0
+        },
+        'end': {
+          'line_num': 0,
+          'column_num': 0
+        }
+      },
+      {
+        'start': {
+          'line_num': start_line,
+          'column_num': start_col
+        },
+        'end': {
+          'line_num': end_line,
+          'column_num': end_col
+        }
+      }
+    ]
+  }
+
+
 def YcmTextPropertyTupleMatcher( start_line, start_col, end_line, end_col ):
   return has_item( contains_exactly(
     start_line,
@@ -86,7 +126,7 @@ class DiagnosticInterfaceTest( TestCase ):
       [
         SimpleDiagnosticToJson( 0, 0, 0, 0 ),
         [ 'Some contents' ],
-        YcmTextPropertyTupleMatcher( 1, 1, 1, 1 )
+        {}
       ],
       [
         SimpleDiagnosticToJson( -1, -2, -3, -4 ),
@@ -106,6 +146,39 @@ class DiagnosticInterfaceTest( TestCase ):
           print( actual )
           assert_that( actual, result )
 
+  def test_ConvertDiagnosticWithInvalidLineNum( self ):
+    for diag, contents, result in [
+      # Error in middle of the line
+      [
+        SimpleDiagnosticToJsonWithInvalidLineNum( 1, 16, 1, 23 ),
+        [ 'Highlight this error please' ],
+        YcmTextPropertyTupleMatcher( 1, 16, 1, 23 )
+      ],
+      # Error at the end of the line
+      [
+        SimpleDiagnosticToJsonWithInvalidLineNum( 1, 16, 1, 21 ),
+        [ 'Highlight this warning' ],
+        YcmTextPropertyTupleMatcher( 1, 16, 1, 21 )
+      ],
+      [
+        SimpleDiagnosticToJsonWithInvalidLineNum( 1, 16, 1, 19 ),
+        [ 'Highlight unicøde' ],
+        YcmTextPropertyTupleMatcher( 1, 16, 1, 19 )
+      ],
+    ]:
+      with self.subTest( diag = diag, contents = contents, result = result ):
+        current_buffer = VimBuffer( 'foo', number = 1, contents = [ '' ] )
+        target_buffer = VimBuffer( 'bar', number = 2, contents = contents )
+
+        with MockVimBuffers( [ current_buffer, target_buffer ],
+                             [ current_buffer, target_buffer ] ):
+          actual = diagnostic_interface._ConvertDiagnosticToTextProperties(
+              target_buffer.number,
+              diag )
+          print( actual )
+          assert_that( actual, result )
+
+
   def test_IsValidRange( self ):
     for start_line, start_col, end_line, end_col, expect in (
       ( 1, 1, 1, 1, True ),