def CppBindings_DefinitionLocation_test():
  translation_unit = ToCppStr( PathToTestFile( 'foo.c' ) )
  filename = ToCppStr( PathToTestFile( 'foo.c' ) )
  line = 9
  column = 17
  unsaved_file_vector = ycm_core.UnsavedFileVector()
  flags = ycm_core.StringVector()
  flags.append( ToCppStr( '-xc++' ) )
  reparse = True
  clang_completer = ycm_core.ClangCompleter()

  location = clang_completer.GetDefinitionLocation( translation_unit,
                                                    filename,
                                                    line,
                                                    column,
                                                    unsaved_file_vector,
                                                    flags,
                                                    reparse )

  del translation_unit
  del filename
  del line
  del column
  del unsaved_file_vector
  del flags
  del clang_completer
  del reparse
  assert_that( location,
               has_properties( { 'line_number_': 2,
                                 'column_number_': 5,
                                 'filename_': PathToTestFile( 'foo.c' ) } ) )
def CppBindings_GetType_test():
  translation_unit = ToCppStr( PathToTestFile( 'foo.c' ) )
  filename = ToCppStr( PathToTestFile( 'foo.c' ) )
  line = 9
  column = 17
  unsaved_file_vector = ycm_core.UnsavedFileVector()
  flags = ycm_core.StringVector()
  flags.append( ToCppStr( '-xc++' ) )
  reparse = True
  clang_completer = ycm_core.ClangCompleter()

  type_at_cursor = clang_completer.GetTypeAtLocation( translation_unit,
                                                      filename,
                                                      line,
                                                      column,
                                                      unsaved_file_vector,
                                                      flags,
                                                      reparse )
  del translation_unit
  del filename
  del line
  del column
  del unsaved_file_vector
  del flags
  del clang_completer
  del reparse

  eq_( 'int ()', type_at_cursor )
Exemple #3
0
 def __init__(self, user_options):
     super(ClangCompleter, self).__init__(user_options)
     self._completer = ycm_core.ClangCompleter()
     self._flags = Flags()
     self._include_cache = IncludeCache()
     self._diagnostic_store = None
     self._files_being_compiled = EphemeralValuesSet()
def CppBindings_GetParent_test():
  translation_unit = ToCppStr( PathToTestFile( 'foo.c' ) )
  filename = ToCppStr( PathToTestFile( 'foo.c' ) )
  line = 9
  column = 17
  unsaved_file_vector = ycm_core.UnsavedFileVector()
  flags = ycm_core.StringVector()
  flags.append( ToCppStr( '-xc++' ) )
  reparse = True
  clang_completer = ycm_core.ClangCompleter()

  enclosing_function = ( clang_completer
                           .GetEnclosingFunctionAtLocation( translation_unit,
                                                            filename,
                                                            line,
                                                            column,
                                                            unsaved_file_vector,
                                                            flags,
                                                            reparse ) )

  del translation_unit
  del filename
  del line
  del column
  del unsaved_file_vector
  del flags
  del clang_completer
  del reparse

  eq_( 'bar', enclosing_function )
Exemple #5
0
 def __init__(self, user_options):
     super(ClangCompleter, self).__init__(user_options)
     self._max_diagnostics_to_display = user_options[
         'max_diagnostics_to_display']
     self._completer = ycm_core.ClangCompleter()
     self._flags = Flags()
     self._diagnostic_store = None
Exemple #6
0
 def __init__(self, user_options):
     super(ClangCompleter, self).__init__(user_options)
     self._max_diagnostics_to_display = user_options[
         'max_diagnostics_to_display']
     self._completer = ycm_core.ClangCompleter()
     self._flags = Flags()
     self._diagnostic_store = None
     self._files_being_compiled = EphemeralValuesSet()
Exemple #7
0
 def __init__( self ):
   self.completer = ycm_core.ClangCompleter()
   self.completer.EnableThreading()
   self.contents_holder = []
   self.filename_holder = []
   self.last_prepared_diagnostics = []
   self.parse_future = None
   self.flags = Flags()
   self.diagnostic_store = None
Exemple #8
0
 def __init__( self, user_options ):
   super( ClangCompleter, self ).__init__( user_options )
   self._max_diagnostics_to_display = user_options[
     'max_diagnostics_to_display' ]
   self._completer = ycm_core.ClangCompleter()
   self._flags = Flags()
   self._include_cache = IncludeCache()
   self._diagnostic_store = None
   self._files_being_compiled = EphemeralValuesSet()
   self._logger = logging.getLogger( __name__ )
