Skip to content

Commit

Permalink
Auto merge of #883 - micbou:cs-completer-zero-column-diagnostic, r=pu…
Browse files Browse the repository at this point in the history
…remourning

[READY] Handle zero column diagnostic from OmniSharp

The OmniSharp server sometimes incorrectly returns diagnostics with a column number of 0 while lines and columns are supposed to be 1-indexed. This causes the following error:
```
Traceback (most recent call last):
  File "C:\Users\micbou\projects\YouCompleteMe\third_party\ycmd\third_party\bottle\bottle.py", line 862, in _handle
    return route.call(**args)
  File "C:\Users\micbou\projects\YouCompleteMe\third_party\ycmd\third_party\bottle\bottle.py", line 1740, in wrapper
    rv = callback(*a, **ka)
  File "C:\Users\micbou\projects\YouCompleteMe\third_party\ycmd\ycmd\..\ycmd\watchdog_plugin.py", line 108, in wrapper
    return callback( *args, **kwargs )
  File "C:\Users\micbou\projects\YouCompleteMe\third_party\ycmd\ycmd\..\ycmd\hmac_plugin.py", line 70, in wrapper
    body = callback( *args, **kwargs )
  File "C:\Users\micbou\projects\YouCompleteMe\third_party\ycmd\ycmd\..\ycmd\handlers.py", line 70, in EventNotification
    event_handler )( request_data )
  File "C:\Users\micbou\projects\YouCompleteMe\third_party\ycmd\ycmd\..\ycmd\completers\cs\cs_completer.py", line 214, in OnFileReadyToParse
    self._diagnostic_store = DiagnosticsToDiagStructure( diagnostics )
  File "C:\Users\micbou\projects\YouCompleteMe\third_party\ycmd\ycmd\..\ycmd\completers\cs\cs_completer.py", line 611, in DiagnosticsToDiagStructure
    structure[ diagnostic.location_.filename_ ][
AttributeError: 'NoneType' object has no attribute 'filename_'
```
See ycm-core/YouCompleteMe#2846 (comment). We assume the column number is 1 in that case.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/883)
<!-- Reviewable:end -->
  • Loading branch information
zzbot authored Dec 22, 2017
2 parents e07d436 + 5c8ff8f commit 70ada92
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
6 changes: 5 additions & 1 deletion ycmd/completers/cs/cs_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,12 @@ def _IndexToLineColumn( text, index ):


def _BuildLocation( request_data, filename, line_num, column_num ):
if line_num <= 0 or column_num <= 0:
if line_num <= 0:
return None
# OmniSharp sometimes incorrectly returns 0 for the column number. Assume the
# column is 1 in that case.
if column_num <= 0:
column_num = 1
contents = utils.SplitLines( GetFileContents( request_data, filename ) )
line_value = contents[ line_num - 1 ]
return responses.Location(
Expand Down
41 changes: 38 additions & 3 deletions ycmd/tests/cs/diagnostics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def Diagnostics_ZeroBasedLineAndColumn_test( app ):
with WrapOmniSharpServer( app, filepath ):
contents = ReadFile( filepath )

results = {}
for _ in ( 0, 1 ): # First call always returns blank for some reason
event_data = BuildRequest( filepath = filepath,
event_name = 'FileReadyToParse',
Expand Down Expand Up @@ -100,7 +99,6 @@ def Diagnostics_WithRange_test( app ):
with WrapOmniSharpServer( app, filepath ):
contents = ReadFile( filepath )

results = {}
for _ in ( 0, 1 ): # First call always returns blank for some reason
event_data = BuildRequest( filepath = filepath,
event_name = 'FileReadyToParse',
Expand Down Expand Up @@ -143,7 +141,6 @@ def Diagnostics_MultipleSolution_test( app ):
with WrapOmniSharpServer( app, filepath ):
contents = ReadFile( filepath )

results = {}
for _ in ( 0, 1 ): # First call always returns blank for some reason
event_data = BuildRequest( filepath = filepath,
event_name = 'FileReadyToParse',
Expand Down Expand Up @@ -173,3 +170,41 @@ def Diagnostics_MultipleSolution_test( app ):
} ),
} )
} ) ) )


@SharedYcmd
def Diagnostics_HandleZeroColumnDiagnostic_test( app ):
filepath = PathToTestFile( 'testy', 'ZeroColumnDiagnostic.cs' )
with WrapOmniSharpServer( app, filepath ):
contents = ReadFile( filepath )

for _ in ( 0, 1 ): # First call always returns blank for some reason
event_data = BuildRequest( filepath = filepath,
event_name = 'FileReadyToParse',
filetype = 'cs',
contents = contents )

results = app.post_json( '/event_notification', event_data ).json

assert_that( results,
contains(
has_entries( {
'kind': equal_to( 'ERROR' ),
'text': contains_string(
"Unexpected symbol `}'', "
"expecting `;'', `{'', or `where''" ),
'location': has_entries( {
'line_num': 3,
'column_num': 1
} ),
'location_extent': has_entries( {
'start': has_entries( {
'line_num': 3,
'column_num': 1,
} ),
'end': has_entries( {
'line_num': 3,
'column_num': 1,
} ),
} )
} ) ) )
3 changes: 3 additions & 0 deletions ycmd/tests/cs/testdata/testy/ZeroColumnDiagnostic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Class{
int Method()
}

0 comments on commit 70ada92

Please sign in to comment.