@@ -4,22 +4,22 @@ import com.google.gson.Gson
4
4
import org.eclipse.lsp4j.ExecuteCommandParams
5
5
import org.eclipse.lsp4j.Position
6
6
import org.eclipse.lsp4j.Range
7
+ import org.eclipse.lsp4j.TextDocumentIdentifier
7
8
import org.junit.Test
8
9
import org.junit.Assert.assertEquals
9
10
import org.junit.Assert.assertNotNull
10
11
import org.junit.Assert.assertNull
11
- import org.javacs.kt.command.RESOLVE_MAIN
12
12
13
13
class NoMainResolve : SingleFileTestFixture (" resolvemain" , " NoMain.kt" ) {
14
14
@Test
15
15
fun `Should not find any main class info` () {
16
16
val root = testResourcesRoot().resolve(workspaceRoot)
17
- val executeCommandParams = ExecuteCommandParams ( RESOLVE_MAIN , listOf ( Gson ().toJsonTree( root.resolve(file).toUri().toString(), )) )
17
+ val fileUri = root.resolve(file).toUri().toString()
18
18
19
- val commandResult = languageServer.workspaceService.executeCommand(executeCommandParams ).get()
19
+ val result = languageServer.getProtocolExtensionService().mainClass( TextDocumentIdentifier (fileUri) ).get()
20
20
21
- assertNotNull(commandResult )
22
- val mainInfo = commandResult as Map <String , String >
21
+ assertNotNull(result )
22
+ val mainInfo = result as Map <String , String >
23
23
assertNull(mainInfo[" mainClass" ])
24
24
assertEquals(root.toString(), mainInfo[" projectRoot" ])
25
25
}
@@ -30,12 +30,12 @@ class SimpleMainResolve : SingleFileTestFixture("resolvemain", "Simple.kt") {
30
30
@Test
31
31
fun `Should resolve correct main class of simple file` () {
32
32
val root = testResourcesRoot().resolve(workspaceRoot)
33
- val executeCommandParams = ExecuteCommandParams ( RESOLVE_MAIN , listOf ( Gson ().toJsonTree( root.resolve(file).toUri().toString())) )
33
+ val fileUri = root.resolve(file).toUri().toString()
34
34
35
- val commandResult = languageServer.workspaceService.executeCommand(executeCommandParams ).get()
35
+ val result = languageServer.getProtocolExtensionService().mainClass( TextDocumentIdentifier (fileUri) ).get()
36
36
37
- assertNotNull(commandResult )
38
- val mainInfo = commandResult as Map <String , Any >
37
+ assertNotNull(result )
38
+ val mainInfo = result as Map <String , Any >
39
39
assertEquals(" test.SimpleKt" , mainInfo[" mainClass" ])
40
40
assertEquals(Range (Position (2 , 0 ), Position (4 , 1 )), mainInfo[" range" ])
41
41
assertEquals(root.toString(), mainInfo[" projectRoot" ])
@@ -47,12 +47,12 @@ class JvmNameAnnotationMainResolve : SingleFileTestFixture("resolvemain", "JvmNa
47
47
@Test
48
48
fun `Should resolve correct main class of file annotated with JvmName` () {
49
49
val root = testResourcesRoot().resolve(workspaceRoot)
50
- val executeCommandParams = ExecuteCommandParams ( RESOLVE_MAIN , listOf ( Gson ().toJsonTree( root.resolve(file).toUri().toString())) )
50
+ val fileUri = root.resolve(file).toUri().toString()
51
51
52
- val commandResult = languageServer.workspaceService.executeCommand(executeCommandParams ).get()
52
+ val result = languageServer.getProtocolExtensionService().mainClass( TextDocumentIdentifier (fileUri) ).get()
53
53
54
- assertNotNull(commandResult )
55
- val mainInfo = commandResult as Map <String , Any >
54
+ assertNotNull(result )
55
+ val mainInfo = result as Map <String , Any >
56
56
assertEquals(" com.mypackage.name.Potato" , mainInfo[" mainClass" ])
57
57
assertEquals(Range (Position (5 , 0 ), Position (7 , 1 )), mainInfo[" range" ])
58
58
assertEquals(root.toString(), mainInfo[" projectRoot" ])
@@ -63,12 +63,12 @@ class CompanionObjectMainResolve : SingleFileTestFixture("resolvemain", "Compani
63
63
@Test
64
64
fun `Should resolve correct main class of main function inside companion object` () {
65
65
val root = testResourcesRoot().resolve(workspaceRoot)
66
- val executeCommandParams = ExecuteCommandParams ( RESOLVE_MAIN , listOf ( Gson ().toJsonTree( root.resolve(file).toUri().toString())) )
66
+ val fileUri = root.resolve(file).toUri().toString()
67
67
68
- val commandResult = languageServer.workspaceService.executeCommand(executeCommandParams ).get()
68
+ val result = languageServer.getProtocolExtensionService().mainClass( TextDocumentIdentifier (fileUri) ).get()
69
69
70
- assertNotNull(commandResult )
71
- val mainInfo = commandResult as Map <String , Any >
70
+ assertNotNull(result )
71
+ val mainInfo = result as Map <String , Any >
72
72
assertEquals(" test.my.companion.SweetPotato" , mainInfo[" mainClass" ])
73
73
assertEquals(Range (Position (8 , 8 ), Position (11 , 9 )), mainInfo[" range" ])
74
74
assertEquals(root.toString(), mainInfo[" projectRoot" ])
0 commit comments