Role : uint8_t -> uint16_t; Add Read,Write to Role (#if CINDEX_VERSION >= 48)

Fix textDocument/documentSymbol
This commit is contained in:
Fangrui Song 2018-02-12 10:15:43 -08:00
parent 8a939389d8
commit de1e350c59
5 changed files with 48 additions and 19 deletions

View File

@ -66,24 +66,25 @@ enum class StorageClass : uint8_t {
};
MAKE_REFLECT_TYPE_PROXY(StorageClass);
enum class Role : uint8_t {
enum class Role : uint16_t {
None = 0,
Declaration = 1 << 0,
Definition = 1 << 1,
Reference = 1 << 2,
Implicit = 1 << 3,
ChildOf = 1 << 4,
BaseOf = 1 << 5,
Call = 1 << 6,
Read = 1 << 3,
Write = 1 << 4,
Call = 1 << 5,
Dynamic = 1 << 6,
Address = 1 << 7,
Implicit = 1 << 8,
};
MAKE_REFLECT_TYPE_PROXY(Role);
MAKE_ENUM_HASHABLE(Role);
inline uint8_t operator&(Role lhs, Role rhs) {
return uint8_t(lhs) & uint8_t(rhs);
inline uint16_t operator&(Role lhs, Role rhs) {
return uint16_t(lhs) & uint16_t(rhs);
}
inline Role operator|(Role lhs, Role rhs) {
return Role(uint8_t(lhs) | uint8_t(rhs));
return Role(uint16_t(lhs) | uint16_t(rhs));
}

View File

@ -21,6 +21,9 @@
#if CINDEX_VERSION >= 47
#define CINDEX_HAVE_PRETTY 1
#endif
#if CINDEX_VERSION >= 48
#define CINDEX_HAVE_ROLE 1
#endif
namespace {
@ -53,6 +56,14 @@ bool IsScopeSemanticContainer(CXCursorKind kind) {
}
}
Role GetRole(const CXIdxEntityRefInfo* ref_info, Role role) {
#if CINDEX_HAVE_ROLE
return static_cast<Role>(static_cast<int>(ref_info->role));
#else
return role;
#endif
}
SymbolKind GetSymbolKind(CXCursorKind kind) {
switch (kind) {
default:
@ -1999,7 +2010,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
var->def.kind = ClangSymbolKind::Parameter;
}
}
UniqueAddUse(db, var->uses, loc, fromContainer(ref->container), Role::Reference);
UniqueAddUse(db, var->uses, loc, fromContainer(ref->container), GetRole(ref, Role::Reference));
break;
}
@ -2056,7 +2067,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
OnIndexReference_Function(
db, loc, ref->container->cursor, called_id,
Role::Call |
GetRole(ref, Role::Call) |
(is_implicit ? Role::Implicit : Role::None));
// Checks if |str| starts with |start|. Ignores case.

View File

@ -30,8 +30,10 @@ struct TextDocumentDocumentSymbolHandler
out.id = request->id;
QueryFile* file;
QueryFileId file_id;
if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) {
request->params.textDocument.uri.GetPath(), &file,
&file_id)) {
return;
}
@ -41,7 +43,10 @@ struct TextDocumentDocumentSymbolHandler
if (!info)
continue;
optional<lsLocation> location = GetLsLocation(db, working_files, sym);
// FIXME
Use use(sym);
use.file = file_id;
optional<lsLocation> location = GetLsLocation(db, working_files, use);
if (!location)
continue;
info->location = *location;

View File

@ -25,12 +25,21 @@ void Reflect(Writer& visitor, uint8_t& value) {
visitor.Int(value);
}
void Reflect(Reader& visitor, int16_t& value) {
void Reflect(Reader& visitor, short& value) {
if (!visitor.IsInt())
throw std::invalid_argument("int16_t");
value = (int16_t)visitor.GetInt();
throw std::invalid_argument("short");
value = (short)visitor.GetInt();
}
void Reflect(Writer& visitor, int16_t& value) {
void Reflect(Writer& visitor, short& value) {
visitor.Int(value);
}
void Reflect(Reader& visitor, unsigned short& value) {
if (!visitor.IsInt())
throw std::invalid_argument("unsigned short");
value = (unsigned short)visitor.GetInt();
}
void Reflect(Writer& visitor, unsigned short& value) {
visitor.Int(value);
}

View File

@ -128,8 +128,11 @@ struct IndexFile;
void Reflect(Reader& visitor, uint8_t& value);
void Reflect(Writer& visitor, uint8_t& value);
void Reflect(Reader& visitor, int16_t& value);
void Reflect(Writer& visitor, int16_t& value);
void Reflect(Reader& visitor, short& value);
void Reflect(Writer& visitor, short& value);
void Reflect(Reader& visitor, unsigned short& value);
void Reflect(Writer& visitor, unsigned short& value);
void Reflect(Reader& visitor, int& value);
void Reflect(Writer& visitor, int& value);