@@ -44,7 +44,8 @@ std::vector<HighlightingToken> getExpectedTokens(Annotations &Test) {
44
44
{HighlightingKind::Field, " Field" },
45
45
{HighlightingKind::Method, " Method" },
46
46
{HighlightingKind::TemplateParameter, " TemplateParameter" },
47
- {HighlightingKind::Primitive, " Primitive" }};
47
+ {HighlightingKind::Primitive, " Primitive" },
48
+ {HighlightingKind::LocalVariable, " LocalVariable" }};
48
49
std::vector<HighlightingToken> ExpectedTokens;
49
50
for (const auto &KindString : KindToString) {
50
51
std::vector<HighlightingToken> Toks = makeHighlightingTokens (
@@ -103,31 +104,31 @@ void checkDiffedHighlights(llvm::StringRef OldCode, llvm::StringRef NewCode) {
103
104
104
105
TEST (SemanticHighlighting, GetsCorrectTokens) {
105
106
const char *TestCases[] = {
106
- R"cpp(
107
+ R"cpp(
107
108
struct $Class[[AS]] {
108
109
$Primitive[[double]] $Field[[SomeMember]];
109
110
};
110
111
struct {
111
112
} $Variable[[S]];
112
113
$Primitive[[void]] $Function[[foo]]($Primitive[[int]] $Parameter[[A]], $Class[[AS]] $Parameter[[As]]) {
113
- $Primitive[[auto]] $Variable [[VeryLongVariableName]] = 12312;
114
- $Class[[AS]] $Variable [[AA]];
115
- $Primitive[[auto]] $Variable [[L]] = $Variable [[AA]].$Field[[SomeMember]] + $Parameter[[A]];
116
- auto $Variable [[FN]] = [ $Variable [[AA]]]($Primitive[[int]] $Parameter[[A]]) -> $Primitive[[void]] {};
117
- $Variable [[FN]](12312);
114
+ $Primitive[[auto]] $LocalVariable [[VeryLongVariableName]] = 12312;
115
+ $Class[[AS]] $LocalVariable [[AA]];
116
+ $Primitive[[auto]] $LocalVariable [[L]] = $LocalVariable [[AA]].$Field[[SomeMember]] + $Parameter[[A]];
117
+ auto $LocalVariable [[FN]] = [ $LocalVariable [[AA]]]($Primitive[[int]] $Parameter[[A]]) -> $Primitive[[void]] {};
118
+ $LocalVariable [[FN]](12312);
118
119
}
119
120
)cpp" ,
120
- R"cpp(
121
+ R"cpp(
121
122
$Primitive[[void]] $Function[[foo]]($Primitive[[int]]);
122
123
$Primitive[[void]] $Function[[Gah]]();
123
124
$Primitive[[void]] $Function[[foo]]() {
124
- auto $Variable [[Bou]] = $Function[[Gah]];
125
+ auto $LocalVariable [[Bou]] = $Function[[Gah]];
125
126
}
126
127
struct $Class[[A]] {
127
128
$Primitive[[void]] $Method[[abc]]();
128
129
};
129
130
)cpp" ,
130
- R"cpp(
131
+ R"cpp(
131
132
namespace $Namespace[[abc]] {
132
133
template<typename $TemplateParameter[[T]]>
133
134
struct $Class[[A]] {
@@ -149,12 +150,12 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
149
150
$Class[[B]]::$Class[[B]]() {}
150
151
$Class[[B]]::~$Class[[B]]() {}
151
152
$Primitive[[void]] $Function[[f]] () {
152
- $Class[[B]] $Variable [[BB]] = $Class[[B]]();
153
- $Variable [[BB]].~$Class[[B]]();
153
+ $Class[[B]] $LocalVariable [[BB]] = $Class[[B]]();
154
+ $LocalVariable [[BB]].~$Class[[B]]();
154
155
$Class[[B]]();
155
156
}
156
157
)cpp" ,
157
- R"cpp(
158
+ R"cpp(
158
159
enum class $Enum[[E]] {
159
160
$EnumConstant[[A]],
160
161
$EnumConstant[[B]],
@@ -169,7 +170,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
169
170
$Primitive[[int]] $Variable[[I]] = $EnumConstant[[Hi]];
170
171
$Enum[[E]] $Variable[[L]] = $Enum[[E]]::$EnumConstant[[B]];
171
172
)cpp" ,
172
- R"cpp(
173
+ R"cpp(
173
174
namespace $Namespace[[abc]] {
174
175
namespace {}
175
176
namespace $Namespace[[bcd]] {
@@ -192,7 +193,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
192
193
::$Namespace[[vwz]]::$Class[[A]] $Variable[[B]];
193
194
::$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[BB]];
194
195
)cpp" ,
195
- R"cpp(
196
+ R"cpp(
196
197
struct $Class[[D]] {
197
198
$Primitive[[double]] $Field[[C]];
198
199
};
@@ -209,21 +210,21 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
209
210
}
210
211
};
211
212
$Primitive[[void]] $Function[[foo]]() {
212
- $Class[[A]] $Variable [[AA]];
213
- $Variable [[AA]].$Field[[B]] += 2;
214
- $Variable [[AA]].$Method[[foo]]();
215
- $Variable [[AA]].$Field[[E]].$Field[[C]];
213
+ $Class[[A]] $LocalVariable [[AA]];
214
+ $LocalVariable [[AA]].$Field[[B]] += 2;
215
+ $LocalVariable [[AA]].$Method[[foo]]();
216
+ $LocalVariable [[AA]].$Field[[E]].$Field[[C]];
216
217
$Class[[A]]::$Variable[[S]] = 90;
217
218
}
218
219
)cpp" ,
219
- R"cpp(
220
+ R"cpp(
220
221
struct $Class[[AA]] {
221
222
$Primitive[[int]] $Field[[A]];
222
223
}
223
224
$Primitive[[int]] $Variable[[B]];
224
225
$Class[[AA]] $Variable[[A]]{$Variable[[B]]};
225
226
)cpp" ,
226
- R"cpp(
227
+ R"cpp(
227
228
namespace $Namespace[[a]] {
228
229
struct $Class[[A]] {};
229
230
typedef $Primitive[[char]] $Primitive[[C]];
@@ -239,7 +240,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
239
240
typedef $Namespace[[a]]::$Primitive[[C]] $Primitive[[PC]];
240
241
typedef $Primitive[[float]] $Primitive[[F]];
241
242
)cpp" ,
242
- R"cpp(
243
+ R"cpp(
243
244
template<typename $TemplateParameter[[T]], typename = $Primitive[[void]]>
244
245
class $Class[[A]] {
245
246
$TemplateParameter[[T]] $Field[[AA]];
@@ -265,30 +266,30 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
265
266
template<typename $TemplateParameter[[T]]>
266
267
$Primitive[[void]] $Function[[foo]]($TemplateParameter[[T]] ...);
267
268
)cpp" ,
268
- R"cpp(
269
+ R"cpp(
269
270
template <class $TemplateParameter[[T]]>
270
271
struct $Class[[Tmpl]] {$TemplateParameter[[T]] $Field[[x]] = 0;};
271
272
extern template struct $Class[[Tmpl]]<$Primitive[[float]]>;
272
273
template struct $Class[[Tmpl]]<$Primitive[[double]]>;
273
274
)cpp" ,
274
- // This test is to guard against highlightings disappearing when using
275
- // conversion operators as their behaviour in the clang AST differ from
276
- // other CXXMethodDecls.
277
- R"cpp(
275
+ // This test is to guard against highlightings disappearing when using
276
+ // conversion operators as their behaviour in the clang AST differ from
277
+ // other CXXMethodDecls.
278
+ R"cpp(
278
279
class $Class[[Foo]] {};
279
280
struct $Class[[Bar]] {
280
281
explicit operator $Class[[Foo]]*() const;
281
282
explicit operator $Primitive[[int]]() const;
282
283
operator $Class[[Foo]]();
283
284
};
284
285
$Primitive[[void]] $Function[[f]]() {
285
- $Class[[Bar]] $Variable [[B]];
286
- $Class[[Foo]] $Variable [[F]] = $Variable [[B]];
287
- $Class[[Foo]] *$Variable [[FP]] = ($Class[[Foo]]*)$Variable [[B]];
288
- $Primitive[[int]] $Variable [[I]] = ($Primitive[[int]])$Variable [[B]];
286
+ $Class[[Bar]] $LocalVariable [[B]];
287
+ $Class[[Foo]] $LocalVariable [[F]] = $LocalVariable [[B]];
288
+ $Class[[Foo]] *$LocalVariable [[FP]] = ($Class[[Foo]]*)$LocalVariable [[B]];
289
+ $Primitive[[int]] $LocalVariable [[I]] = ($Primitive[[int]])$LocalVariable [[B]];
289
290
}
290
291
)cpp"
291
- R"cpp(
292
+ R"cpp(
292
293
struct $Class[[B]] {};
293
294
struct $Class[[A]] {
294
295
$Class[[B]] $Field[[BB]];
@@ -297,7 +298,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
297
298
298
299
$Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Parameter[[O]]) = default;
299
300
)cpp" ,
300
- R"cpp(
301
+ R"cpp(
301
302
enum $Enum[[En]] {
302
303
$EnumConstant[[EC]],
303
304
};
@@ -315,7 +316,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
315
316
$Class[[Bar2]]() : $Class[[Bar]]($Class[[Foo]](), $EnumConstant[[EC]]) {}
316
317
};
317
318
)cpp" ,
318
- R"cpp(
319
+ R"cpp(
319
320
enum $Enum[[E]] {
320
321
$EnumConstant[[E]],
321
322
};
@@ -329,7 +330,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
329
330
$Primitive[[decltype]]($Variable[[Form]]) $Variable[[F]] = 10;
330
331
auto $Variable[[Fun]] = []()->$Primitive[[void]]{};
331
332
)cpp" ,
332
- R"cpp(
333
+ R"cpp(
333
334
class $Class[[G]] {};
334
335
template<$Class[[G]] *$TemplateParameter[[U]]>
335
336
class $Class[[GP]] {};
@@ -344,19 +345,19 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
344
345
template<$Primitive[[unsigned]] $TemplateParameter[[U]] = 2>
345
346
class $Class[[Foo]] {
346
347
$Primitive[[void]] $Method[[f]]() {
347
- for($Primitive[[int]] $Variable [[I]] = 0;
348
- $Variable [[I]] < $TemplateParameter[[U]];) {}
348
+ for($Primitive[[int]] $LocalVariable [[I]] = 0;
349
+ $LocalVariable [[I]] < $TemplateParameter[[U]];) {}
349
350
}
350
351
};
351
352
352
353
$Class[[G]] $Variable[[L]];
353
354
$Primitive[[void]] $Function[[f]]() {
354
- $Class[[Foo]]<123> $Variable [[F]];
355
- $Class[[GP]]<&$Variable[[L]]> $Variable [[LL]];
356
- $Class[[GR]]<$Variable[[L]]> $Variable [[LLL]];
355
+ $Class[[Foo]]<123> $LocalVariable [[F]];
356
+ $Class[[GP]]<&$Variable[[L]]> $LocalVariable [[LL]];
357
+ $Class[[GR]]<$Variable[[L]]> $LocalVariable [[LLL]];
357
358
}
358
359
)cpp" ,
359
- R"cpp(
360
+ R"cpp(
360
361
template<typename $TemplateParameter[[T]],
361
362
$Primitive[[void]] (T::*$TemplateParameter[[method]])($Primitive[[int]])>
362
363
struct $Class[[G]] {
@@ -376,14 +377,14 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
376
377
};
377
378
378
379
$Primitive[[void]] $Function[[foo]]() {
379
- $Class[[F]] $Variable [[FF]];
380
- $Class[[G]]<$Class[[F]], &$Class[[F]]::$Method[[f]]> $Variable [[GG]];
381
- $Variable [[GG]].$Method[[foo]](&$Variable [[FF]]);
382
- $Class[[A]]<$Function[[foo]]> $Variable [[AA]];
380
+ $Class[[F]] $LocalVariable [[FF]];
381
+ $Class[[G]]<$Class[[F]], &$Class[[F]]::$Method[[f]]> $LocalVariable [[GG]];
382
+ $LocalVariable [[GG]].$Method[[foo]](&$LocalVariable [[FF]]);
383
+ $Class[[A]]<$Function[[foo]]> $LocalVariable [[AA]];
383
384
)cpp" ,
384
- // Tokens that share a source range but have conflicting Kinds are not
385
- // highlighted.
386
- R"cpp(
385
+ // Tokens that share a source range but have conflicting Kinds are not
386
+ // highlighted.
387
+ R"cpp(
387
388
#define DEF_MULTIPLE(X) namespace X { class X { int X; }; }
388
389
#define DEF_CLASS(T) class T {};
389
390
DEF_MULTIPLE(XYZ);
@@ -399,17 +400,17 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
399
400
#define SOME_NAME_SET variable2 = 123
400
401
#define INC_VAR(X) X += 2
401
402
$Primitive[[void]] $Function[[foo]]() {
402
- DEF_VAR($Variable [[X]], 123);
403
- DEF_VAR_REV(908, $Variable [[XY]]);
404
- $Primitive[[int]] CPY( $Variable [[XX]] );
405
- DEF_VAR_TYPE($Class[[A]], $Variable [[AA]]);
403
+ DEF_VAR($LocalVariable [[X]], 123);
404
+ DEF_VAR_REV(908, $LocalVariable [[XY]]);
405
+ $Primitive[[int]] CPY( $LocalVariable [[XX]] );
406
+ DEF_VAR_TYPE($Class[[A]], $LocalVariable [[AA]]);
406
407
$Primitive[[double]] SOME_NAME;
407
408
$Primitive[[int]] SOME_NAME_SET;
408
- $Variable [[variable]] = 20.1;
409
+ $LocalVariable [[variable]] = 20.1;
409
410
MACRO_CONCAT(var, 2, $Primitive[[float]]);
410
- DEF_VAR_T($Class[[A]], CPY(CPY($Variable [[Nested]])),
411
+ DEF_VAR_T($Class[[A]], CPY(CPY($LocalVariable [[Nested]])),
411
412
CPY($Class[[A]]()));
412
- INC_VAR($Variable [[variable]]);
413
+ INC_VAR($LocalVariable [[variable]]);
413
414
}
414
415
$Primitive[[void]] SOME_NAME();
415
416
DEF_VAR($Variable[[XYZ]], 567);
@@ -421,7 +422,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
421
422
CALL_FN($Function[[foo]]);
422
423
}
423
424
)cpp" ,
424
- R"cpp(
425
+ R"cpp(
425
426
#define fail(expr) expr
426
427
#define assert(COND) if (!(COND)) { fail("assertion failed" #COND); }
427
428
$Primitive[[int]] $Variable[[x]];
@@ -505,7 +506,7 @@ TEST(SemanticHighlighting, toSemanticHighlightingInformation) {
505
506
std::vector<SemanticHighlightingInformation> ActualResults =
506
507
toSemanticHighlightingInformation (Tokens);
507
508
std::vector<SemanticHighlightingInformation> ExpectedResults = {
508
- {3 , " AAAACAAEAAAAAAAEAAMAAg ==" }, {1 , " AAAAAQAEAAA=" }};
509
+ {3 , " AAAACAAEAAAAAAAEAAMAAw ==" }, {1 , " AAAAAQAEAAA=" }};
509
510
EXPECT_EQ (ActualResults, ExpectedResults);
510
511
}
511
512
0 commit comments