diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 507b919d..b1554152 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -562,7 +562,6 @@ function! youcompleteme#OmniComplete( findstart, base ) endfunction -" TODO: Make this work again function! s:ShowDetailedDiagnostic() py ycm_state.ShowDetailedDiagnostic() endfunction diff --git a/python/ycm/completers/cpp/clang_completer.py b/python/ycm/completers/cpp/clang_completer.py index a8e5e676..c9e6d209 100644 --- a/python/ycm/completers/cpp/clang_completer.py +++ b/python/ycm/completers/cpp/clang_completer.py @@ -227,13 +227,11 @@ class ClangCompleter( Completer ): current_file = request_data[ 'filepath' ] if not self._diagnostic_store: - return responses.BuildDisplayMessageResponse( - NO_DIAGNOSTIC_MESSAGE ) + raise ValueError( NO_DIAGNOSTIC_MESSAGE ) diagnostics = self._diagnostic_store[ current_file ][ current_line ] if not diagnostics: - return responses.BuildDisplayMessageResponse( - NO_DIAGNOSTIC_MESSAGE ) + raise ValueError( NO_DIAGNOSTIC_MESSAGE ) closest_diagnostic = None distance_to_closest_diagnostic = 999 diff --git a/python/ycm/server/tests/basic_test.py b/python/ycm/server/tests/basic_test.py index 5ff6a218..e09e6449 100644 --- a/python/ycm/server/tests/basic_test.py +++ b/python/ycm/server/tests/basic_test.py @@ -295,7 +295,8 @@ struct Foo { """ filename = '/foo.cpp' - diag_data = { + event_data = { + 'event_name': 'FileReadyToParse', 'compilation_flags': ['-x', 'c++'], 'line_num': 0, 'column_num': 0, @@ -309,17 +310,50 @@ struct Foo { } } + results = app.post_json( '/event_notification', event_data ).json + assert_that( results, + contains( + has_entries( { 'text': contains_string( "expected ';'" ), + 'line_num': 2, + 'column_num': 7 } ) ) ) + + +@with_setup( Setup ) +def GetDetailedDiagnostic_ClangCompleter_Works_test(): + app = TestApp( ycmd.app ) + contents = """ +struct Foo { + int x // semicolon missing here! + int y; + int c; + int d; +}; +""" + + filename = '/foo.cpp' + diag_data = { + 'compilation_flags': ['-x', 'c++'], + 'line_num': 2, + 'column_num': 0, + 'filetypes': ['cpp'], + 'filepath': filename, + 'file_data': { + filename: { + 'contents': contents, + 'filetypes': ['cpp'] + } + } + } + event_data = diag_data.copy() event_data.update( { 'event_name': 'FileReadyToParse', } ) - results = app.post_json( '/event_notification', event_data ).json + app.post_json( '/event_notification', event_data ) + results = app.post_json( '/detailed_diagnostic', diag_data ).json assert_that( results, - contains( - has_entries( { 'text': contains_string( "expected ';'" ), - 'line_num': 2, - 'column_num': 7 } ) ) ) + has_entry( 'message', contains_string( "expected ';'" ) ) ) @with_setup( Setup ) diff --git a/python/ycm/server/ycmd.py b/python/ycm/server/ycmd.py index 8183cb89..50751b9a 100755 --- a/python/ycm/server/ycmd.py +++ b/python/ycm/server/ycmd.py @@ -133,6 +133,15 @@ def DefinedSubcommands(): return _JsonResponse( completer.DefinedSubcommands() ) +@app.post( '/detailed_diagnostic') +def GetDetailedDiagnostic(): + LOGGER.info( 'Received detailed diagnostic request') + request_data = request.json + completer = _GetCompleterForRequestData( request_data ) + + return _JsonResponse( completer.GetDetailedDiagnostic( request_data ) ) + + @app.post( '/debug_info') def DebugInfo(): # This can't be at the top level because of possible extra conf preload diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 66ebd111..ad46f12b 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -194,11 +194,11 @@ class YouCompleteMe( object ): return [] - # TODO: Make this work again. - def GetDetailedDiagnostic( self ): - # if self.FiletypeCompletionUsable(): - # return self.GetFiletypeCompleter().GetDetailedDiagnostic() - pass + def ShowDetailedDiagnostic( self ): + debug_info = BaseRequest.PostDataToHandler( BuildRequestData(), + 'detailed_diagnostic' ) + if 'message' in debug_info: + vimsupport.EchoText( debug_info[ 'message' ] ) def DebugInfo( self ):