| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHTING_H |
| 21 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHTING_H |
| 22 |
|
| 23 |
#include "Protocol.h" |
| 24 |
#include "llvm/ADT/StringRef.h" |
| 25 |
#include "llvm/Support/raw_ostream.h" |
| 26 |
|
| 27 |
namespace clang { |
| 28 |
namespace clangd { |
| 29 |
class ParsedAST; |
| 30 |
|
| 31 |
enum class HighlightingKind { |
| 32 |
Variable = 0, |
| 33 |
LocalVariable, |
| 34 |
Parameter, |
| 35 |
Function, |
| 36 |
Method, |
| 37 |
StaticMethod, |
| 38 |
Field, |
| 39 |
StaticField, |
| 40 |
Class, |
| 41 |
Interface, |
| 42 |
Enum, |
| 43 |
EnumConstant, |
| 44 |
Typedef, |
| 45 |
Type, |
| 46 |
Unknown, |
| 47 |
Namespace, |
| 48 |
TemplateParameter, |
| 49 |
Concept, |
| 50 |
Primitive, |
| 51 |
Macro, |
| 52 |
Modifier, |
| 53 |
Operator, |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
InactiveCode, |
| 58 |
|
| 59 |
LastKind = InactiveCode |
| 60 |
}; |
| 61 |
|
| 62 |
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, HighlightingKind K); |
| 63 |
|
| 64 |
enum class HighlightingModifier { |
| 65 |
Declaration, |
| 66 |
Definition, |
| 67 |
Deprecated, |
| 68 |
Deduced, |
| 69 |
Readonly, |
| 70 |
Static, |
| 71 |
Abstract, |
| 72 |
Virtual, |
| 73 |
DependentName, |
| 74 |
DefaultLibrary, |
| 75 |
UsedAsMutableReference, |
| 76 |
UsedAsMutablePointer, |
| 77 |
ConstructorOrDestructor, |
| 78 |
UserDefined, |
| 79 |
|
| 80 |
FunctionScope, |
| 81 |
ClassScope, |
| 82 |
FileScope, |
| 83 |
GlobalScope, |
| 84 |
|
| 85 |
LastModifier = GlobalScope |
| 86 |
}; |
| 87 |
static_assert(static_cast<unsigned>(HighlightingModifier::LastModifier) < 32, |
| 88 |
"Increase width of modifiers bitfield!"); |
| 89 |
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, HighlightingModifier K); |
| 90 |
|
| 91 |
|
| 92 |
struct HighlightingToken { |
| 93 |
HighlightingKind Kind; |
| 94 |
uint32_t Modifiers = 0; |
| 95 |
Range R; |
| 96 |
|
| 97 |
HighlightingToken &addModifier(HighlightingModifier M) { |
| 98 |
Modifiers |= 1 << static_cast<unsigned>(M); |
| 99 |
return *this; |
| 100 |
} |
| 101 |
}; |
| 102 |
|
| 103 |
bool operator==(const HighlightingToken &L, const HighlightingToken &R); |
| 104 |
bool operator<(const HighlightingToken &L, const HighlightingToken &R); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST); |
| 109 |
|
| 110 |
std::vector<SemanticToken> toSemanticTokens(llvm::ArrayRef<HighlightingToken>, |
| 111 |
llvm::StringRef Code); |
| 112 |
llvm::StringRef toSemanticTokenType(HighlightingKind Kind); |
| 113 |
llvm::StringRef toSemanticTokenModifier(HighlightingModifier Modifier); |
| 114 |
std::vector<SemanticTokensEdit> diffTokens(llvm::ArrayRef<SemanticToken> Before, |
| 115 |
llvm::ArrayRef<SemanticToken> After); |
| 116 |
|
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
#endif |