Skip to content

Commit 39cd23e

Browse files
committed
Merge pull request #372 from lsp4j-0.14
2 parents f6b0638 + b0f06de commit 39cd23e

File tree

9 files changed

+92
-19
lines changed

9 files changed

+92
-19
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
projectVersion=1.3.2
22
kotlinVersion=1.6.10
33
exposedVersion=0.37.3
4-
lsp4jVersion=0.12.0
4+
lsp4jVersion=0.14.0
55
javaVersion=11

server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class KotlinTextDocumentService(
156156
TODO("not implemented")
157157
}
158158

159+
@Suppress("DEPRECATION")
159160
override fun documentSymbol(params: DocumentSymbolParams): CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> = async.compute {
160161
LOG.info("Find symbols in {}", describeURI(params.textDocument.uri))
161162

server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.javacs.kt
22

3-
import com.intellij.openapi.project.Project
43
import org.eclipse.lsp4j.*
54
import org.eclipse.lsp4j.services.WorkspaceService
65
import org.eclipse.lsp4j.services.LanguageClient
@@ -9,12 +8,9 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either
98
import org.javacs.kt.symbols.workspaceSymbols
109
import org.javacs.kt.command.JAVA_TO_KOTLIN_COMMAND
1110
import org.javacs.kt.j2k.convertJavaToKotlin
12-
import org.javacs.kt.KotlinTextDocumentService
1311
import org.javacs.kt.position.extractRange
1412
import org.javacs.kt.util.filePath
1513
import org.javacs.kt.util.parseURI
16-
import org.javacs.kt.resolve.resolveMain
17-
import java.net.URI
1814
import java.nio.file.Paths
1915
import java.util.concurrent.CompletableFuture
2016
import com.google.gson.JsonElement
@@ -30,7 +26,7 @@ class KotlinWorkspaceService(
3026
) : WorkspaceService, LanguageClientAware {
3127
private val gson = Gson()
3228
private var languageClient: LanguageClient? = null
33-
29+
3430
override fun connect(client: LanguageClient): Unit {
3531
languageClient = client
3632
}
@@ -143,10 +139,11 @@ class KotlinWorkspaceService(
143139
LOG.info("Updated configuration: {}", settings)
144140
}
145141

146-
override fun symbol(params: WorkspaceSymbolParams): CompletableFuture<List<SymbolInformation>> {
142+
@Suppress("DEPRECATION")
143+
override fun symbol(params: WorkspaceSymbolParams): CompletableFuture<Either<List<SymbolInformation>, List<WorkspaceSymbol>>> {
147144
val result = workspaceSymbols(params.query, sp)
148145

149-
return CompletableFuture.completedFuture(result)
146+
return CompletableFuture.completedFuture(Either.forRight(result))
150147
}
151148

152149
override fun didChangeWorkspaceFolders(params: DidChangeWorkspaceFoldersParams) {

server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package org.javacs.kt.symbols
24

35
import com.intellij.psi.PsiElement
4-
import org.eclipse.lsp4j.Location
56
import org.eclipse.lsp4j.SymbolInformation
67
import org.eclipse.lsp4j.SymbolKind
78
import org.eclipse.lsp4j.DocumentSymbol
9+
import org.eclipse.lsp4j.WorkspaceSymbol
10+
import org.eclipse.lsp4j.WorkspaceSymbolLocation
811
import org.eclipse.lsp4j.jsonrpc.messages.Either
912
import org.javacs.kt.SourcePath
1013
import org.javacs.kt.position.range
@@ -15,7 +18,7 @@ import org.jetbrains.kotlin.psi.*
1518
import org.jetbrains.kotlin.psi.psiUtil.parents
1619

1720
fun documentSymbols(file: KtFile): List<Either<SymbolInformation, DocumentSymbol>> =
18-
doDocumentSymbols(file).map { Either.forRight<SymbolInformation, DocumentSymbol>(it) }
21+
doDocumentSymbols(file).map { Either.forRight(it) }
1922

2023
private fun doDocumentSymbols(element: PsiElement): List<DocumentSymbol> {
2124
val children = element.children.flatMap(::doDocumentSymbols)
@@ -30,10 +33,10 @@ private fun doDocumentSymbols(element: PsiElement): List<DocumentSymbol> {
3033
} ?: children
3134
}
3235

33-
fun workspaceSymbols(query: String, sp: SourcePath): List<SymbolInformation> =
36+
fun workspaceSymbols(query: String, sp: SourcePath): List<WorkspaceSymbol> =
3437
doWorkspaceSymbols(sp)
3538
.filter { containsCharactersInOrder(it.name!!, query, false) }
36-
.mapNotNull(::symbolInformation)
39+
.mapNotNull(::workspaceSymbol)
3740
.toList()
3841

3942
private fun doWorkspaceSymbols(sp: SourcePath): Sequence<KtNamedDeclaration> =
@@ -53,10 +56,10 @@ private fun pickImportantElements(node: PsiElement, includeLocals: Boolean): KtN
5356
else -> null
5457
}
5558

56-
private fun symbolInformation(d: KtNamedDeclaration): SymbolInformation? {
59+
private fun workspaceSymbol(d: KtNamedDeclaration): WorkspaceSymbol? {
5760
val name = d.name ?: return null
5861

59-
return SymbolInformation(name, symbolKind(d), symbolLocation(d), symbolContainer(d))
62+
return WorkspaceSymbol(name, symbolKind(d), Either.forRight(workspaceLocation(d)), symbolContainer(d))
6063
}
6164

6265
private fun symbolKind(d: KtNamedDeclaration): SymbolKind =
@@ -70,12 +73,11 @@ private fun symbolKind(d: KtNamedDeclaration): SymbolKind =
7073
else -> throw IllegalArgumentException("Unexpected symbol $d")
7174
}
7275

73-
private fun symbolLocation(d: KtNamedDeclaration): Location {
76+
private fun workspaceLocation(d: KtNamedDeclaration): WorkspaceSymbolLocation {
7477
val file = d.containingFile
7578
val uri = file.toPath().toUri().toString()
76-
val range = range(file.text, d.textRange)
7779

78-
return Location(uri, range)
80+
return WorkspaceSymbolLocation(uri)
7981
}
8082

8183
private fun symbolContainer(d: KtNamedDeclaration): String? =

server/src/test/kotlin/org/javacs/kt/ClassPathTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ class ClassPathTest {
2828
assertThat(classPath, hasItem(containsString("junit")))
2929
}
3030

31+
@Test fun `find maven classpath`() {
32+
val workspaceRoot = testResourcesRoot().resolve("mavenWorkspace")
33+
val buildFile = workspaceRoot.resolve("pom.xml")
34+
35+
assertTrue(Files.exists(buildFile))
36+
37+
val resolvers = defaultClassPathResolver(listOf(workspaceRoot))
38+
print(resolvers)
39+
val classPath = resolvers.classpathOrEmpty.map { it.toString() }
40+
41+
assertThat(classPath, hasItem(containsString("junit")))
42+
}
43+
3144
@Test fun `find kotlin stdlib`() {
3245
assertThat(findKotlinStdlib(), notNullValue())
3346
}

server/src/test/kotlin/org/javacs/kt/WorkspaceSymbolsTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import org.eclipse.lsp4j.WorkspaceSymbolParams
55
import org.hamcrest.Matchers.hasItem
66
import org.hamcrest.Matchers.not
77
import org.junit.Assert.assertThat
8-
import org.junit.Before
98
import org.junit.Test
109

1110
class WorkspaceSymbolsTest : SingleFileTestFixture("symbols", "DocumentSymbols.kt") {
1211
@Test fun `find symbols in OtherFileSymbols`() {
13-
val found = languageServer.workspaceService.symbol(WorkspaceSymbolParams("")).get()
12+
val found = languageServer.workspaceService.symbol(WorkspaceSymbolParams("")).get().right
1413
val byKind = found.groupBy({ it.kind }, { it.name })
1514
val all = found.map { it.name }.toList()
1615

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.example</groupId>
5+
<artifactId>test-project</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>test-project</name>
9+
<url>http://maven.apache.org</url>
10+
<dependencies>
11+
<dependency>
12+
<groupId>junit</groupId>
13+
<artifactId>junit</artifactId>
14+
<version>3.8.1</version>
15+
<scope>test</scope>
16+
</dependency>
17+
</dependencies>
18+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.example;
2+
3+
/**
4+
* Hello world!
5+
*/
6+
public class App {
7+
public static void main(String[] args) {
8+
System.out.println("Hello World!");
9+
}
10+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.example;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest extends TestCase {
11+
/**
12+
* Create the test case
13+
*
14+
* @param testName name of the test case
15+
*/
16+
public AppTest(String testName) {
17+
super(testName);
18+
}
19+
20+
/**
21+
* @return the suite of tests being tested
22+
*/
23+
public static Test suite() {
24+
return new TestSuite(AppTest.class);
25+
}
26+
27+
/**
28+
* Rigorous Test :-)
29+
*/
30+
public void testApp() {
31+
assertTrue(true);
32+
}
33+
}

0 commit comments

Comments
 (0)