From a7ec7a6cd94e98d918f7fff4643e6d6aa5db0dc3 Mon Sep 17 00:00:00 2001 From: micbou Date: Thu, 24 May 2018 11:34:48 +0200 Subject: [PATCH] Fix YcmShowDetailedDiagnostic command on line without a diagnostic The YcmShowDetailedDiagnostic command raises a NoneType exception on a line with no diagnostic. --- doc/youcompleteme.txt | 4 ++-- python/ycm/tests/youcompleteme_test.py | 16 ++++++++++++++++ python/ycm/youcompleteme.py | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/youcompleteme.txt b/doc/youcompleteme.txt index ecce153f..1cb7cac9 100644 --- a/doc/youcompleteme.txt +++ b/doc/youcompleteme.txt @@ -1900,8 +1900,8 @@ The *GoToDeclaration* subcommand Looks up the symbol under the cursor and jumps to its declaration. -Supported in filetypes: 'c, cpp, objc, objcpp, cuda, cs, go, java, python, rust, -typescript' +Supported in filetypes: 'c, cpp, objc, objcpp, cuda, cs, go, java, python, +rust, typescript' ------------------------------------------------------------------------------- The *GoToDefinition* subcommand diff --git a/python/ycm/tests/youcompleteme_test.py b/python/ycm/tests/youcompleteme_test.py index c08c9ded..90138b06 100644 --- a/python/ycm/tests/youcompleteme_test.py +++ b/python/ycm/tests/youcompleteme_test.py @@ -386,6 +386,22 @@ def YouCompleteMe_ShowDetailedDiagnostic_MessageFromServer_test( ] ) +@YouCompleteMeInstance() +@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock ) +def YouCompleteMe_ShowDetailedDiagnostic_Exception_test( + ycm, post_vim_message ): + + current_buffer = VimBuffer( 'buffer' ) + with MockVimBuffers( [ current_buffer ], current_buffer ): + with patch( 'ycm.client.base_request._JsonFromFuture', + side_effect = RuntimeError( 'Some exception' ) ): + ycm.ShowDetailedDiagnostic(), + + post_vim_message.assert_has_exact_calls( [ + call( 'Some exception', truncate = False ) + ] ) + + @YouCompleteMeInstance() @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock ) def YouCompleteMe_ShowDiagnostics_FiletypeNotSupported_test( ycm, diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 142f191e..67976585 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -660,7 +660,7 @@ class YouCompleteMe( object ): detailed_diagnostic = BaseRequest().PostDataToHandler( BuildRequestData(), 'detailed_diagnostic' ) - if 'message' in detailed_diagnostic: + if detailed_diagnostic and 'message' in detailed_diagnostic: vimsupport.PostVimMessage( detailed_diagnostic[ 'message' ], warning = False )