ycm_core.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Copyright (C) 2011, 2012 Google Inc.
  2. //
  3. // This file is part of YouCompleteMe.
  4. //
  5. // YouCompleteMe is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // YouCompleteMe is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. #include "IdentifierCompleter.h"
  18. #include "PythonSupport.h"
  19. #include "versioning.h"
  20. #ifdef USE_CLANG_COMPLETER
  21. # include "ClangCompleter.h"
  22. # include "ClangUtils.h"
  23. # include "CompletionData.h"
  24. # include "Diagnostic.h"
  25. # include "Location.h"
  26. # include "Range.h"
  27. # include "UnsavedFile.h"
  28. # include "CompilationDatabase.h"
  29. #endif // USE_CLANG_COMPLETER
  30. #include <boost/python.hpp>
  31. #include <boost/utility.hpp>
  32. #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
  33. bool HasClangSupport() {
  34. #ifdef USE_CLANG_COMPLETER
  35. return true;
  36. #else
  37. return false;
  38. #endif // USE_CLANG_COMPLETER
  39. }
  40. BOOST_PYTHON_MODULE(ycm_core)
  41. {
  42. using namespace boost::python;
  43. using namespace YouCompleteMe;
  44. // Necessary because of usage of the ReleaseGil class
  45. PyEval_InitThreads();
  46. def( "HasClangSupport", HasClangSupport );
  47. def( "FilterAndSortCandidates", FilterAndSortCandidates );
  48. def( "YcmCoreVersion", YcmCoreVersion );
  49. class_< IdentifierCompleter, boost::noncopyable >( "IdentifierCompleter" )
  50. .def( "AddIdentifiersToDatabase",
  51. &IdentifierCompleter::AddIdentifiersToDatabase )
  52. .def( "AddIdentifiersToDatabaseFromTagFiles",
  53. &IdentifierCompleter::AddIdentifiersToDatabaseFromTagFiles )
  54. .def( "AddIdentifiersToDatabaseFromBuffer",
  55. &IdentifierCompleter::AddIdentifiersToDatabaseFromBuffer )
  56. .def( "CandidatesForQueryAndType",
  57. &IdentifierCompleter::CandidatesForQueryAndType );
  58. // TODO: rename these *Vec classes to *Vector; don't forget the python file
  59. class_< std::vector< std::string >,
  60. boost::shared_ptr< std::vector< std::string > > >( "StringVec" )
  61. .def( vector_indexing_suite< std::vector< std::string > >() );
  62. #ifdef USE_CLANG_COMPLETER
  63. def( "ClangVersion", ClangVersion );
  64. // CAREFUL HERE! For filename and contents we are referring directly to
  65. // Python-allocated and -managed memory since we are accepting pointers to
  66. // data members of python objects. We need to ensure that those objects
  67. // outlive our UnsavedFile objects.
  68. class_< UnsavedFile >( "UnsavedFile" )
  69. .add_property( "filename_",
  70. make_getter( &UnsavedFile::filename_ ),
  71. make_setter( &UnsavedFile::filename_,
  72. return_value_policy< reference_existing_object >() ) )
  73. .add_property( "contents_",
  74. make_getter( &UnsavedFile::contents_ ),
  75. make_setter( &UnsavedFile::contents_,
  76. return_value_policy< reference_existing_object >() ) )
  77. .def_readwrite( "length_", &UnsavedFile::length_ );
  78. class_< std::vector< UnsavedFile > >( "UnsavedFileVec" )
  79. .def( vector_indexing_suite< std::vector< UnsavedFile > >() );
  80. class_< ClangCompleter, boost::noncopyable >( "ClangCompleter" )
  81. .def( "GetDeclarationLocation", &ClangCompleter::GetDeclarationLocation )
  82. .def( "GetDefinitionLocation", &ClangCompleter::GetDefinitionLocation )
  83. .def( "DeleteCachesForFile", &ClangCompleter::DeleteCachesForFile )
  84. .def( "UpdatingTranslationUnit", &ClangCompleter::UpdatingTranslationUnit )
  85. .def( "UpdateTranslationUnit", &ClangCompleter::UpdateTranslationUnit )
  86. .def( "CandidatesForLocationInFile",
  87. &ClangCompleter::CandidatesForLocationInFile );
  88. class_< CompletionData >( "CompletionData" )
  89. .def( "TextToInsertInBuffer", &CompletionData::TextToInsertInBuffer )
  90. .def( "MainCompletionText", &CompletionData::MainCompletionText )
  91. .def( "ExtraMenuInfo", &CompletionData::ExtraMenuInfo )
  92. .def( "DetailedInfoForPreviewWindow",
  93. &CompletionData::DetailedInfoForPreviewWindow )
  94. .def_readonly( "kind_", &CompletionData::kind_ );
  95. class_< std::vector< CompletionData >,
  96. boost::shared_ptr< std::vector< CompletionData > > >( "CompletionVec" )
  97. .def( vector_indexing_suite< std::vector< CompletionData > >() );
  98. class_< Location >( "Location" )
  99. .def_readonly( "line_number_", &Location::line_number_ )
  100. .def_readonly( "column_number_", &Location::column_number_ )
  101. .def_readonly( "filename_", &Location::filename_ )
  102. .def( "IsValid", &Location::IsValid );
  103. class_< Range >( "Range" )
  104. .def_readonly( "start_", &Range::start_ )
  105. .def_readonly( "end_", &Range::end_ );
  106. class_< std::vector< Range > >( "RangeVec" )
  107. .def( vector_indexing_suite< std::vector< Range > >() );
  108. class_< Diagnostic >( "Diagnostic" )
  109. .def_readonly( "ranges_", &Diagnostic::ranges_ )
  110. .def_readonly( "location_", &Diagnostic::location_ )
  111. .def_readonly( "location_extent_", &Diagnostic::location_extent_ )
  112. .def_readonly( "kind_", &Diagnostic::kind_ )
  113. .def_readonly( "text_", &Diagnostic::text_ )
  114. .def_readonly( "long_formatted_text_", &Diagnostic::long_formatted_text_ );
  115. class_< std::vector< Diagnostic > >( "DiagnosticVec" )
  116. .def( vector_indexing_suite< std::vector< Diagnostic > >() );
  117. class_< CompilationDatabase, boost::noncopyable >(
  118. "CompilationDatabase", init< std::string >() )
  119. .def( "DatabaseSuccessfullyLoaded",
  120. &CompilationDatabase::DatabaseSuccessfullyLoaded )
  121. .def( "AlreadyGettingFlags",
  122. &CompilationDatabase::AlreadyGettingFlags )
  123. .def( "GetCompilationInfoForFile",
  124. &CompilationDatabase::GetCompilationInfoForFile );
  125. class_< CompilationInfoForFile,
  126. boost::shared_ptr< CompilationInfoForFile > >(
  127. "CompilationInfoForFile", no_init )
  128. .def_readonly( "compiler_working_dir_",
  129. &CompilationInfoForFile::compiler_working_dir_ )
  130. .def_readonly( "compiler_flags_",
  131. &CompilationInfoForFile::compiler_flags_ );
  132. #endif // USE_CLANG_COMPLETER
  133. }
  134. // Boost.Thread forces us to implement this.
  135. // We don't use any thread-specific (local) storage so it's fine to implement
  136. // this as an empty function.
  137. namespace boost {
  138. void tss_cleanup_implemented() {}
  139. };