Exemple #9
0
def CppBindings_FixIt_test():
    translation_unit = ToCppStr(PathToTestFile('foo.c'))
    filename = ToCppStr(PathToTestFile('foo.c'))
    line = 3
    column = 5
    unsaved_file_vector = ycm_core.UnsavedFileVector()
    flags = ycm_core.StringVector()
    flags.append(ToCppStr('-xc++'))
    reparse = True
    clang_completer = ycm_core.ClangCompleter()

    fixits = clang_completer.GetFixItsForLocationInFile(
        translation_unit, filename, line, column, unsaved_file_vector, flags,
        reparse)
    del translation_unit
    del filename
    del line
    del column
    del unsaved_file_vector
    del flags
    del clang_completer
    del reparse

    assert_that(
        fixits,
        contains(
            has_properties({
                'text': (PathToTestFile('foo.c') +
                         ':3:16: error: expected \';\' at end of declaration'),
                'location':
                has_properties({
                    'line_number_': 3,
                    'column_number_': 16,
                    'filename_': PathToTestFile('foo.c')
                }),
                'chunks':
                contains(
                    has_properties({
                        'replacement_text':
                        ';',
                        'range':
                        has_properties({
                            'start_':
                            has_properties({
                                'line_number_': 3,
                                'column_number_': 16,
                            }),
                            'end_':
                            has_properties({
                                'line_number_': 3,
                                'column_number_': 16,
                            }),
                        })
                    })),
            })))
def CppBindings_FixItChunkVector_test():
    flags = ycm_core.StringVector()
    flags.append(ToCppStr('-xc++'))
    clang_completer = ycm_core.ClangCompleter()
    translation_unit = PathToTestFile('foo.c')
    filename = PathToTestFile('foo.c')
    fixits = (clang_completer.GetFixItsForLocationInFile(
        ToCppStr(translation_unit), ToCppStr(filename), 3, 5,
        ycm_core.UnsavedFileVector(), flags, True))

    fixit_chunks = fixits[0].chunks[0:1]
    EmplaceBack(fixit_chunks, fixit_chunks[0])
    del translation_unit
    del flags
    del filename
    del clang_completer
    del fixits
    assert_that(
        fixit_chunks,
        contains(
            has_properties({
                'replacement_text':
                ';',
                'range':
                has_properties({
                    'start_':
                    has_properties({
                        'line_number_': 3,
                        'column_number_': 16,
                    }),
                    'end_':
                    has_properties({
                        'line_number_': 3,
                        'column_number_': 16,
                    }),
                }),
            }),
            has_properties({
                'replacement_text':
                ';',
                'range':
                has_properties({
                    'start_':
                    has_properties({
                        'line_number_': 3,
                        'column_number_': 16,
                    }),
                    'end_':
                    has_properties({
                        'line_number_': 3,
                        'column_number_': 16,
                    }),
                }),
            })))
def CppBindings_CompletionDataVector_test():
  translation_unit = ToCppStr( PathToTestFile( 'foo.c' ) )
  filename = ToCppStr( PathToTestFile( 'foo.c' ) )
  line = 11
  column = 6
  unsaved_file_vector = ycm_core.UnsavedFileVector()
  flags = ycm_core.StringVector()
  flags.append( ToCppStr( '-xc' ) )
  clang_completer = ycm_core.ClangCompleter()

  candidates = ( clang_completer
                   .CandidatesForLocationInFile( translation_unit,
                                                 filename,
                                                 line,
                                                 column,
                                                 unsaved_file_vector,
                                                 flags ) )


  if candidates[ 0 ].TextToInsertInBuffer() == 'a':
    candidate = candidates[ 0 ]
  else:
    candidate = candidates[ 1 ]
  candidates = ycm_core.CompletionVector()
  candidates.append( candidate )
  EmplaceBack( candidates, candidate )

  del translation_unit
  del filename
  del candidate
  del clang_completer
  del line
  del column
  del flags
  del unsaved_file_vector
  candidates = [ ConvertCompletionData( x ) for x in candidates ]
  assert_that( candidates, contains_inanyorder(
                             has_entries( {
                               'detailed_info': 'int a\n',
                               'extra_menu_info': 'int',
                               'insertion_text': 'a',
                               'kind': 'MEMBER',
                               'menu_text': 'a'
                             } ),
                             has_entries( {
                               'detailed_info': 'int a\n',
                               'extra_menu_info': 'int',
                               'insertion_text': 'a',
                               'kind': 'MEMBER',
                               'menu_text': 'a'
                             } )
                           ) )
