Skip to content

Commit

Permalink
Add diag kind to /detailed_diagnostic response
Browse files Browse the repository at this point in the history
  • Loading branch information
bstaletic committed Nov 5, 2023
1 parent 62cfc45 commit 63a9aaa
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ycmd/completers/language_server/language_server_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,12 @@ def GetDetailedDiagnostic( self, request_data ):
distance = _DistanceOfPointToRange( point, diagnostic[ 'range' ] )
if minimum_distance is None or distance < minimum_distance:
message = diagnostic[ 'message' ]
try:
code = diagnostic[ 'code' ]
message += f' [{ code }]'
except KeyError:
pass

if distance == 0:
break
minimum_distance = distance
Expand Down
47 changes: 46 additions & 1 deletion ycmd/tests/clangd/diagnostics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
contains_exactly,
contains_string,
empty,
ends_with,
equal_to,
has_entries,
has_entry,
has_items )
has_items,
is_not )
from unittest.mock import patch
from unittest import TestCase
from pprint import pprint
Expand Down Expand Up @@ -398,6 +400,49 @@ def test_Diagnostics_MaximumDiagnosticsNumberExceeded( self, app ):
) )


@IsolatedYcmd( { 'max_diagnostics_to_display': 0 } )
def test_Diagnostics_MultilineNoKind( self, app ):
filepath = PathToTestFile( 'foo.cc' )
contents = """int main () {
const int &&
/* */
rd = 1;
rd = 4;
}
"""
request = { 'contents': contents,
'filepath': filepath,
'filetype': 'cpp' }

test = { 'request': request, 'route': '/receive_messages' }
response = RunAfterInitialized( app, test )

pprint( response )

assert_that( response, contains_exactly(
has_entries( { 'diagnostics': has_items(
has_entries( {
'kind': equal_to( 'INFORMATION' ),
'location': LocationMatcher( filepath, 2, 1 ),
'location_extent': RangeMatcher( filepath, ( 2, 1 ), ( 4, 11 ) ),
'ranges': contains_exactly(
RangeMatcher( filepath, ( 2, 1 ), ( 4, 11 ) ) ),
'text': is_not( ends_with( ']' ) ), # No diagnostic kind for INFO.
'fixit_available': False
} ),
has_entries( {
'kind': equal_to( 'ERROR' ),
'location': LocationMatcher( filepath, 5, 4 ),
'location_extent': RangeMatcher( filepath, ( 5, 4 ), ( 5, 5 ) ),
'ranges': contains_exactly(
RangeMatcher( filepath, ( 5, 4 ), ( 5, 5 ) ) ),
'text': contains_string( "typecheck_assign_const" ),
'fixit_available': False
} )
) } )
) )


@IsolatedYcmd( { 'max_diagnostics_to_display': 0 } )
def test_Diagnostics_NoLimitToNumberOfDiagnostics( self, app ):
filepath = PathToTestFile( 'max_diagnostics.cc' )
Expand Down
3 changes: 2 additions & 1 deletion ycmd/tests/go/diagnostics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_Diagnostics_DetailedDiags( self, app ):
any_of( has_entry( 'message',
'undeclared name: diagnostics_test' ),
has_entry( 'message',
'undefined: diagnostics_test' ) ) )
'undefined: diagnostics_test'
' [UndeclaredName]' ) ) )


@WithRetry()
Expand Down
3 changes: 2 additions & 1 deletion ycmd/tests/java/diagnostics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def test_Diagnostics_DetailedDiags( self, app ):
results = app.post_json( '/detailed_diagnostic', request_data ).json
assert_that( results, has_entry(
'message',
'The value of the field TestFactory.Bar.testString is not used' ) )
'The value of the field TestFactory.Bar.testString '
'is not used [570425421]' ) )


@WithRetry()
Expand Down
2 changes: 1 addition & 1 deletion ycmd/tests/rust/diagnostics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_Diagnostics_DetailedDiags( self, app ):
results = app.post_json( '/detailed_diagnostic', request_data ).json
assert_that( results, has_entry(
'message',
'no field `build_` on type `test::Builder`\nunknown field' ) )
'no field `build_` on type `test::Builder`\nunknown field [E0609]' ) )


@WithRetry()
Expand Down

0 comments on commit 63a9aaa

Please sign in to comment.