Workaround for annoying clang bug with pragma once

Fixes #216
This commit is contained in:
Strahinja Val Markovic 2013-11-17 17:59:39 -08:00
parent 06b5411fb3
commit 5ae3a573b9
3 changed files with 38 additions and 3 deletions

View File

@ -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

View File

@ -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 ]

View File

@ -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():