@@ -12,20 +12,28 @@ class SemanticTokensTest : SingleFileTestFixture("semantictokens", "SemanticToke
1212 @Test fun `tokenize file` () {
1313 val varLine = 1
1414 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
1819
1920 val expectedVar = sequenceOf(
2021 SemanticToken (range(varLine, 5 , varLine, 13 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION )), // variable
2122 )
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.
2228 val expectedConst = sequenceOf(
2329 SemanticToken (range(constLine, 5 , constLine, 13 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // constant
2430 SemanticToken (range(constLine, 15 , constLine, 21 ), SemanticTokenType .CLASS ), // String
25- SemanticToken (range(constLine, 24 , constLine, 40 ), SemanticTokenType .STRING ), // "test $variable"
2631 SemanticToken (range(constLine, 30 , constLine, 39 ), SemanticTokenType .INTERPOLATION_ENTRY ), // $variable
2732 SemanticToken (range(constLine, 31 , constLine, 39 ), SemanticTokenType .PROPERTY ), // variable
2833 )
34+ val expectedString = sequenceOf(
35+ SemanticToken (range(stringLine, 5 , stringLine, 11 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // string
36+ )
2937 val expectedClass = sequenceOf(
3038 SemanticToken (range(classLine, 12 , classLine, 16 ), SemanticTokenType .CLASS , setOf (SemanticTokenModifier .DECLARATION )), // Type
3139 SemanticToken (range(classLine, 21 , classLine, 29 ), SemanticTokenType .PARAMETER , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // property
@@ -44,11 +52,11 @@ class SemanticTokensTest : SingleFileTestFixture("semantictokens", "SemanticToke
4452 SemanticToken (range(enumLine, 19 , enumLine, 27 ), SemanticTokenType .ENUM_MEMBER , setOf (SemanticTokenModifier .DECLARATION )) // Variant1
4553 )
4654
47- val partialExpected = encodeTokens(expectedConst + expectedClass)
55+ val partialExpected = encodeTokens(expectedConst + expectedString + expectedClass)
4856 val partialResponse = languageServer.textDocumentService.semanticTokensRange(semanticTokensRangeParams(file, range(constLine, 0 , classLine + 1 , 0 ))).get()!!
4957 assertThat(partialResponse.data, contains(* partialExpected.toTypedArray()))
5058
51- val fullExpected = encodeTokens(expectedVar + expectedConst + expectedClass + expectedFun + expectedEnum)
59+ val fullExpected = encodeTokens(expectedVar + expectedConst + expectedString + expectedClass + expectedFun + expectedEnum)
5260 val fullResponse = languageServer.textDocumentService.semanticTokensFull(semanticTokensParams(file)).get()!!
5361 assertThat(fullResponse.data, contains(* fullExpected.toTypedArray()))
5462 }
0 commit comments