@@ -12,20 +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
- SemanticToken (range(constLine, 24 , constLine, 40 ), SemanticTokenType .STRING ), // "test $variable"
26
31
SemanticToken (range(constLine, 30 , constLine, 39 ), SemanticTokenType .INTERPOLATION_ENTRY ), // $variable
27
32
SemanticToken (range(constLine, 31 , constLine, 39 ), SemanticTokenType .PROPERTY ), // variable
28
33
)
34
+ val expectedString = sequenceOf(
35
+ SemanticToken (range(stringLine, 5 , stringLine, 11 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // string
36
+ )
29
37
val expectedClass = sequenceOf(
30
38
SemanticToken (range(classLine, 12 , classLine, 16 ), SemanticTokenType .CLASS , setOf (SemanticTokenModifier .DECLARATION )), // Type
31
39
SemanticToken (range(classLine, 21 , classLine, 29 ), SemanticTokenType .PARAMETER , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // property
@@ -44,11 +52,11 @@ class SemanticTokensTest : SingleFileTestFixture("semantictokens", "SemanticToke
44
52
SemanticToken (range(enumLine, 19 , enumLine, 27 ), SemanticTokenType .ENUM_MEMBER , setOf (SemanticTokenModifier .DECLARATION )) // Variant1
45
53
)
46
54
47
- val partialExpected = encodeTokens(expectedConst + expectedClass)
55
+ val partialExpected = encodeTokens(expectedConst + expectedString + expectedClass)
48
56
val partialResponse = languageServer.textDocumentService.semanticTokensRange(semanticTokensRangeParams(file, range(constLine, 0 , classLine + 1 , 0 ))).get()!!
49
57
assertThat(partialResponse.data, contains(* partialExpected.toTypedArray()))
50
58
51
- val fullExpected = encodeTokens(expectedVar + expectedConst + expectedClass + expectedFun + expectedEnum)
59
+ val fullExpected = encodeTokens(expectedVar + expectedConst + expectedString + expectedClass + expectedFun + expectedEnum)
52
60
val fullResponse = languageServer.textDocumentService.semanticTokensFull(semanticTokensParams(file)).get()!!
53
61
assertThat(fullResponse.data, contains(* fullExpected.toTypedArray()))
54
62
}
0 commit comments