DocumentationData TranslationUnit::GetDocsForLocation(
  const Location &location,
  const std::vector< UnsavedFile > &unsaved_files,
  bool reparse ) {

  if ( reparse ) {
    Reparse( unsaved_files );
  }

  unique_lock< mutex > lock( clang_access_mutex_ );

  if ( !clang_translation_unit_ ) {
    return DocumentationData();
  }

  CXCursor cursor = GetCursor( location.filename_,
                               location.line_number_,
                               location.column_number_ );

  if ( !CursorIsValid( cursor ) ) {
    return DocumentationData();
  }

  return DocumentationData( cursor );
}
Beispiel #2
0
DocumentationData TranslationUnit::GetDocsForLocationInFile(
  int line,
  int column,
  const std::vector< UnsavedFile > &unsaved_files,
  bool reparse ) {

  if ( reparse )
    Reparse( unsaved_files );

  unique_lock< mutex > lock( clang_access_mutex_ );

  if ( !clang_translation_unit_ )
    return DocumentationData();

  CXCursor cursor = GetCursor( line, column );

  if ( !CursorIsValid( cursor ) )
    return DocumentationData();

  // If the original cursor is a reference, then we return the documentation
  // for the type/method/etc. that is referenced
  CXCursor referenced_cursor = clang_getCursorReferenced( cursor );

  if ( CursorIsValid( referenced_cursor ) )
    cursor = referenced_cursor;

  // We always want the documentation associated with the canonical declaration
  CXCursor canonical_cursor = clang_getCanonicalCursor( cursor );

  if ( !CursorIsValid( canonical_cursor ) )
    return DocumentationData();

  return DocumentationData( canonical_cursor );
}
Beispiel #3
0
TEST_F( TranslationUnitTest, InvalidTranslationUnit ) {

  TranslationUnit unit;

  EXPECT_TRUE( unit.IsCurrentlyUpdating() );

  EXPECT_EQ( std::vector< CompletionData >(),
             unit.CandidatesForLocation( 1, 1, std::vector< UnsavedFile >() ) );

  EXPECT_EQ( Location(),
             unit.GetDeclarationLocation( 1,
                                          1,
                                          std::vector< UnsavedFile >() ) );

  EXPECT_EQ( Location(),
             unit.GetDefinitionLocation( 1,
                                         1,
                                         std::vector< UnsavedFile >() ) );

  EXPECT_EQ( std::string( "Internal error: no translation unit" ),
             unit.GetTypeAtLocation( 1, 1, std::vector< UnsavedFile >() ) );

  EXPECT_EQ( std::string( "Internal error: no translation unit" ),
             unit.GetEnclosingFunctionAtLocation( 1,
                                                  1,
                                                  std::vector< UnsavedFile >()
                                                ) );

  EXPECT_EQ( DocumentationData(),
             unit.GetDocsForLocationInFile( 1,
                                            1,
                                            std::vector< UnsavedFile >(), false
                                          ) );
}
Beispiel #4
0
DocumentationData ClangCompleter::GetDocsForLocationInFile(
  const std::string &filename,
  int line,
  int column,
  const std::vector< UnsavedFile > &unsaved_files,
  const std::vector< std::string > &flags,
  bool reparse ) {

  ReleaseGil unlock;

  shared_ptr< TranslationUnit > unit =
    translation_unit_store_.GetOrCreate( filename, unsaved_files, flags );

  if ( !unit ) {
    return DocumentationData();
  }

  return unit->GetDocsForLocationInFile( line,
                                         column,
                                         unsaved_files,
                                         reparse );

}