From c953a8fad1b28e2e100434595b03ce378da8d838 Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Sun, 5 Nov 2023 18:29:36 +0100 Subject: [PATCH] Add diag kind to /detailed_diagnostic response --- .../language_server_completer.py | 6 ++++ ycmd/tests/clangd/diagnostics_test.py | 31 ++++++++++++++++++- ycmd/tests/go/diagnostics_test.py | 3 +- ycmd/tests/java/diagnostics_test.py | 3 +- ycmd/tests/rust/diagnostics_test.py | 2 +- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/ycmd/completers/language_server/language_server_completer.py b/ycmd/completers/language_server/language_server_completer.py index 2a088db933..a2796e81ce 100644 --- a/ycmd/completers/language_server/language_server_completer.py +++ b/ycmd/completers/language_server/language_server_completer.py @@ -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 diff --git a/ycmd/tests/clangd/diagnostics_test.py b/ycmd/tests/clangd/diagnostics_test.py index 452e69062a..290170ff5e 100644 --- a/ycmd/tests/clangd/diagnostics_test.py +++ b/ycmd/tests/clangd/diagnostics_test.py @@ -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 @@ -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' ) diff --git a/ycmd/tests/go/diagnostics_test.py b/ycmd/tests/go/diagnostics_test.py index 011eb67dd2..d50d0078df 100644 --- a/ycmd/tests/go/diagnostics_test.py +++ b/ycmd/tests/go/diagnostics_test.py @@ -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() diff --git a/ycmd/tests/java/diagnostics_test.py b/ycmd/tests/java/diagnostics_test.py index 642290cdee..b3edc50d63 100644 --- a/ycmd/tests/java/diagnostics_test.py +++ b/ycmd/tests/java/diagnostics_test.py @@ -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() diff --git a/ycmd/tests/rust/diagnostics_test.py b/ycmd/tests/rust/diagnostics_test.py index 5daafb8e4e..9fe9d1a5a5 100644 --- a/ycmd/tests/rust/diagnostics_test.py +++ b/ycmd/tests/rust/diagnostics_test.py @@ -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()