diff --git a/cpp/ycm/ycm_core.cpp b/cpp/ycm/ycm_core.cpp index a7e80507..0d7c6ac7 100644 --- a/cpp/ycm/ycm_core.cpp +++ b/cpp/ycm/ycm_core.cpp @@ -109,8 +109,7 @@ BOOST_PYTHON_MODULE(ycm_core) .def_readonly( "kind_", &CompletionData::kind_ ); class_< std::vector< CompletionData >, - boost::shared_ptr< std::vector< CompletionData > > >( - "CompletionVec" ) + boost::shared_ptr< std::vector< CompletionData > > >( "CompletionVec" ) .def( vector_indexing_suite< std::vector< CompletionData > >() ); class_< Location >( "Location" ) @@ -123,9 +122,7 @@ BOOST_PYTHON_MODULE(ycm_core) .def_readonly( "start_", &Range::start_ ) .def_readonly( "end_", &Range::end_ ); - class_< std::vector< Range >, - boost::shared_ptr< std::vector< Range > > >( - "RangeVec" ) + class_< std::vector< Range > >( "RangeVec" ) .def( vector_indexing_suite< std::vector< Range > >() ); class_< Diagnostic >( "Diagnostic" ) diff --git a/python/ycm/client/event_notification.py b/python/ycm/client/event_notification.py index 498cd5c7..1c13226e 100644 --- a/python/ycm/client/event_notification.py +++ b/python/ycm/client/event_notification.py @@ -76,10 +76,11 @@ def _ConvertDiagnosticDataToVimData( diagnostic ): # Note that, as usual, Vim is completely inconsistent about whether # line/column numbers are 1 or 0 based in its various APIs. Here, it wants # them to be 1-based. + location = diagnostic[ 'location' ] return { - 'bufnr' : vimsupport.GetBufferNumberForFilename( diagnostic[ 'filepath' ] ), - 'lnum' : diagnostic[ 'line_num' ] + 1, - 'col' : diagnostic[ 'column_num' ] + 1, + 'bufnr' : vimsupport.GetBufferNumberForFilename( location[ 'filepath' ] ), + 'lnum' : location[ 'line_num' ] + 1, + 'col' : location[ 'column_num' ] + 1, 'text' : diagnostic[ 'text' ], 'type' : diagnostic[ 'kind' ], 'valid' : 1 diff --git a/python/ycm/completers/cpp/clang_completer.py b/python/ycm/completers/cpp/clang_completer.py index 70f47c73..07cd089f 100644 --- a/python/ycm/completers/cpp/clang_completer.py +++ b/python/ycm/completers/cpp/clang_completer.py @@ -200,7 +200,7 @@ class ClangCompleter( Completer ): diagnostics = _FilterDiagnostics( diagnostics ) self._diagnostic_store = DiagnosticsToDiagStructure( diagnostics ) - return [ ConvertToDiagnosticResponse( x ) for x in + return [ responses.BuildDiagnosticData( x ) for x in diagnostics[ : self._max_diagnostics_to_display ] ] @@ -279,13 +279,6 @@ def InCFamilyFile( filetypes ): return ClangAvailableForFiletypes( filetypes ) -def ConvertToDiagnosticResponse( diagnostic ): - return responses.BuildDiagnosticData( diagnostic.location_.filename_, - diagnostic.location_.line_number_ - 1, - diagnostic.location_.column_number_ - 1, - diagnostic.text_, - diagnostic.kind_ ) - def _FilterDiagnostics( diagnostics ): # Clang has an annoying warning that shows up when we try to compile header # files if the header has "#pragma once" inside it. The error is not diff --git a/python/ycm/server/responses.py b/python/ycm/server/responses.py index 21fc4869..88b97ffd 100644 --- a/python/ycm/server/responses.py +++ b/python/ycm/server/responses.py @@ -101,17 +101,25 @@ def BuildCompletionData( insertion_text, return completion_data -def BuildDiagnosticData( filepath, - line_num, - column_num, - text, - kind ): +def BuildDiagnosticData( diagnostic ): + def BuildRangeData( source_range ): + return { + 'start': BuildLocationData( source_range.start_ ), + 'end': BuildLocationData( source_range.end_ ), + } + + def BuildLocationData( location ): + return { + 'line_num': location.line_number_ - 1, + 'column_num': location.column_number_ - 1, + 'filepath': location.filename_, + } + return { - 'filepath': filepath, - 'line_num': line_num, - 'column_num': column_num, - 'text': text, - 'kind': kind + 'ranges': [ BuildRangeData( x ) for x in diagnostic.ranges_ ], + 'location': BuildLocationData( diagnostic.location_ ), + 'text': diagnostic.text_, + 'kind': diagnostic.kind_ } diff --git a/python/ycm/server/tests/diagnostics_test.py b/python/ycm/server/tests/diagnostics_test.py index be7b71c9..f426df51 100644 --- a/python/ycm/server/tests/diagnostics_test.py +++ b/python/ycm/server/tests/diagnostics_test.py @@ -35,12 +35,11 @@ bottle.debug( True ) def Diagnostics_ClangCompleter_ZeroBasedLineAndColumn_test(): app = TestApp( handlers.app ) contents = """ -struct Foo { - int x // semicolon missing here! - int y; - int c; - int d; -}; +void foo() { + double baz = "foo"; +} +// Padding to 5 lines +// Padding to 5 lines """ event_data = BuildRequest( compilation_flags = ['-x', 'c++'], @@ -49,11 +48,26 @@ struct Foo { filetype = 'cpp' ) results = app.post_json( '/event_notification', event_data ).json + print results assert_that( results, contains( - has_entries( { 'text': contains_string( "expected ';'" ), - 'line_num': 2, - 'column_num': 7 } ) ) ) + has_entries( { + 'text': contains_string( 'cannot initialize' ), + 'ranges': contains( has_entries( { + 'start': has_entries( { + 'line_num': 2, + 'column_num': 15, + } ), + 'end': has_entries( { + 'line_num': 2, + 'column_num': 20, + } ), + } ) ), + 'location': has_entries( { + 'line_num': 2, + 'column_num': 9 + } ) + } ) ) ) @with_setup( Setup ) def Diagnostics_ClangCompleter_PragmaOnceWarningIgnored_test():