Serialize VarDefDefinitionData::{parent_kind,parent_id}

This commit is contained in:
Fangrui Song 2018-01-28 12:34:31 -08:00
parent 79b60561d1
commit bdb880e0a5
7 changed files with 50 additions and 41 deletions

View File

@ -566,7 +566,7 @@ void OnIndexReference_Function(IndexFile* db,
// static
const int IndexFile::kMajorVersion = 10;
const int IndexFile::kMinorVersion = 0;
const int IndexFile::kMinorVersion = 1;
IndexFile::IndexFile(const std::string& path,
const optional<std::string>& contents)
@ -1455,13 +1455,13 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
if (IsFunctionCallContext(decl->semanticContainer->cursor.kind)) {
IndexFuncId parent_func_id =
db->ToFuncId(decl->semanticContainer->cursor);
var->def.semantic_parent_kind = SymbolKind::Func;
var->def.semantic_parent_id = size_t(parent_func_id);
var->def.parent_kind = SymbolKind::Func;
var->def.parent_id = size_t(parent_func_id);
} else if (IsTypeDefinition(decl->semanticContainer)) {
IndexTypeId parent_type_id =
db->ToTypeId(decl->semanticContainer->cursor);
var->def.semantic_parent_kind = SymbolKind::Type;
var->def.semantic_parent_id = size_t(parent_type_id);
var->def.parent_kind = SymbolKind::Type;
var->def.parent_id = size_t(parent_type_id);
db->Resolve(parent_type_id)->def.vars.push_back(var_id);
}
}

View File

@ -385,8 +385,8 @@ struct VarDefDefinitionData {
optional<TypeId> variable_type;
// Function/type which declares this one.
size_t semantic_parent_id = size_t(-1);
SymbolKind semantic_parent_kind = SymbolKind::Invalid;
size_t parent_id = size_t(-1);
SymbolKind parent_kind = SymbolKind::Invalid;
ClangSymbolKind kind = ClangSymbolKind::Unknown;
// Note a variable may have instances of both |None| and |Extern|
@ -423,13 +423,15 @@ void Reflect(TVisitor& visitor,
REFLECT_MEMBER_START();
REFLECT_MEMBER(short_name);
REFLECT_MEMBER(detailed_name);
REFLECT_MEMBER(kind);
REFLECT_MEMBER(storage);
REFLECT_MEMBER(hover);
REFLECT_MEMBER(comments);
REFLECT_MEMBER(definition_spelling);
REFLECT_MEMBER(definition_extent);
REFLECT_MEMBER(variable_type);
REFLECT_MEMBER(parent_id);
REFLECT_MEMBER(parent_kind);
REFLECT_MEMBER(kind);
REFLECT_MEMBER(storage);
REFLECT_MEMBER_END();
}

View File

@ -1080,34 +1080,6 @@ struct Out_CquerySetInactiveRegion
MAKE_REFLECT_STRUCT(Out_CquerySetInactiveRegion::Params, uri, inactiveRegions);
MAKE_REFLECT_STRUCT(Out_CquerySetInactiveRegion, jsonrpc, method, params);
struct Out_CqueryPublishSemanticHighlighting
: public lsOutMessage<Out_CqueryPublishSemanticHighlighting> {
struct Symbol {
int stableId = 0;
ClangSymbolKind kind;
StorageClass storage;
std::vector<lsRange> ranges;
};
struct Params {
lsDocumentUri uri;
std::vector<Symbol> symbols;
};
std::string method = "$cquery/publishSemanticHighlighting";
Params params;
};
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Symbol,
kind,
storage,
stableId,
ranges);
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Params,
uri,
symbols);
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting,
jsonrpc,
method,
params);
struct Out_LocationList : public lsOutMessage<Out_LocationList> {
lsRequestId id;
std::vector<lsLocation> result;

View File

@ -111,6 +111,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
grouped_symbols;
for (SymbolRef sym : file->def->all_symbols) {
std::string detailed_name;
SymbolKind parent_kind = SymbolKind::Invalid;
ClangSymbolKind kind = ClangSymbolKind::Unknown;
StorageClass storage = StorageClass::Invalid;
// This switch statement also filters out symbols that are not highlighted.
@ -146,6 +147,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
QueryVar* var = &db->vars[sym.idx.idx];
if (!var->def)
continue; // applies to for loop
parent_kind = var->def->parent_kind;
kind = var->def->kind;
storage = var->def->storage;
detailed_name = var->def->short_name;
@ -172,6 +174,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
Out_CqueryPublishSemanticHighlighting::Symbol symbol;
symbol.stableId =
semantic_cache_for_file->GetStableId(sym.idx.kind, detailed_name);
symbol.parentKind = parent_kind;
symbol.kind = kind;
symbol.storage = storage;
symbol.ranges.push_back(*loc);

View File

@ -24,6 +24,36 @@ struct TimestampManager;
struct WorkingFile;
struct WorkingFiles;
struct Out_CqueryPublishSemanticHighlighting
: public lsOutMessage<Out_CqueryPublishSemanticHighlighting> {
struct Symbol {
int stableId = 0;
SymbolKind parentKind;
ClangSymbolKind kind;
StorageClass storage;
std::vector<lsRange> ranges;
};
struct Params {
lsDocumentUri uri;
std::vector<Symbol> symbols;
};
std::string method = "$cquery/publishSemanticHighlighting";
Params params;
};
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Symbol,
stableId,
parentKind,
kind,
storage,
ranges);
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Params,
uri,
symbols);
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting,
jsonrpc,
method,
params);
// Usage:
//
// struct FooHandler : MessageHandler {

View File

@ -84,8 +84,8 @@ optional<QueryVar::Def> ToQuery(const IdMap& id_map, const IndexVar::Def& var) {
result.definition_spelling = id_map.ToQuery(var.definition_spelling);
result.definition_extent = id_map.ToQuery(var.definition_extent);
result.variable_type = id_map.ToQuery(var.variable_type);
result.semantic_parent_id = var.semantic_parent_id;
result.semantic_parent_kind = var.semantic_parent_kind;
result.parent_id = var.parent_id;
result.parent_kind = var.parent_kind;
result.kind = var.kind;
result.storage = var.storage;
return result;

View File

@ -185,8 +185,6 @@ void Reflect(TVisitor& visitor, IndexVar& value) {
REFLECT_MEMBER2("usr", value.usr);
REFLECT_MEMBER2("short_name", value.def.short_name);
REFLECT_MEMBER2("detailed_name", value.def.detailed_name);
REFLECT_MEMBER2("kind", value.def.kind);
REFLECT_MEMBER2("storage", value.def.storage);
REFLECT_MEMBER2("hover", value.def.hover);
REFLECT_MEMBER2("comments", value.def.comments);
REFLECT_MEMBER2("declarations", value.declarations);
@ -194,6 +192,10 @@ void Reflect(TVisitor& visitor, IndexVar& value) {
REFLECT_MEMBER2("definition_extent", value.def.definition_extent);
REFLECT_MEMBER2("variable_type", value.def.variable_type);
REFLECT_MEMBER2("uses", value.uses);
REFLECT_MEMBER2("parent_id", value.def.parent_id);
REFLECT_MEMBER2("parent_kind", value.def.parent_kind);
REFLECT_MEMBER2("kind", value.def.kind);
REFLECT_MEMBER2("storage", value.def.storage);
REFLECT_MEMBER_END();
}