Exemple #12
0
def CppBindings_Diags_test():
    filename = ToCppStr(PathToTestFile('foo.c'))
    unsaved_file_vector = ycm_core.UnsavedFileVector()
    flags = ycm_core.StringVector()
    flags.append(ToCppStr('-xc++'))
    reparse = True
    clang_completer = ycm_core.ClangCompleter()

    diag_vector = clang_completer.UpdateTranslationUnit(
        filename, unsaved_file_vector, flags)

    diags = [BuildDiagnosticData(x) for x in diag_vector]

    del diag_vector
    del filename
    del unsaved_file_vector
    del flags
    del clang_completer
    del reparse

    assert_that(
        diags,
        contains(
            has_entries({
                'kind':
                'ERROR',
                'text':
                contains_string('expected \';\' at end of declaration'),
                'ranges':
                contains(),
                'location':
                has_entries({
                    'line_num': 3,
                    'column_num': 16,
                }),
                'location_extent':
                has_entries({
                    'start':
                    has_entries({
                        'line_num': 3,
                        'column_num': 16,
                    }),
                    'end':
                    has_entries({
                        'line_num': 3,
                        'column_num': 16,
                    }),
                }),
            })))
Exemple #13
0
def CppBindings_RangeVector_test():
    flags = ycm_core.StringVector()
    flags.append('-xc++')
    clang_completer = ycm_core.ClangCompleter()
    translation_unit = PathToTestFile('foo.c')
    filename = PathToTestFile('foo.c')

    fixits = (clang_completer.GetFixItsForLocationInFile(
        translation_unit, filename, 3, 5, ycm_core.UnsavedFileVector(), flags,
        True))
    fixit_range = fixits[0].chunks[0].range
    ranges = ycm_core.RangeVector()
    ranges.append(fixit_range)
    EmplaceBack(ranges, fixit_range)
    del flags
    del translation_unit
    del filename
    del clang_completer
    del fixits
    del fixit_range
    assert_that(
        ranges,
        contains_exactly(
            has_properties({
                'start_':
                has_properties({
                    'line_number_': 3,
                    'column_number_': 16,
                }),
                'end_':
                has_properties({
                    'line_number_': 3,
                    'column_number_': 16,
                }),
            }),
            has_properties({
                'start_':
                has_properties({
                    'line_number_': 3,
                    'column_number_': 16,
                }),
                'end_':
                has_properties({
                    'line_number_': 3,
                    'column_number_': 16,
                }),
            }),
        ))
Exemple #14
0
    def __init__(self):
        super(ClangCompleter, self).__init__()
        self.completer = ycm_core.ClangCompleter()
        self.completer.EnableThreading()
        self.contents_holder = []
        self.filename_holder = []
        self.last_prepared_diagnostics = []
        self.parse_future = None
        self.flags = Flags()
        self.diagnostic_store = None

        # We set this flag when a compilation request comes in while one is already
        # in progress. We use this to trigger the pending request after the previous
        # one completes (from GetDiagnosticsForCurrentFile because that's the only
        # method that knows when the compilation has finished).
        self.extra_parse_desired = False
def CppBindings_Candidates_test():
  translation_unit = ToCppStr( PathToTestFile( 'foo.c' ) )
  filename = ToCppStr( PathToTestFile( 'foo.c' ) )
  line = 11
  column = 6
  unsaved_file_vector = ycm_core.UnsavedFileVector()
  flags = ycm_core.StringVector()
  flags.append( ToCppStr( '-xc' ) )
  reparse = True
  clang_completer = ycm_core.ClangCompleter()

  candidates = ( clang_completer
                   .CandidatesForLocationInFile( translation_unit,
                                                 filename,
                                                 line,
                                                 column,
                                                 unsaved_file_vector,
                                                 flags ) )

  del translation_unit
  del filename
  del line
  del column
  del unsaved_file_vector
  del flags
  del clang_completer
  del reparse
  candidates = [ ConvertCompletionData( x ) for x in candidates ]
  assert_that( candidates, contains_inanyorder(
                             has_entries( {
                               'detailed_info': 'float b\n',
                               'extra_menu_info': 'float',
                               'insertion_text': 'b',
                               'kind': 'MEMBER',
                               'menu_text': 'b'
                             } ),
                             has_entries( {
                               'detailed_info': 'int a\n',
                               'extra_menu_info': 'int',
                               'insertion_text': 'a',
                               'kind': 'MEMBER',
                               'menu_text': 'a'
                             } )
                           ) )
