Strongly typed semantic highlighting kind

This commit is contained in:
Jacob Dufault 2018-01-16 17:48:22 -08:00
parent 5ff7d165f9
commit 67834ca783
4 changed files with 50 additions and 42 deletions

46
src/clang_symbol_kind.h Normal file
View File

@ -0,0 +1,46 @@
#pragma once
#include "serializer.h"
#include <stdint.h>
// 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,
Parameter = 25,
Using,
};
MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind,
std::underlying_type<ClangSymbolKind>::type);

View File

@ -2,6 +2,7 @@
#include "clang_cursor.h"
#include "clang_index.h"
#include "clang_symbol_kind.h"
#include "clang_translation_unit.h"
#include "clang_utils.h"
#include "file_consumer.h"
@ -77,46 +78,6 @@ using IndexVarId = Id<IndexVar>;
struct IdCache;
// 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,
Parameter = 25,
Using,
};
MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind,
std::underlying_type<ClangSymbolKind>::type);
struct IndexFuncRef {
// NOTE: id can be -1 if the function call is not coming from a function.
IndexFuncId id;

View File

@ -1,5 +1,6 @@
#pragma once
#include "clang_symbol_kind.h"
#include "config.h"
#include "ipc.h"
#include "serializer.h"
@ -1086,7 +1087,7 @@ struct Out_CqueryPublishSemanticHighlighting
int stableId = 0;
// TODO Deprecate |type| in favor of fine-grained |kind|.
SymbolType type = SymbolType::Type;
int kind;
ClangSymbolKind kind;
bool isTypeMember = false;
std::vector<lsRange> ranges;
};

View File

@ -187,7 +187,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
Out_CqueryPublishSemanticHighlighting::Symbol symbol;
symbol.stableId =
semantic_cache_for_file->GetStableId(sym.idx.kind, detailed_name);
symbol.kind = static_cast<int>(kind);
symbol.kind = kind;
symbol.type = map_symbol_kind_to_symbol_type(sym.idx.kind);
symbol.isTypeMember = is_type_member;
symbol.ranges.push_back(*loc);