Remove ClangSymbolKind in favor of lsSymbolKind

This commit is contained in:
Fangrui Song 2018-02-18 11:29:38 -08:00
parent f3134d564c
commit 58d6547411
7 changed files with 61 additions and 125 deletions

View File

@ -89,60 +89,59 @@ SymbolKind GetSymbolKind(CXCursorKind kind) {
}
// Inverse of libclang/CXIndexDataConsumer.cpp getEntityKindFromSymbolKind
ClangSymbolKind GetSymbolKind(CXIdxEntityKind kind) {
lsSymbolKind GetSymbolKind(CXIdxEntityKind kind) {
switch (kind) {
default:
return ClangSymbolKind::Unknown;
return lsSymbolKind::Unknown;
case CXIdxEntity_Enum:
return ClangSymbolKind::Enum;
return lsSymbolKind::Enum;
case CXIdxEntity_Struct:
return ClangSymbolKind::Struct;
case CXIdxEntity_Union:
return ClangSymbolKind::Union;
return lsSymbolKind::Struct;
case CXIdxEntity_CXXTypeAlias:
case CXIdxEntity_Typedef:
return ClangSymbolKind::TypeAlias;
return lsSymbolKind::TypeParameter;
case CXIdxEntity_Function:
return ClangSymbolKind::Function;
return lsSymbolKind::Function;
case CXIdxEntity_Variable:
// Can also be Parameter
return ClangSymbolKind::Variable;
return lsSymbolKind::Variable;
case CXIdxEntity_Field:
case CXIdxEntity_ObjCIvar:
return ClangSymbolKind::Field;
return lsSymbolKind::Field;
case CXIdxEntity_EnumConstant:
return ClangSymbolKind::EnumConstant;
return lsSymbolKind::EnumMember;
case CXIdxEntity_CXXClass:
case CXIdxEntity_ObjCClass:
return ClangSymbolKind::Class;
return lsSymbolKind::Class;
case CXIdxEntity_CXXInterface:
case CXIdxEntity_ObjCProtocol:
return ClangSymbolKind::Protocol;
return lsSymbolKind::Interface;
case CXIdxEntity_ObjCCategory:
return ClangSymbolKind::Extension;
return lsSymbolKind::Interface;
case CXIdxEntity_CXXInstanceMethod:
case CXIdxEntity_ObjCInstanceMethod:
return ClangSymbolKind::InstanceMethod;
return lsSymbolKind::Method;
case CXIdxEntity_ObjCClassMethod:
return ClangSymbolKind::ClassMethod;
return lsSymbolKind::Method;
case CXIdxEntity_CXXStaticMethod:
return ClangSymbolKind::StaticMethod;
return lsSymbolKind::Method;
case CXIdxEntity_ObjCProperty:
return ClangSymbolKind::InstanceProperty;
return lsSymbolKind::Property;
case CXIdxEntity_CXXStaticVariable:
return ClangSymbolKind::StaticProperty;
return lsSymbolKind::Field;
case CXIdxEntity_CXXNamespace:
return ClangSymbolKind::Namespace;
return lsSymbolKind::Namespace;
case CXIdxEntity_CXXNamespaceAlias:
return ClangSymbolKind::NamespaceAlias;
return lsSymbolKind::Namespace;
case CXIdxEntity_CXXConstructor:
return ClangSymbolKind::Constructor;
return lsSymbolKind::Constructor;
case CXIdxEntity_CXXDestructor:
return ClangSymbolKind::Destructor;
return lsSymbolKind::Method;
case CXIdxEntity_CXXConversionFunction:
return ClangSymbolKind::ConversionFunction;
return lsSymbolKind::Constructor;
}
}
@ -448,39 +447,33 @@ std::string GetDocumentContentInRange(CXTranslationUnit cx_tu,
void SetUsePreflight(IndexFile* db, ClangCursor parent) {
switch (GetSymbolKind(parent.get_kind())) {
case SymbolKind::Func: {
case SymbolKind::Func:
(void)db->ToFuncId(parent.cx_cursor);
break;
}
case SymbolKind::Type: {
case SymbolKind::Type:
(void)db->ToTypeId(parent.cx_cursor);
break;
}
case SymbolKind::Var: {
case SymbolKind::Var:
(void)db->ToVarId(parent.cx_cursor);
break;
default:
break;
}
}
}
// |parent| should be resolved before using |SetUsePreflight| so that |def| will
// not be invalidated by |To{Func,Type,Var}Id|.
Use SetUse(IndexFile* db, Range range, ClangCursor parent, Role role) {
switch (GetSymbolKind(parent.get_kind())) {
case SymbolKind::Func: {
IndexFuncId id = db->ToFuncId(parent.cx_cursor);
return Use(range, id, SymbolKind::Func, Role::Definition, {});
}
case SymbolKind::Type: {
IndexTypeId id = db->ToTypeId(parent.cx_cursor);
return Use(range, id, SymbolKind::Type, Role::Definition, {});
}
case SymbolKind::Var: {
IndexVarId id = db->ToVarId(parent.cx_cursor);
return Use(range, id, SymbolKind::Var, Role::Definition, {});
}
case SymbolKind::Func:
return Use(range, db->ToFuncId(parent.cx_cursor), SymbolKind::Func, role,
{});
case SymbolKind::Type:
return Use(range, db->ToTypeId(parent.cx_cursor), SymbolKind::Type, role,
{});
case SymbolKind::Var:
return Use(range, db->ToVarId(parent.cx_cursor), SymbolKind::Var, role,
{});
default:
return Use(range, Id<void>(), SymbolKind::File, role, {});
}
@ -1237,7 +1230,7 @@ ClangCursor::VisitResult VisitMacroDefinitionAndExpansions(ClangCursor cursor,
int16_t(strlen(var_def->def.detailed_name.c_str()));
var_def->def.hover =
"#define " + GetDocumentContentInRange(param->tu->cx_tu, cx_extent);
var_def->def.kind = ClangSymbolKind::Macro;
var_def->def.kind = lsSymbolKind::Macro;
var_def->def.comments = cursor.get_comments();
var_def->def.spell =
SetUse(db, decl_loc_spelling, parent, Role::Definition);
@ -1288,7 +1281,7 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
ref_var->def.extent =
SetUse(db, ref_cursor.get_extent(), lex_parent, Role::None);
ref_var = db->Resolve(ref_var_id);
ref_var->def.kind = ClangSymbolKind::Parameter;
ref_var->def.kind = lsSymbolKind::Parameter;
SetVarDetail(ref_var, ref_cursor.get_spell_name(), ref_cursor,
nullptr, true, db, param);
@ -1356,7 +1349,7 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
ref_type->def.short_name_offset = 0;
ref_type->def.short_name_size =
int16_t(strlen(ref_type->def.detailed_name.c_str()));
ref_type->def.kind = ClangSymbolKind::Parameter;
ref_type->def.kind = lsSymbolKind::TypeParameter;
}
UniqueAddUseSpell(db, ref_type->uses, cursor);
}
@ -1390,7 +1383,7 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
ref_type->def.short_name_offset = 0;
ref_type->def.short_name_size =
int16_t(strlen(ref_type->def.detailed_name.c_str()));
ref_type->def.kind = ClangSymbolKind::Parameter;
ref_type->def.kind = lsSymbolKind::TypeParameter;
}
UniqueAddUseSpell(db, ref_type->uses, cursor);
}
@ -1552,9 +1545,9 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
// FIXME https://github.com/jacobdufault/cquery/issues/239
var->def.kind = GetSymbolKind(decl->entityInfo->kind);
if (var->def.kind == ClangSymbolKind::Variable &&
if (var->def.kind == lsSymbolKind::Variable &&
decl->cursor.kind == CXCursor_ParmDecl)
var->def.kind = ClangSymbolKind::Parameter;
var->def.kind = lsSymbolKind::Parameter;
//}
if (decl->isDefinition) {
@ -2022,7 +2015,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
// and has more information, thus not easy to reuse the code.
SetVarDetail(var, referenced.get_spell_name(), referenced, nullptr,
true, db, param);
var->def.kind = ClangSymbolKind::Parameter;
var->def.kind = lsSymbolKind::Parameter;
}
}
UniqueAddUse(db, var->uses, loc, fromContainer(ref->container), GetRole(ref, Role::Reference));