Exemple #16
0
def CppBindings_Docs_test():
    translation_unit = ToCppStr(PathToTestFile('foo.c'))
    filename = ToCppStr(PathToTestFile('foo.c'))
    line = 9
    column = 16
    unsaved_file_vector = ycm_core.UnsavedFileVector()
    flags = ycm_core.StringVector()
    flags.append(ToCppStr('-xc++'))
    reparse = True
    clang_completer = ycm_core.ClangCompleter()

    docs = clang_completer.GetDocsForLocationInFile(translation_unit, filename,
                                                    line, column,
                                                    unsaved_file_vector, flags,
                                                    reparse)
    del translation_unit
    del filename
    del line
    del column
    del unsaved_file_vector
    del flags
    del clang_completer
    del reparse
    assert_that(
        docs,
        has_properties({
            'comment_xml':
            '<Function file="' + PathToTestFile('foo.c') + '"'
            ' line="2" column="5"><Name>foooo</Name><USR>c:@F@foooo#'
            '</USR><Declaration>int foooo()</Declaration><Abstract>'
            '<Para> Foo</Para></Abstract></Function>',
            'brief_comment':
            'Foo',
            'raw_comment':
            '/// Foo',
            'canonical_type':
            'int ()',
            'display_name':
            'foooo'
        }))
Exemple #17
0
from codeintel2 import util
from codeintel2.common import Trigger, TRG_FORM_CPLN, TRG_FORM_CALLTIP, TRG_FORM_DEFN, CILEDriver, Definition
from codeintel2.citadel import CitadelLangIntel, CitadelBuffer
from codeintel2.langintel import (ParenStyleCalltipIntelMixin,
                                  ProgLangTriggerIntelMixin)
from codeintel2.tree import tree_from_cix

# ---- globals

lang = "C++"
log = logging.getLogger("codeintel.cpp")
# log.setLevel(logging.DEBUG)

try:
    import ycm_core
    completer = ycm_core.ClangCompleter()
except ImportError:
    completer = None
    log.warning(
        "Module ycm_core not available. C++ requires ycmd generated ycm_core and libclang in %s",
        "codeintel moduel path")

PRAGMA_DIAG_TEXT_TO_IGNORE = '#pragma once in main file'
TOO_MANY_ERRORS_DIAG_TEXT_TO_IGNORE = 'too many errors emitted, stopping now'


def to_utf8(value):
    if isinstance(value, unicode):
        return value.encode('utf-8')
    if isinstance(value, str):
        return value
def CppBindings_FixItVector_test():
    flags = ycm_core.StringVector()
    flags.append(ToCppStr('-xc++'))
    clang_completer = ycm_core.ClangCompleter()
    translation_unit = PathToTestFile('foo.c')
    filename = ToCppStr(PathToTestFile('foo.c'))
    fixits = (clang_completer.GetFixItsForLocationInFile(
        ToCppStr(translation_unit), ToCppStr(filename), 3, 5,
        ycm_core.UnsavedFileVector(), flags, True))

    fixits = fixits[0:1]
    EmplaceBack(fixits, fixits[0])
    del translation_unit
    del flags
    del filename
    del clang_completer
    assert_that(
        fixits,
        contains(
            has_properties({
                'text': (PathToTestFile('foo.c') +
                         ':3:16: error: expected \';\' at end of declaration'),
                'location':
                has_properties({
                    'line_number_': 3,
                    'column_number_': 16,
                    'filename_': PathToTestFile('foo.c')
                }),
                'chunks':
                contains(
                    has_properties({
                        'replacement_text':
                        ';',
                        'range':
                        has_properties({
                            'start_':
                            has_properties({
                                'line_number_': 3,
                                'column_number_': 16,
                            }),
                            'end_':
                            has_properties({
                                'line_number_': 3,
                                'column_number_': 16,
                            }),
                        })
                    })),
            }),
            has_properties({
                'text': (PathToTestFile('foo.c') +
                         ':3:16: error: expected \';\' at end of declaration'),
                'location':
                has_properties({
                    'line_number_': 3,
                    'column_number_': 16,
                    'filename_': PathToTestFile('foo.c')
                }),
                'chunks':
                contains(
                    has_properties({
                        'replacement_text':
                        ';',
                        'range':
                        has_properties({
                            'start_':
                            has_properties({
                                'line_number_': 3,
                                'column_number_': 16,
                            }),
                            'end_':
                            has_properties({
                                'line_number_': 3,
                                'column_number_': 16,
                            }),
                        })
                    })),
            })))