Browse Source

Added get_usr to completion results, and get_spelling to cursor.

merge-requests/37/head
eidheim 10 years ago
parent
commit
2aab9cd898
  1. 15
      src/CodeCompleteResults.cc
  2. 6
      src/CodeCompleteResults.h
  3. 4
      src/Cursor.cc
  4. 1
      src/Cursor.h
  5. 1
      src/Token.cc

15
src/CodeCompleteResults.cc

@ -1,9 +1,10 @@
#include "CodeCompleteResults.h" #include "CodeCompleteResults.h"
#include "CompletionString.h" #include "CompletionString.h"
#include <exception> #include <exception>
#include "Utility.h"
clang::CodeCompleteResults:: clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu,
CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &file_name, const std::string &file_name,
const std::map<std::string, std::string> &buffers, const std::map<std::string, std::string> &buffers,
unsigned line_num, unsigned column) { unsigned line_num, unsigned column) {
std::vector<CXUnsavedFile> files; std::vector<CXUnsavedFile> files;
@ -29,17 +30,19 @@ clang::CodeCompleteResults::~CodeCompleteResults() {
clang_disposeCodeCompleteResults(cx_results); clang_disposeCodeCompleteResults(cx_results);
} }
unsigned clang::CodeCompleteResults:: unsigned clang::CodeCompleteResults::size() const {
size() {
if(cx_results==NULL) if(cx_results==NULL)
return 0; return 0;
return cx_results->NumResults; return cx_results->NumResults;
} }
clang::CompletionString clang::CodeCompleteResults:: clang::CompletionString clang::CodeCompleteResults::get(unsigned i) const {
get(unsigned i) {
if (i >= size()) { if (i >= size()) {
throw std::invalid_argument("clang::CodeCompleteResults::get(unsigned i): i>=size()"); throw std::invalid_argument("clang::CodeCompleteResults::get(unsigned i): i>=size()");
} }
return CompletionString(cx_results->Results[i].CompletionString); return CompletionString(cx_results->Results[i].CompletionString);
} }
std::string clang::CodeCompleteResults::get_usr() const {
return clang::to_string(clang_codeCompleteGetContainerUSR(cx_results));
}

6
src/CodeCompleteResults.h

@ -2,6 +2,7 @@
#define CODECOMPLETERESULTS_H_ #define CODECOMPLETERESULTS_H_
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include <map> #include <map>
#include <string>
#include "CompletionString.h" #include "CompletionString.h"
namespace clang { namespace clang {
@ -12,8 +13,9 @@ namespace clang {
unsigned line_num, unsigned column); unsigned line_num, unsigned column);
public: public:
~CodeCompleteResults(); ~CodeCompleteResults();
CompletionString get(unsigned index); CompletionString get(unsigned index) const;
unsigned size(); unsigned size() const;
std::string get_usr() const;
CXCodeCompleteResults *cx_results; CXCodeCompleteResults *cx_results;
}; };

4
src/Cursor.cc

@ -13,6 +13,10 @@ clang::SourceRange clang::Cursor::get_source_range() const {
return SourceRange(clang_getCursorExtent(cx_cursor)); return SourceRange(clang_getCursorExtent(cx_cursor));
} }
std::string clang::Cursor::get_spelling() const {
return clang::to_string(clang_getCursorSpelling(cx_cursor));
}
std::string clang::Cursor::get_usr() const { std::string clang::Cursor::get_usr() const {
return clang::to_string(clang_getCursorUSR(cx_cursor)); return clang::to_string(clang_getCursorUSR(cx_cursor));
} }

1
src/Cursor.h

@ -180,6 +180,7 @@ namespace clang {
const CursorKind get_kind(); const CursorKind get_kind();
SourceLocation get_source_location() const; SourceLocation get_source_location() const;
SourceRange get_source_range() const; SourceRange get_source_range() const;
std::string get_spelling() const;
std::string get_usr() const; std::string get_usr() const;
Cursor get_referenced() const; Cursor get_referenced() const;
operator bool() const; operator bool() const;

1
src/Token.cc

@ -34,6 +34,7 @@ bool clang::Token::has_type() {
return spelling!=""; return spelling!="";
} }
//TODO: Move to clang::Cursor
std::string clang::Token::get_type() { std::string clang::Token::get_type() {
std::string spelling; std::string spelling;
auto referenced=clang_getCursorReferenced(cx_cursor); auto referenced=clang_getCursorReferenced(cx_cursor);

Loading…
Cancel
Save