Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/CodeCompleteResults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
#include "Utility.h"

clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu,
const std::string &buffer,
unsigned line_num, unsigned column) {
CXUnsavedFile files[1];
auto file_path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu));
files[0].Filename = file_path.c_str();
files[0].Contents = buffer.c_str();
files[0].Length = buffer.size();

cx_results = clang_codeCompleteAt(cx_tu,
file_path.c_str(),
line_num,
column,
files,
1,
clang_defaultCodeCompleteOptions()|CXCodeComplete_IncludeBriefComments);
if(cx_results!=NULL)
clang_sortCodeCompletionResults(cx_results->Results, cx_results->NumResults);
}

clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu,
const std::string &file_name,
const std::map<std::string, std::string> &buffers,
unsigned line_num, unsigned column) {
Expand Down
6 changes: 5 additions & 1 deletion src/CodeCompleteResults.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
namespace clang {
class CodeCompleteResults {
friend class TranslationUnit;
CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &file_name,

CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &buffer,
unsigned line_num, unsigned column);
//TODO: remove
CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &file_path,
const std::map<std::string, std::string> &buffers,
unsigned line_num, unsigned column);
public:
Expand Down
35 changes: 35 additions & 0 deletions src/TranslationUnit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_pa
parse(index, file_path, command_line_args, buffers);
}

clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path,
const std::vector<std::string> &command_line_args,
const std::string &buffer, unsigned flags) {
std::vector<const char*> args;
for(auto &a: command_line_args) {
args.push_back(a.c_str());
}

CXUnsavedFile files[1];
files[0].Filename=file_path.c_str();
files[0].Contents=buffer.c_str();
files[0].Length=buffer.size();

cx_tu = clang_parseTranslationUnit(index.cx_index, file_path.c_str(), args.data(),
args.size(), files, 1, flags);
}

clang::TranslationUnit::TranslationUnit(clang::Index &index, const std::string &file_path,
const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers, unsigned flags) {
Expand All @@ -58,6 +75,18 @@ void clang::TranslationUnit::parse(Index &index, const std::string &file_path,
args.size(), files.data(), files.size(), flags);
}

int clang::TranslationUnit::ReparseTranslationUnit(const std::string &buffer, unsigned flags) {
CXUnsavedFile files[1];

auto file_path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu));

files[0].Filename=file_path.c_str();
files[0].Contents=buffer.c_str();
files[0].Length=buffer.size();

return clang_reparseTranslationUnit(cx_tu, 1, files, flags);
}

int clang::TranslationUnit::ReparseTranslationUnit(const std::map<std::string, std::string> &buffers, unsigned flags) {
std::vector<CXUnsavedFile> files;
for (auto &buffer : buffers) {
Expand All @@ -74,6 +103,12 @@ unsigned clang::TranslationUnit::DefaultFlags() {
return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
}

clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const std::string &buffer,
unsigned line_number, unsigned column) {
clang::CodeCompleteResults results(cx_tu, buffer, line_number, column);
return results;
}

clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const std::map<std::string, std::string> &buffers,
unsigned line_number, unsigned column) {
auto path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu));
Expand Down
18 changes: 16 additions & 2 deletions src/TranslationUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,41 @@
namespace clang {
class TranslationUnit {
public:
//TODO: remove
TranslationUnit(Index &index,
const std::string &file_path,
const std::vector<std::string> &command_line_args);
TranslationUnit(Index &index,
const std::string &file_path,
const std::vector<std::string> &command_line_args,
const std::string &buffer,
unsigned flags=DefaultFlags());
//TODO: remove
TranslationUnit(Index &index,
const std::string &file_path,
const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers,
unsigned flags=DefaultFlags());
TranslationUnit(Index &index, const std::string &file_path);
~TranslationUnit();

int ReparseTranslationUnit(const std::string &buffer, unsigned flags=DefaultFlags());
//TODO: remove
int ReparseTranslationUnit(const std::map<std::string, std::string> &buffers,
unsigned flags=DefaultFlags());

static unsigned DefaultFlags();

void parse(Index &index,
const std::string &file_path,
const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers,
unsigned flags=DefaultFlags());

clang::CodeCompleteResults get_code_completions(const std::map<std::string, std::string> &buffers,

clang::CodeCompleteResults get_code_completions(const std::string &buffer,
unsigned line_number, unsigned column);
//TODO: remove
clang::CodeCompleteResults get_code_completions(const std::map<std::string, std::string> &buffers,
unsigned line_number, unsigned column);

std::vector<clang::Diagnostic> get_diagnostics();
Expand Down