Serialize {type,func}->def.kind for semantic highlighting

This commit is contained in:
Fangrui Song 2018-01-07 08:43:53 -08:00
parent 6661410483
commit 332a3b5240
3 changed files with 57 additions and 25 deletions

View File

@ -47,32 +47,61 @@ bool IsScopeSemanticContainer(CXCursorKind kind) {
}
}
// Inverse of libclang/CXIndexDataConsumer.cpp getEntityKindFromSymbolKind
ClangSymbolKind GetSymbolKind(CXIdxEntityKind kind) {
switch (kind) {
default:
return ClangSymbolKind::Unknown;
case CXIdxEntity_CXXConstructor:
return ClangSymbolKind::Constructor;
case CXIdxEntity_CXXDestructor:
return ClangSymbolKind::Destructor;
case CXIdxEntity_CXXStaticMethod:
case CXIdxEntity_ObjCClassMethod:
return ClangSymbolKind::StaticMethod;
case CXIdxEntity_CXXInstanceMethod:
case CXIdxEntity_ObjCInstanceMethod:
return ClangSymbolKind::InstanceMethod;
case CXIdxEntity_Function:
return ClangSymbolKind::Function;
case CXIdxEntity_Enum:
return ClangSymbolKind::Enum;
case CXIdxEntity_CXXClass:
case CXIdxEntity_ObjCClass:
return ClangSymbolKind::Class;
case CXIdxEntity_Struct:
return ClangSymbolKind::Struct;
case CXIdxEntity_Union:
return ClangSymbolKind::Union;
case CXIdxEntity_CXXTypeAlias:
case CXIdxEntity_Typedef:
return ClangSymbolKind::TypeAlias;
case CXIdxEntity_Function:
return ClangSymbolKind::Function;
case CXIdxEntity_Variable:
// Can also be Parameter
return ClangSymbolKind::Variable;
case CXIdxEntity_Field:
case CXIdxEntity_ObjCIvar:
return ClangSymbolKind::Field;
case CXIdxEntity_EnumConstant:
return ClangSymbolKind::EnumConstant;
case CXIdxEntity_CXXClass:
case CXIdxEntity_ObjCClass:
return ClangSymbolKind::Class;
case CXIdxEntity_CXXInterface:
case CXIdxEntity_ObjCProtocol:
return ClangSymbolKind::Protocol;
case CXIdxEntity_ObjCCategory:
return ClangSymbolKind::Extension;
case CXIdxEntity_CXXInstanceMethod:
case CXIdxEntity_ObjCInstanceMethod:
return ClangSymbolKind::InstanceMethod;
case CXIdxEntity_ObjCClassMethod:
return ClangSymbolKind::ClassMethod;
case CXIdxEntity_CXXStaticMethod:
return ClangSymbolKind::StaticMethod;
case CXIdxEntity_ObjCProperty:
return ClangSymbolKind::InstanceProperty;
case CXIdxEntity_CXXStaticVariable:
return ClangSymbolKind::StaticProperty;
case CXIdxEntity_CXXNamespace:
return ClangSymbolKind::Namespace;
case CXIdxEntity_CXXNamespaceAlias:
return ClangSymbolKind::NamespaceAlias;
case CXIdxEntity_CXXConstructor:
return ClangSymbolKind::Constructor;
case CXIdxEntity_CXXDestructor:
return ClangSymbolKind::Destructor;
case CXIdxEntity_CXXConversionFunction:
return ClangSymbolKind::ConversionFunction;
}
}
@ -437,7 +466,7 @@ void OnIndexReference_Function(IndexFile* db,
} // namespace
// static
int IndexFile::kCurrentVersion = 7;
int IndexFile::kCurrentVersion = 8;
IndexFile::IndexFile(const std::string& path) : id_cache(path), path(path) {
// TODO: Reconsider if we should still be reusing the same id_cache.
@ -1244,12 +1273,10 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
!decl->isRedeclaration, db, param);
// FIXME https://github.com/jacobdufault/cquery/issues/239
if (IsGlobalContainer(decl->semanticContainer))
var->def.kind = ClangSymbolKind::Module;
else if (IsTypeDefinition(decl->semanticContainer))
var->def.kind = ClangSymbolKind::Field;
else
var->def.kind = ClangSymbolKind::Variable;
var->def.kind = GetSymbolKind(decl->entityInfo->kind);
if (var->def.kind == ClangSymbolKind::Variable &&
decl->cursor.kind == CXCursor_ParmDecl)
var->def.kind = ClangSymbolKind::Parameter;
//}
if (decl->isDefinition) {
@ -1468,7 +1495,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
type->def.short_name = decl->entityInfo->name;
type->def.detailed_name =
ns->QualifiedName(decl->semanticContainer, type->def.short_name);
type->def.kind = ClangSymbolKind::TypeAlias;
type->def.kind = GetSymbolKind(decl->entityInfo->kind);
type->def.comments = decl_cursor.get_comments();

View File

@ -128,10 +128,13 @@ void EmitSemanticHighlighting(QueryDatabase* db,
if (!var->def)
continue; // applies to for loop
switch (var->def->kind) {
// TODO
case ClangSymbolKind::EnumConstant:
case ClangSymbolKind::Field:
case ClangSymbolKind::Macro:
case ClangSymbolKind::Module:
case ClangSymbolKind::Parameter:
case ClangSymbolKind::StaticProperty:
case ClangSymbolKind::Variable:
break;
default:

View File

@ -99,11 +99,12 @@ void Reflect(Writer& visitor, IndexInclude& value) {
template <typename TVisitor>
void Reflect(TVisitor& visitor, IndexType& value) {
REFLECT_MEMBER_START(16);
REFLECT_MEMBER_START(17);
REFLECT_MEMBER2("id", value.id);
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("hover", value.def.hover);
REFLECT_MEMBER2("comments", value.def.comments);
REFLECT_MEMBER2("definition_spelling", value.def.definition_spelling);
@ -121,12 +122,13 @@ void Reflect(TVisitor& visitor, IndexType& value) {
template <typename TVisitor>
void Reflect(TVisitor& visitor, IndexFunc& value) {
REFLECT_MEMBER_START(16);
REFLECT_MEMBER_START(17);
REFLECT_MEMBER2("id", value.id);
REFLECT_MEMBER2("is_operator", value.def.is_operator);
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("hover", value.def.hover);
REFLECT_MEMBER2("comments", value.def.comments);
REFLECT_MEMBER2("declarations", value.declarations);