mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 23:55:08 +00:00
Change VarClass::cls to ClangSymbolKind::kind
ClangSymbolKind is ported from clang::index::SymbolKind
This commit is contained in:
parent
cf2103b521
commit
516b94e982
@ -408,7 +408,7 @@ void OnIndexReference_Function(IndexFile* db,
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// static
|
// static
|
||||||
int IndexFile::kCurrentVersion = 6;
|
int IndexFile::kCurrentVersion = 7;
|
||||||
|
|
||||||
IndexFile::IndexFile(const std::string& path) : id_cache(path), path(path) {
|
IndexFile::IndexFile(const std::string& path) : id_cache(path), path(path) {
|
||||||
// TODO: Reconsider if we should still be reusing the same id_cache.
|
// TODO: Reconsider if we should still be reusing the same id_cache.
|
||||||
@ -965,7 +965,7 @@ ClangCursor::VisitResult VisitMacroDefinitionAndExpansions(ClangCursor cursor,
|
|||||||
var_def->def.detailed_name = cursor.get_display_name();
|
var_def->def.detailed_name = cursor.get_display_name();
|
||||||
var_def->def.hover =
|
var_def->def.hover =
|
||||||
"#define " + GetDocumentContentInRange(param->tu->cx_tu, cx_extent);
|
"#define " + GetDocumentContentInRange(param->tu->cx_tu, cx_extent);
|
||||||
var_def->def.cls = VarClass::Macro;
|
var_def->def.kind = ClangSymbolKind::Macro;
|
||||||
var_def->def.comments = cursor.get_comments();
|
var_def->def.comments = cursor.get_comments();
|
||||||
var_def->def.definition_spelling = decl_loc_spelling;
|
var_def->def.definition_spelling = decl_loc_spelling;
|
||||||
var_def->def.definition_extent = ResolveCXSourceRange(cx_extent, nullptr);
|
var_def->def.definition_extent = ResolveCXSourceRange(cx_extent, nullptr);
|
||||||
@ -1213,18 +1213,13 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
SetVarDetail(var, decl->cursor, decl->semanticContainer,
|
SetVarDetail(var, decl->cursor, decl->semanticContainer,
|
||||||
!decl->isRedeclaration, db, param);
|
!decl->isRedeclaration, db, param);
|
||||||
|
|
||||||
bool is_system = clang_Location_isInSystemHeader(
|
// FIXME https://github.com/jacobdufault/cquery/issues/239
|
||||||
clang_indexLoc_getCXSourceLocation(decl->loc));
|
if (IsGlobalContainer(decl->semanticContainer))
|
||||||
if (is_system)
|
var->def.kind = ClangSymbolKind::Module;
|
||||||
var->def.cls = VarClass::Unknown;
|
else if (IsTypeDefinition(decl->semanticContainer))
|
||||||
else {
|
var->def.kind = ClangSymbolKind::Field;
|
||||||
if (IsGlobalContainer(decl->semanticContainer))
|
else
|
||||||
var->def.cls = VarClass::Global;
|
var->def.kind = ClangSymbolKind::Variable;
|
||||||
else if (IsTypeDefinition(decl->semanticContainer))
|
|
||||||
var->def.cls = VarClass::Member;
|
|
||||||
else
|
|
||||||
var->def.cls = VarClass::Local;
|
|
||||||
}
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if (decl->isDefinition) {
|
if (decl->isDefinition) {
|
||||||
@ -1635,7 +1630,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
|
|||||||
// and has more information, thus not easy to reuse the code.
|
// and has more information, thus not easy to reuse the code.
|
||||||
var->def.short_name = referenced.get_spelling();
|
var->def.short_name = referenced.get_spelling();
|
||||||
SetVarDetail(var, referenced, nullptr, true, db, param);
|
SetVarDetail(var, referenced, nullptr, true, db, param);
|
||||||
var->def.cls = VarClass::Local;
|
var->def.kind = ClangSymbolKind::Parameter;
|
||||||
UniqueAdd(var->uses, referenced.get_spelling_range());
|
UniqueAdd(var->uses, referenced.get_spelling_range());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,45 @@ using IndexVarId = Id<IndexVar>;
|
|||||||
|
|
||||||
struct IdCache;
|
struct IdCache;
|
||||||
|
|
||||||
|
// TODO Rename query.h:SymbolKind to another name; change int16_t to uint8_t
|
||||||
|
// clang/Index/IndexSymbol.h clang::index::SymbolKind
|
||||||
|
enum class ClangSymbolKind : int16_t {
|
||||||
|
Unknown,
|
||||||
|
|
||||||
|
Module,
|
||||||
|
Namespace,
|
||||||
|
NamespaceAlias,
|
||||||
|
Macro,
|
||||||
|
|
||||||
|
Enum,
|
||||||
|
Struct,
|
||||||
|
Class,
|
||||||
|
Protocol,
|
||||||
|
Extension,
|
||||||
|
Union,
|
||||||
|
TypeAlias,
|
||||||
|
|
||||||
|
Function,
|
||||||
|
Variable,
|
||||||
|
Field,
|
||||||
|
EnumConstant,
|
||||||
|
|
||||||
|
InstanceMethod,
|
||||||
|
ClassMethod,
|
||||||
|
StaticMethod,
|
||||||
|
InstanceProperty,
|
||||||
|
ClassProperty,
|
||||||
|
StaticProperty,
|
||||||
|
|
||||||
|
Constructor,
|
||||||
|
Destructor,
|
||||||
|
ConversionFunction,
|
||||||
|
|
||||||
|
Parameter,
|
||||||
|
Using,
|
||||||
|
};
|
||||||
|
MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind, std::underlying_type<ClangSymbolKind>::type);
|
||||||
|
|
||||||
struct IndexFuncRef {
|
struct IndexFuncRef {
|
||||||
// NOTE: id can be -1 if the function call is not coming from a function.
|
// NOTE: id can be -1 if the function call is not coming from a function.
|
||||||
IndexFuncId id;
|
IndexFuncId id;
|
||||||
@ -149,6 +188,7 @@ struct TypeDefDefinitionData {
|
|||||||
// General metadata.
|
// General metadata.
|
||||||
std::string short_name;
|
std::string short_name;
|
||||||
std::string detailed_name;
|
std::string detailed_name;
|
||||||
|
ClangSymbolKind kind = ClangSymbolKind::Unknown;
|
||||||
optional<std::string> hover;
|
optional<std::string> hover;
|
||||||
optional<std::string> comments;
|
optional<std::string> comments;
|
||||||
|
|
||||||
@ -202,6 +242,7 @@ void Reflect(TVisitor& visitor,
|
|||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(short_name);
|
REFLECT_MEMBER(short_name);
|
||||||
REFLECT_MEMBER(detailed_name);
|
REFLECT_MEMBER(detailed_name);
|
||||||
|
REFLECT_MEMBER(kind);
|
||||||
REFLECT_MEMBER(hover);
|
REFLECT_MEMBER(hover);
|
||||||
REFLECT_MEMBER(comments);
|
REFLECT_MEMBER(comments);
|
||||||
REFLECT_MEMBER(definition_spelling);
|
REFLECT_MEMBER(definition_spelling);
|
||||||
@ -249,6 +290,7 @@ struct FuncDefDefinitionData {
|
|||||||
// General metadata.
|
// General metadata.
|
||||||
std::string short_name;
|
std::string short_name;
|
||||||
std::string detailed_name;
|
std::string detailed_name;
|
||||||
|
ClangSymbolKind kind = ClangSymbolKind::Unknown;
|
||||||
optional<std::string> hover;
|
optional<std::string> hover;
|
||||||
optional<std::string> comments;
|
optional<std::string> comments;
|
||||||
optional<Range> definition_spelling;
|
optional<Range> definition_spelling;
|
||||||
@ -299,6 +341,7 @@ void Reflect(
|
|||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(short_name);
|
REFLECT_MEMBER(short_name);
|
||||||
REFLECT_MEMBER(detailed_name);
|
REFLECT_MEMBER(detailed_name);
|
||||||
|
REFLECT_MEMBER(kind);
|
||||||
REFLECT_MEMBER(hover);
|
REFLECT_MEMBER(hover);
|
||||||
REFLECT_MEMBER(comments);
|
REFLECT_MEMBER(comments);
|
||||||
REFLECT_MEMBER(definition_spelling);
|
REFLECT_MEMBER(definition_spelling);
|
||||||
@ -361,25 +404,12 @@ MAKE_REFLECT_STRUCT(IndexFunc::Declaration,
|
|||||||
content,
|
content,
|
||||||
param_spellings);
|
param_spellings);
|
||||||
|
|
||||||
enum class VarClass {
|
|
||||||
// probably a variable in system headers
|
|
||||||
Unknown = 0,
|
|
||||||
// a parameter or function variable
|
|
||||||
Local = 1,
|
|
||||||
// a macro, ie, #define FOO
|
|
||||||
Macro = 2,
|
|
||||||
// a global variable
|
|
||||||
Global = 3,
|
|
||||||
// a member variable of struct/union/class/enum
|
|
||||||
Member = 4
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_TYPE_PROXY(VarClass, std::underlying_type<VarClass>::type);
|
|
||||||
|
|
||||||
template <typename TypeId, typename FuncId, typename VarId, typename Range>
|
template <typename TypeId, typename FuncId, typename VarId, typename Range>
|
||||||
struct VarDefDefinitionData {
|
struct VarDefDefinitionData {
|
||||||
// General metadata.
|
// General metadata.
|
||||||
std::string short_name;
|
std::string short_name;
|
||||||
std::string detailed_name;
|
std::string detailed_name;
|
||||||
|
ClangSymbolKind kind = ClangSymbolKind::Unknown;
|
||||||
optional<std::string> hover;
|
optional<std::string> hover;
|
||||||
optional<std::string> comments;
|
optional<std::string> comments;
|
||||||
optional<Range> declaration;
|
optional<Range> declaration;
|
||||||
@ -394,10 +424,9 @@ struct VarDefDefinitionData {
|
|||||||
// Type which declares this one.
|
// Type which declares this one.
|
||||||
optional<TypeId> declaring_type;
|
optional<TypeId> declaring_type;
|
||||||
|
|
||||||
VarClass cls = VarClass::Unknown;
|
// FIXME
|
||||||
|
bool is_local() const { return kind == ClangSymbolKind::Variable; }
|
||||||
bool is_local() const { return cls == VarClass::Local; }
|
bool is_macro() const { return kind == ClangSymbolKind::Macro; }
|
||||||
bool is_macro() const { return cls == VarClass::Macro; }
|
|
||||||
|
|
||||||
bool operator==(
|
bool operator==(
|
||||||
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||||
@ -426,13 +455,13 @@ void Reflect(TVisitor& visitor,
|
|||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(short_name);
|
REFLECT_MEMBER(short_name);
|
||||||
REFLECT_MEMBER(detailed_name);
|
REFLECT_MEMBER(detailed_name);
|
||||||
|
REFLECT_MEMBER(kind);
|
||||||
REFLECT_MEMBER(hover);
|
REFLECT_MEMBER(hover);
|
||||||
REFLECT_MEMBER(comments);
|
REFLECT_MEMBER(comments);
|
||||||
REFLECT_MEMBER(definition_spelling);
|
REFLECT_MEMBER(definition_spelling);
|
||||||
REFLECT_MEMBER(definition_extent);
|
REFLECT_MEMBER(definition_extent);
|
||||||
REFLECT_MEMBER(variable_type);
|
REFLECT_MEMBER(variable_type);
|
||||||
REFLECT_MEMBER(declaring_type);
|
REFLECT_MEMBER(declaring_type);
|
||||||
REFLECT_MEMBER(cls);
|
|
||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,10 +126,11 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
|||||||
QueryVar* var = &db->vars[sym.idx.idx];
|
QueryVar* var = &db->vars[sym.idx.idx];
|
||||||
if (!var->def)
|
if (!var->def)
|
||||||
continue; // applies to for loop
|
continue; // applies to for loop
|
||||||
switch (var->def->cls) {
|
switch (var->def->kind) {
|
||||||
case VarClass::Local:
|
case ClangSymbolKind::Field:
|
||||||
case VarClass::Global:
|
case ClangSymbolKind::Macro:
|
||||||
case VarClass::Member:
|
case ClangSymbolKind::Module:
|
||||||
|
case ClangSymbolKind::Variable:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue; // applies to for loop
|
continue; // applies to for loop
|
||||||
|
@ -72,7 +72,7 @@ optional<QueryVar::Def> ToQuery(const IdMap& id_map, const IndexVar::Def& var) {
|
|||||||
result.definition_extent = id_map.ToQuery(var.definition_extent);
|
result.definition_extent = id_map.ToQuery(var.definition_extent);
|
||||||
result.variable_type = id_map.ToQuery(var.variable_type);
|
result.variable_type = id_map.ToQuery(var.variable_type);
|
||||||
result.declaring_type = id_map.ToQuery(var.declaring_type);
|
result.declaring_type = id_map.ToQuery(var.declaring_type);
|
||||||
result.cls = var.cls;
|
result.kind = var.kind;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ void Reflect(TVisitor& visitor, IndexVar& value) {
|
|||||||
REFLECT_MEMBER2("definition_extent", value.def.definition_extent);
|
REFLECT_MEMBER2("definition_extent", value.def.definition_extent);
|
||||||
REFLECT_MEMBER2("variable_type", value.def.variable_type);
|
REFLECT_MEMBER2("variable_type", value.def.variable_type);
|
||||||
REFLECT_MEMBER2("declaring_type", value.def.declaring_type);
|
REFLECT_MEMBER2("declaring_type", value.def.declaring_type);
|
||||||
REFLECT_MEMBER2("cls", value.def.cls);
|
REFLECT_MEMBER2("kind", value.def.kind);
|
||||||
REFLECT_MEMBER2("uses", value.uses);
|
REFLECT_MEMBER2("uses", value.uses);
|
||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user