View File

@ -187,7 +187,7 @@ struct TypeDefDefinitionData {
int16_t short_name_offset = 0;
int16_t short_name_size = 0;
ClangSymbolKind kind = ClangSymbolKind::Unknown;
lsSymbolKind kind = lsSymbolKind::Unknown;
bool operator==(const TypeDefDefinitionData& o) const {
return detailed_name == o.detailed_name &&
@ -274,7 +274,7 @@ struct FuncDefDefinitionData {
Maybe<typename F::TypeId> declaring_type;
int16_t short_name_offset = 0;
int16_t short_name_size = 0;
ClangSymbolKind kind = ClangSymbolKind::Unknown;
lsSymbolKind kind = lsSymbolKind::Unknown;
StorageClass storage = StorageClass::Invalid;
bool operator==(const FuncDefDefinitionData& o) const {
@ -372,16 +372,15 @@ struct VarDefDefinitionData {
int16_t short_name_offset = 0;
int16_t short_name_size = 0;
ClangSymbolKind kind = ClangSymbolKind::Unknown;
lsSymbolKind kind = lsSymbolKind::Unknown;
// Note a variable may have instances of both |None| and |Extern|
// (declaration).
StorageClass storage = StorageClass::Invalid;
bool is_local() const {
return kind == ClangSymbolKind::Parameter ||
kind == ClangSymbolKind::Variable;
return kind == lsSymbolKind::Variable;
}
bool is_macro() const { return kind == ClangSymbolKind::Macro; }
bool is_macro() const { return kind == lsSymbolKind::Macro; }
bool operator==(const VarDefDefinitionData& o) const {
return detailed_name == o.detailed_name && spell == o.spell &&

View File

@ -112,7 +112,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
for (SymbolRef sym : file->def->all_symbols) {
std::string_view detailed_name;
SymbolKind parent_kind = SymbolKind::Invalid;
ClangSymbolKind kind = ClangSymbolKind::Unknown;
lsSymbolKind kind = lsSymbolKind::Unknown;
StorageClass storage = StorageClass::Invalid;
// This switch statement also filters out symbols that are not highlighted.
switch (sym.kind) {

View File

@ -29,7 +29,7 @@ struct Out_CqueryPublishSemanticHighlighting
struct Symbol {
int stableId = 0;
SymbolKind parentKind;
ClangSymbolKind kind;
lsSymbolKind kind;
StorageClass storage;
std::vector<lsRange> ranges;
};

View File

@ -155,7 +155,7 @@ struct TextDocumentCodeLensHandler
case SymbolKind::Type: {
QueryType& type = db->GetType(sym);
const QueryType::Def* def = type.AnyDef();
if (!def || def->kind == ClangSymbolKind::Namespace)
if (!def || def->kind == lsSymbolKind::Namespace)
continue;
AddCodeLens("ref", "refs", &common, OffsetStartColumn(use, 0),
type.uses, true /*force_display*/);

View File

@ -459,17 +459,9 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
info.name = def->ShortName();
else
info.name = def->detailed_name;
info.kind = def->kind;
if (def->detailed_name.c_str() != def->ShortName())
info.containerName = def->detailed_name;
// TODO ClangSymbolKind -> lsSymbolKind
switch (def->kind) {
default:
info.kind = lsSymbolKind::Class;
break;
case ClangSymbolKind::Namespace:
info.kind = lsSymbolKind::Namespace;
break;
}
return info;
}
case SymbolKind::Func: {
@ -482,16 +474,8 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
info.name = def->ShortName();
else
info.name = def->detailed_name;
info.kind = def->kind;
info.containerName = def->detailed_name;
switch (def->kind) {
default:
info.kind = lsSymbolKind::Function;
break;
case ClangSymbolKind::InstanceMethod:
case ClangSymbolKind::StaticMethod:
info.kind = lsSymbolKind::Method;
break;
}
return info;
}
case SymbolKind::Var: {
@ -504,15 +488,8 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
info.name = def->ShortName();
else
info.name = def->detailed_name;
info.kind = def->kind;
info.containerName = def->detailed_name;
switch (def->kind) {
default:
info.kind = lsSymbolKind::Variable;
break;
case ClangSymbolKind::EnumConstant:
info.kind = lsSymbolKind::EnumMember;
break;
}
return info;
}
case SymbolKind::Invalid:

View File

@ -8,47 +8,6 @@ enum class SymbolKind : uint8_t { Invalid, File, Type, Func, Var };
MAKE_REFLECT_TYPE_PROXY(SymbolKind);
MAKE_ENUM_HASHABLE(SymbolKind);
// TODO Rename query.h:SymbolKind to another name
// clang/Index/IndexSymbol.h clang::index::SymbolKind
enum class ClangSymbolKind : uint8_t {
Unknown,
Module = 1,
Namespace,
NamespaceAlias,
Macro,
Enum = 5,
Struct,
Class,
Protocol,
Extension,
Union,
TypeAlias,
Function = 12,
Variable,
Field,
EnumConstant,
InstanceMethod = 16,
ClassMethod,
StaticMethod,
InstanceProperty,
ClassProperty,
StaticProperty,
Constructor = 22,
Destructor,
ConversionFunction,
// Used for both function and template parameters.
// Clients can differentiate based on StorageClass.
Parameter = 25,
Using,
};
MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind);
// clang/Basic/Specifiers.h clang::StorageClass
enum class StorageClass : uint8_t {
// In |CX_StorageClass| but not in |clang::StorageClass|
@ -119,7 +78,9 @@ struct lsDocumentHighlight {
};
MAKE_REFLECT_STRUCT(lsDocumentHighlight, range, kind, role);
enum class lsSymbolKind : int {
enum class lsSymbolKind : uint8_t {
Unknown = 0,
File = 1,
Module = 2,
Namespace = 3,
@ -146,6 +107,12 @@ enum class lsSymbolKind : int {
Event = 24,
Operator = 25,
TypeParameter = 26,
// cquery extensions
// See also https://github.com/Microsoft/language-server-protocol/issues/344 for new SymbolKind
// clang/Index/IndexSymbol.h clang::index::SymbolKind
Parameter = 13,
Macro = 255,
};
MAKE_REFLECT_TYPE_PROXY(lsSymbolKind);