diff --git a/python/test_requirements.txt b/python/test_requirements.txt index 1170bb4d..43dc2869 100644 --- a/python/test_requirements.txt +++ b/python/test_requirements.txt @@ -1,6 +1,6 @@ flake8>=2.0 mock>=1.0.1 nose>=1.3.0 -PyHamcrest>=1.7.2 +PyHamcrest>=1.8.0 WebTest>=2.0.9 diff --git a/python/ycm/completers/cpp/clang_completer.py b/python/ycm/completers/cpp/clang_completer.py index 1771dfad..0a835dfa 100644 --- a/python/ycm/completers/cpp/clang_completer.py +++ b/python/ycm/completers/cpp/clang_completer.py @@ -35,6 +35,7 @@ FILE_TOO_SHORT_MESSAGE = ( 'File is less than {0} lines long; not compiling.'.format( MIN_LINES_IN_FILE_TO_PARSE ) ) NO_DIAGNOSTIC_MESSAGE = 'No diagnostic for current line!' +PRAGMA_DIAG_TEXT_TO_IGNORE = '#pragma once in main file' class ClangCompleter( Completer ): @@ -196,6 +197,7 @@ class ClangCompleter( Completer ): self.GetUnsavedFilesVector( request_data ), flags ) + diagnostics = _FilterDiagnostics( diagnostics ) self._diagnostic_store = DiagnosticsToDiagStructure( diagnostics ) return [ ConvertToDiagnosticResponse( x ) for x in diagnostics[ : self._max_diagnostics_to_display ] ] @@ -261,7 +263,7 @@ def ConvertCompletionData( completion_data ): def DiagnosticsToDiagStructure( diagnostics ): - structure = defaultdict(lambda : defaultdict(list)) + structure = defaultdict( lambda : defaultdict( list ) ) for diagnostic in diagnostics: structure[ diagnostic.filename_ ][ diagnostic.line_number_ ].append( diagnostic ) @@ -283,4 +285,14 @@ def ConvertToDiagnosticResponse( diagnostic ): 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 + # legitimate because it shows up because libclang thinks we are compiling a + # source file instead of a header file. + # + # See our issue #216 and upstream bug: + # http://llvm.org/bugs/show_bug.cgi?id=16686 + return [ x for x in diagnostics if x.text_ != PRAGMA_DIAG_TEXT_TO_IGNORE ] + diff --git a/python/ycm/server/tests/diagnostics_test.py b/python/ycm/server/tests/diagnostics_test.py index 6f1d199b..c0c87ace 100644 --- a/python/ycm/server/tests/diagnostics_test.py +++ b/python/ycm/server/tests/diagnostics_test.py @@ -23,7 +23,7 @@ from .test_utils import Setup, BuildRequest from webtest import TestApp from nose.tools import with_setup from hamcrest import ( assert_that, contains, contains_string, has_entries, - has_entry ) + has_entry, empty ) from .. import handlers import bottle @@ -53,6 +53,29 @@ struct Foo { 'line_num': 2, 'column_num': 7 } ) ) ) +@with_setup( Setup ) +def Diagnostics_ClangCompleter_PragmaOnceWarningIgnored_test(): + app = TestApp( handlers.app ) + contents = """ +#pragma once + +struct Foo { + int x; + int y; + int c; + int d; +}; +""" + + event_data = BuildRequest( compilation_flags = ['-x', 'c++'], + event_name = 'FileReadyToParse', + contents = contents, + filepath = '/foo.h', + filetype = 'cpp' ) + + response = app.post_json( '/event_notification', event_data ) + assert_that( response.body, empty() ) + @with_setup( Setup ) def GetDetailedDiagnostic_ClangCompleter_Works_test():