Adding CompilationDatabase support (still WIP)
This commit is contained in:
parent
f9a516704b
commit
c1119c001f
@ -25,13 +25,14 @@
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
|
||||
struct CompletionData;
|
||||
|
||||
class ClangResultsCache
|
||||
class ClangResultsCache : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
|
115
cpp/ycm/ClangCompleter/CompilationDatabase.cpp
Normal file
115
cpp/ycm/ClangCompleter/CompilationDatabase.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
// Copyright (C) 2011, 2012 Strahinja Val Markovic <val@markovic.io>
|
||||
//
|
||||
// This file is part of YouCompleteMe.
|
||||
//
|
||||
// YouCompleteMe is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// YouCompleteMe is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "CompilationDatabase.h"
|
||||
#include "ClangUtils.h"
|
||||
#include "standard.h"
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
|
||||
CompilationDatabase::CompilationDatabase(
|
||||
const std::string& path_to_directory )
|
||||
: is_loaded_( false )
|
||||
{
|
||||
CXCompilationDatabase_Error status;
|
||||
compilation_database_ = clang_CompilationDatabase_fromDirectory(
|
||||
path_to_directory.c_str(),
|
||||
&status );
|
||||
is_loaded_ = status == CXCompilationDatabase_NoError;
|
||||
}
|
||||
|
||||
|
||||
CompilationDatabase::~CompilationDatabase()
|
||||
{
|
||||
clang_CompilationDatabase_dispose( compilation_database_ );
|
||||
}
|
||||
|
||||
|
||||
bool CompilationDatabase::DatabaseSuccessfullyLoaded()
|
||||
{
|
||||
return is_loaded_;
|
||||
}
|
||||
|
||||
|
||||
std::vector< std::string > CompilationDatabase::FlagsForFile(
|
||||
const std::string &path_to_file )
|
||||
{
|
||||
std::vector< std::string > flags;
|
||||
if ( !is_loaded_ )
|
||||
return flags;
|
||||
|
||||
CXCompileCommands commands =
|
||||
clang_CompilationDatabase_getCompileCommands(
|
||||
compilation_database_,
|
||||
path_to_file.c_str() );
|
||||
|
||||
uint num_commands = clang_CompileCommands_getSize( commands );
|
||||
if ( num_commands < 1 ) {
|
||||
clang_CompileCommands_dispose( commands );
|
||||
return flags;
|
||||
}
|
||||
|
||||
// We always pick the first command offered
|
||||
CXCompileCommand command = clang_CompileCommands_getCommand(
|
||||
commands,
|
||||
0);
|
||||
|
||||
uint num_flags = clang_CompileCommand_getNumArgs( command );
|
||||
flags.reserve( num_flags );
|
||||
for ( uint i = 0; i < num_flags; ++i )
|
||||
{
|
||||
flags.push_back( CXStringToString(
|
||||
clang_CompileCommand_getArg( command, i ) ) );
|
||||
}
|
||||
|
||||
clang_CompileCommands_dispose( commands );
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
std::string CompilationDatabase::CompileCommandWorkingDirectoryForFile(
|
||||
const std::string &path_to_file )
|
||||
{
|
||||
std::string path_to_directory;
|
||||
if ( !is_loaded_ )
|
||||
return path_to_directory;
|
||||
|
||||
CXCompileCommands commands =
|
||||
clang_CompilationDatabase_getCompileCommands(
|
||||
compilation_database_,
|
||||
path_to_file.c_str() );
|
||||
|
||||
uint num_commands = clang_CompileCommands_getSize( commands );
|
||||
if ( num_commands < 1 ) {
|
||||
clang_CompileCommands_dispose( commands );
|
||||
return path_to_directory;
|
||||
}
|
||||
|
||||
// We always pick the first command offered
|
||||
CXCompileCommand command = clang_CompileCommands_getCommand(
|
||||
commands,
|
||||
0);
|
||||
|
||||
path_to_directory = CXStringToString( clang_CompileCommand_getDirectory(
|
||||
command ) );
|
||||
|
||||
return path_to_directory;
|
||||
}
|
||||
|
||||
} // namespace YouCompleteMe
|
||||
|
49
cpp/ycm/ClangCompleter/CompilationDatabase.h
Normal file
49
cpp/ycm/ClangCompleter/CompilationDatabase.h
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2011, 2012 Strahinja Val Markovic <val@markovic.io>
|
||||
//
|
||||
// This file is part of YouCompleteMe.
|
||||
//
|
||||
// YouCompleteMe is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// YouCompleteMe is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef COMPILATIONDATABASE_H_ZT7MQXPG
|
||||
#define COMPILATIONDATABASE_H_ZT7MQXPG
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <boost/utility.hpp>
|
||||
#include <clang-c/CXCompilationDatabase.h>
|
||||
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
|
||||
class CompilationDatabase : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
CompilationDatabase( const std::string& path_to_directory );
|
||||
~CompilationDatabase();
|
||||
|
||||
bool DatabaseSuccessfullyLoaded();
|
||||
|
||||
std::vector< std::string > FlagsForFile( const std::string &path_to_file );
|
||||
|
||||
std::string CompileCommandWorkingDirectoryForFile(
|
||||
const std::string &path_to_file );
|
||||
|
||||
private:
|
||||
bool is_loaded_;
|
||||
CXCompilationDatabase compilation_database_;
|
||||
};
|
||||
|
||||
} // namespace YouCompleteMe
|
||||
|
||||
#endif /* end of include guard: COMPILATIONDATABASE_H_ZT7MQXPG */
|
@ -23,6 +23,7 @@
|
||||
# include "CompletionData.h"
|
||||
# include "Diagnostic.h"
|
||||
# include "UnsavedFile.h"
|
||||
# include "CompilationDatabase.h"
|
||||
#endif // USE_CLANG_COMPLETER
|
||||
|
||||
#include <boost/python.hpp>
|
||||
@ -88,8 +89,8 @@ BOOST_PYTHON_MODULE(ycm_core)
|
||||
return_value_policy< reference_existing_object >() ) )
|
||||
.def_readwrite( "length_", &UnsavedFile::length_ );
|
||||
|
||||
class_< std::vector< UnsavedFile > >( "UnsavedFileVec" )
|
||||
.def( vector_indexing_suite< std::vector< UnsavedFile > >() );
|
||||
class_< std::vector< UnsavedFile > >( "UnsavedFileVec" )
|
||||
.def( vector_indexing_suite< std::vector< UnsavedFile > >() );
|
||||
|
||||
class_< ClangCompleter, boost::noncopyable >( "ClangCompleter" )
|
||||
.def( "EnableThreading", &ClangCompleter::EnableThreading )
|
||||
@ -124,5 +125,13 @@ BOOST_PYTHON_MODULE(ycm_core)
|
||||
class_< std::vector< Diagnostic > >( "DiagnosticVec" )
|
||||
.def( vector_indexing_suite< std::vector< Diagnostic > >() );
|
||||
|
||||
class_< CompilationDatabase, boost::noncopyable >(
|
||||
"CompilationDatabase", init< std::string >() )
|
||||
.def( "FlagsForFile", &CompilationDatabase::FlagsForFile )
|
||||
.def( "DatabaseSuccessfullyLoaded",
|
||||
&CompilationDatabase::DatabaseSuccessfullyLoaded )
|
||||
.def( "CompileCommandWorkingDirectoryForFile",
|
||||
&CompilationDatabase::CompileCommandWorkingDirectoryForFile );
|
||||
|
||||
#endif // USE_CLANG_COMPLETER
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user