@@ -9,30 +9,45 @@ import org.javacs.kt.semantictokens.SemanticTokenType
9
9
import org.javacs.kt.semantictokens.SemanticTokenModifier
10
10
11
11
class SemanticTokensTest : SingleFileTestFixture (" semantictokens" , " SemanticTokens.kt" ) {
12
- @Test fun `tokenize entire file` () {
13
- val response = languageServer.textDocumentService.semanticTokensFull(semanticTokensParams(file)).get() !!
14
- val actual = response.data
15
- val expected = encodeTokens(sequenceOf(
16
- SemanticToken (range( 1 , 5 , 1 , 13 ), SemanticTokenType . PROPERTY , setOf ( SemanticTokenModifier . DECLARATION )), // variable
12
+ @Test fun `tokenize file` () {
13
+ val varLine = 1
14
+ val constLine = 2
15
+ val classLine = 4
16
+ val funLine = 6
17
17
18
- SemanticToken (range(2 , 5 , 2 , 13 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // constant
19
- SemanticToken (range(2 , 15 , 2 , 21 ), SemanticTokenType .CLASS ), // String
20
- SemanticToken (range(2 , 24 , 2 , 40 ), SemanticTokenType .STRING ), // "test $variable"
21
- SemanticToken (range(2 , 30 , 2 , 39 ), SemanticTokenType .INTERPOLATION_ENTRY ), // $variable
22
- SemanticToken (range(2 , 31 , 2 , 39 ), SemanticTokenType .PROPERTY ), // variable
23
-
24
- SemanticToken (range(4 , 12 , 4 , 16 ), SemanticTokenType .CLASS , setOf (SemanticTokenModifier .DECLARATION )), // Type
25
- SemanticToken (range(4 , 21 , 4 , 29 ), SemanticTokenType .PARAMETER , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // property
26
- SemanticToken (range(4 , 31 , 4 , 34 ), SemanticTokenType .CLASS ), // Int
27
-
28
- SemanticToken (range(6 , 5 , 6 , 6 ), SemanticTokenType .FUNCTION , setOf (SemanticTokenModifier .DECLARATION )), // f
29
- SemanticToken (range(6 , 7 , 6 , 8 ), SemanticTokenType .PARAMETER , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // x
30
- SemanticToken (range(6 , 10 , 6 , 13 ), SemanticTokenType .CLASS ), // Int?
31
- SemanticToken (range(6 , 24 , 6 , 27 ), SemanticTokenType .CLASS ), // Int
32
- SemanticToken (range(6 , 30 , 6 , 31 ), SemanticTokenType .FUNCTION ), // f
33
- SemanticToken (range(6 , 32 , 6 , 33 ), SemanticTokenType .VARIABLE , setOf (SemanticTokenModifier .READONLY )), // x
18
+ val expectedVar = encodeTokens(sequenceOf(
19
+ SemanticToken (range(varLine, 5 , varLine, 13 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION )), // variable
20
+ ))
21
+ val expectedConst = encodeTokens(sequenceOf(
22
+ SemanticToken (range(constLine, 5 , constLine, 13 ), SemanticTokenType .PROPERTY , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // constant
23
+ SemanticToken (range(constLine, 15 , constLine, 21 ), SemanticTokenType .CLASS ), // String
24
+ SemanticToken (range(constLine, 24 , constLine, 40 ), SemanticTokenType .STRING ), // "test $variable"
25
+ SemanticToken (range(constLine, 30 , constLine, 39 ), SemanticTokenType .INTERPOLATION_ENTRY ), // $variable
26
+ SemanticToken (range(constLine, 31 , constLine, 39 ), SemanticTokenType .PROPERTY ), // variable
34
27
))
28
+ val expectedClass = encodeTokens(sequenceOf(
29
+ SemanticToken (range(classLine, 12 , classLine, 16 ), SemanticTokenType .CLASS , setOf (SemanticTokenModifier .DECLARATION )), // Type
30
+ SemanticToken (range(classLine, 21 , classLine, 29 ), SemanticTokenType .PARAMETER , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // property
31
+ SemanticToken (range(classLine, 31 , classLine, 34 ), SemanticTokenType .CLASS ), // Int
32
+ ))
33
+ val expectedFun = encodeTokens(sequenceOf(
34
+ SemanticToken (range(funLine, 5 , funLine, 6 ), SemanticTokenType .FUNCTION , setOf (SemanticTokenModifier .DECLARATION )), // f
35
+ SemanticToken (range(funLine, 7 , funLine, 8 ), SemanticTokenType .PARAMETER , setOf (SemanticTokenModifier .DECLARATION , SemanticTokenModifier .READONLY )), // x
36
+ SemanticToken (range(funLine, 10 , funLine, 13 ), SemanticTokenType .CLASS ), // Int?
37
+ SemanticToken (range(funLine, 24 , funLine, 27 ), SemanticTokenType .CLASS ), // Int
38
+ SemanticToken (range(funLine, 30 , funLine, 31 ), SemanticTokenType .FUNCTION ), // f
39
+ SemanticToken (range(funLine, 32 , funLine, 33 ), SemanticTokenType .VARIABLE , setOf (SemanticTokenModifier .READONLY )), // x
40
+ ))
41
+
42
+ val partialExpected = expectedConst + expectedClass
43
+ val partialResponse = languageServer.textDocumentService.semanticTokensRange(semanticTokensRangeParams(file, range(constLine, 0 , classLine + 1 , 0 ))).get()!!
44
+ // DEBUG
45
+ println (partialExpected)
46
+ println (partialResponse.data)
47
+ assertThat(partialResponse.data, contains(* partialExpected.toTypedArray()))
35
48
36
- assertThat(actual, contains(* expected.toTypedArray()))
49
+ val fullExpected = expectedVar + expectedConst + expectedClass + expectedFun
50
+ val fullResponse = languageServer.textDocumentService.semanticTokensFull(semanticTokensParams(file)).get()!!
51
+ assertThat(fullResponse.data, contains(* fullExpected.toTypedArray()))
37
52
}
38
53
}
0 commit comments