Skip to content

Commit

Permalink
Merge pull request #1720 from bstaletic/detailed-diag-with-kindness
Browse files Browse the repository at this point in the history
[READY] Add diag kind to /detailed_diagnostic response
  • Loading branch information
mergify[bot] authored Nov 6, 2023
2 parents 62cfc45 + c953a8f commit 0607eed
Show file tree
Hide file tree
Showing 5 changed files with 41 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
31 changes: 30 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 @@ -178,6 +180,33 @@ def test_Diagnostics_Multiline( self, app ):
has_entry( 'message', contains_string( "\n" ) ) )


@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' }
RunAfterInitialized( app, test )

diag_data = BuildRequest( line_num = 2,
contents = contents,
filepath = filepath,
filetype = 'cpp' )

results = app.post_json( '/detailed_diagnostic', diag_data ).json
assert_that( results,
has_entry( 'message', is_not( ends_with( ']' ) ) ) )


@IsolatedYcmd()
def test_Diagnostics_FixIt_Available( self, app ):
filepath = PathToTestFile( 'FixIt_Clang_cpp11.cpp' )
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 0607eed

Please sign in to comment.