Browse Source

Added codecompletion comments, and some cleanup.

merge-requests/37/head
eidheim 11 years ago
parent
commit
eed0d35936
  1. 2
      src/CodeCompleteResults.cc
  2. 1
      src/CodeCompleteResults.h
  3. 10
      src/CompletionString.cc
  4. 1
      src/CompletionString.h
  5. 2
      src/Tokens.cc
  6. 2
      src/Tokens.h
  7. 55
      src/TranslationUnit.cc
  8. 5
      src/TranslationUnit.h

2
src/CodeCompleteResults.cc

@ -22,7 +22,7 @@ CodeCompleteResults(clang::TranslationUnit *tu,
column, column,
files.data(), files.data(),
files.size(), files.size(),
clang_defaultCodeCompleteOptions()); clang_defaultCodeCompleteOptions()|CXCodeComplete_IncludeBriefComments);
clang_sortCodeCompletionResults(results_->Results, results_->NumResults); clang_sortCodeCompletionResults(results_->Results, results_->NumResults);
} }

1
src/CodeCompleteResults.h

@ -13,6 +13,7 @@ namespace clang {
const std::map<std::string, std::string> &buffers, const std::map<std::string, std::string> &buffers,
int line_num, int line_num,
int column); int column);
~CodeCompleteResults() {clang_disposeCodeCompleteResults(results_);}
CompletionString get(int index); CompletionString get(int index);
int size(); int size();

10
src/CompletionString.cc

@ -26,6 +26,16 @@ get_chunks() {
return res; return res;
} }
std::string clang::CompletionString::get_brief_comments() {
std::string brief_comments;
auto cxstr=clang_getCompletionBriefComment(str_);
if(cxstr.data!=NULL) {
brief_comments=clang_getCString(cxstr);
clang_disposeString(cxstr);
}
return brief_comments;
}
clang::CompletionChunk:: clang::CompletionChunk::
CompletionChunk(std::string chunk, clang::CompletionChunkKind kind) : CompletionChunk(std::string chunk, clang::CompletionChunkKind kind) :
chunk_(chunk), kind_(kind) { } chunk_(chunk), kind_(kind) { }

1
src/CompletionString.h

@ -31,6 +31,7 @@ namespace clang {
class CompletionString { class CompletionString {
public: public:
std::vector<CompletionChunk> get_chunks(); std::vector<CompletionChunk> get_chunks();
std::string get_brief_comments();
int get_num_chunks(); int get_num_chunks();
private: private:
explicit CompletionString(const CXCompletionString &str); explicit CompletionString(const CXCompletionString &str);

2
src/Tokens.cc

@ -81,7 +81,7 @@ void clang::Tokens::update_types(clang::TranslationUnit *tu) {
} }
} }
std::string clang::Tokens::get_brief_comment(size_t cursor_id) { std::string clang::Tokens::get_brief_comments(size_t cursor_id) {
std::string comment_string; std::string comment_string;
auto referenced=clang_getCursorReferenced(clang_cursors[cursor_id]); auto referenced=clang_getCursorReferenced(clang_cursors[cursor_id]);
auto comment=clang_Cursor_getParsedComment(referenced); auto comment=clang_Cursor_getParsedComment(referenced);

2
src/Tokens.h

@ -10,7 +10,7 @@ namespace clang {
Tokens(TranslationUnit *tu, SourceRange *range); Tokens(TranslationUnit *tu, SourceRange *range);
~Tokens(); ~Tokens();
void update_types(clang::TranslationUnit *tu); void update_types(clang::TranslationUnit *tu);
std::string get_brief_comment(size_t cursor_id); std::string get_brief_comments(size_t cursor_id);
private: private:
CXToken *tokens_; CXToken *tokens_;
unsigned num_tokens_; unsigned num_tokens_;

55
src/TranslationUnit.cc

@ -1,6 +1,8 @@
#include "TranslationUnit.h" #include "TranslationUnit.h"
#include "SourceLocation.h" #include "SourceLocation.h"
#include "Tokens.h" #include "Tokens.h"
#include <fstream>
#include <sstream>
clang::TranslationUnit:: clang::TranslationUnit::
~TranslationUnit() { ~TranslationUnit() {
@ -17,27 +19,24 @@ clang::TranslationUnit::
TranslationUnit(Index *index, TranslationUnit(Index *index,
const std::string &filepath, const std::string &filepath,
const std::vector<std::string> &command_line_args) { const std::vector<std::string> &command_line_args) {
std::vector<const char*> args; std::map<std::string, std::string> buffers;
for(auto &a: command_line_args) { std::ifstream ifs(filepath, std::ifstream::in);
args.push_back(a.c_str()); std::stringstream ss;
} ss << ifs.rdbuf();
tu_ = clang_createTranslationUnitFromSourceFile(index->index_, buffers[filepath]=ss.str();
filepath.c_str(), parse(index, filepath, command_line_args, buffers);
args.size(),
args.data(),
0,
NULL);
} }
clang::TranslationUnit:: clang::TranslationUnit::
TranslationUnit(Index *index, TranslationUnit(Index *index,
const std::string &filepath) { const std::string &filepath) {
tu_ = clang_createTranslationUnitFromSourceFile(index->index_, std::vector<std::string> command_line_args;
filepath.c_str(), std::map<std::string, std::string> buffers;
0, std::ifstream ifs(filepath, std::ifstream::in);
NULL, std::stringstream ss;
0, ss << ifs.rdbuf();
NULL); buffers[filepath]=ss.str();
parse(index, filepath, command_line_args, buffers);
} }
clang::TranslationUnit:: clang::TranslationUnit::
@ -46,6 +45,14 @@ TranslationUnit(clang::Index *index,
const std::vector<std::string> &command_line_args, const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers, const std::map<std::string, std::string> &buffers,
unsigned flags) { unsigned flags) {
parse(index, filepath, command_line_args, buffers, flags);
}
void clang::TranslationUnit::parse(Index *index,
const std::string &filepath,
const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers,
unsigned flags) {
std::vector<CXUnsavedFile> files; std::vector<CXUnsavedFile> files;
for (auto &buffer : buffers) { for (auto &buffer : buffers) {
CXUnsavedFile file; CXUnsavedFile file;
@ -59,13 +66,13 @@ TranslationUnit(clang::Index *index,
args.push_back(a.c_str()); args.push_back(a.c_str());
} }
tu_ = tu_ =
clang_parseTranslationUnit(index->index_, clang_parseTranslationUnit(index->index_,
filepath.c_str(), filepath.c_str(),
args.data(), args.data(),
args.size(), args.size(),
files.data(), files.data(),
files.size(), files.size(),
flags); flags);
} }
int clang::TranslationUnit:: int clang::TranslationUnit::
@ -87,7 +94,7 @@ ReparseTranslationUnit(const std::string &file_path,
} }
unsigned clang::TranslationUnit::DefaultFlags() { unsigned clang::TranslationUnit::DefaultFlags() {
return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete; return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
} }
void clang::TranslationUnit::update_diagnostics() { void clang::TranslationUnit::update_diagnostics() {

5
src/TranslationUnit.h

@ -40,6 +40,11 @@ namespace clang {
std::vector<clang::Diagnostic> diagnostics; std::vector<clang::Diagnostic> diagnostics;
private: private:
void parse(Index *index,
const std::string &filepath,
const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers,
unsigned flags=DefaultFlags());
friend Token; friend Token;
friend Tokens; friend Tokens;
friend SourceLocation; friend SourceLocation;

Loading…
Cancel
Save