@@ -12,19 +12,28 @@ class SemanticTokensTest : SingleFileTestFixture("semantictokens", "SemanticToke
12
12
@Test fun `tokenize file` () {
13
13
val varLine = 1
14
14
val constLine = 2
15
- val classLine = 4
16
- val funLine = 6
17
- val enumLine = 8
15
+ val stringLine = 3
16
+ val classLine = 5
17
+ val funLine = 7
18
+ val enumLine = 9
18
19
19
20
val expectedVar = sequenceOf(
20
21
SemanticToken (range(varLine, 5 , varLine, 13 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION )), // variable
21
22
)
23
+ // Neither string literals nor interpolations (which are both
24
+ // represented as string templates) are currently emitted as semantic
25
+ // tokens. This is to avoid "covering" interpolations with the literal.
26
+ // A more sophisticated implementation would slice up the string tokens
27
+ // to not include child nodes, but that's for a future implementation.
22
28
val expectedConst = sequenceOf(
23
29
SemanticToken (range(constLine, 5 , constLine, 13 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // constant
24
30
SemanticToken (range(constLine, 15 , constLine, 21 ), SemanticTokenType .CLASS ), // String
25
31
SemanticToken (range(constLine, 30 , constLine, 39 ), SemanticTokenType .INTERPOLATION_ENTRY ), // $variable
26
32
SemanticToken (range(constLine, 31 , constLine, 39 ), SemanticTokenType .PROPERTY ), // variable
27
33
)
34
+ val expectedString = sequenceOf(
35
+ SemanticToken (range(stringLine, 5 , stringLine, 11 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // string
36
+ )
28
37
val expectedClass = sequenceOf(
29
38
SemanticToken (range(classLine, 12 , classLine, 16 ), SemanticTokenType .CLASS , setOf (SemanticTokenModifier .DECLARATION )), // Type
30
39
SemanticToken (range(classLine, 21 , classLine, 29 ), SemanticTokenType .PARAMETER , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // property
@@ -43,11 +52,11 @@ class SemanticTokensTest : SingleFileTestFixture("semantictokens", "SemanticToke
43
52
SemanticToken (range(enumLine, 19 , enumLine, 27 ), SemanticTokenType .ENUM_MEMBER , setOf (SemanticTokenModifier .DECLARATION )) // Variant1
44
53
)
45
54
46
- val partialExpected = encodeTokens(expectedConst + expectedClass)
55
+ val partialExpected = encodeTokens(expectedConst + expectedString + expectedClass)
47
56
val partialResponse = languageServer.textDocumentService.semanticTokensRange(semanticTokensRangeParams(file, range(constLine, 0 , classLine + 1 , 0 ))).get()!!
48
57
assertThat(partialResponse.data, contains(* partialExpected.toTypedArray()))
49
58
50
- val fullExpected = encodeTokens(expectedVar + expectedConst + expectedClass + expectedFun + expectedEnum)
59
+ val fullExpected = encodeTokens(expectedVar + expectedConst + expectedString + expectedClass + expectedFun + expectedEnum)
51
60
val fullResponse = languageServer.textDocumentService.semanticTokensFull(semanticTokensParams(file)).get()!!
52
61
assertThat(fullResponse.data, contains(* fullExpected.toTypedArray()))
53
62
}
0 commit comments