Skip to content

Commit 931ed26

Browse files
committed
Allow exclamation marks on paths
1 parent 2022884 commit 931ed26

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
2828
val sourcePath = SourcePath(classPath, uriContentProvider, config.indexing)
2929
val sourceFiles = SourceFiles(sourcePath, uriContentProvider)
3030

31-
private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider)
31+
private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider, classPath)
3232
private val workspaces = KotlinWorkspaceService(sourceFiles, sourcePath, classPath, textDocuments, config)
3333
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider)
3434

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class KotlinTextDocumentService(
3838
private val sp: SourcePath,
3939
private val config: Configuration,
4040
private val tempDirectory: TemporaryDirectory,
41-
private val uriContentProvider: URIContentProvider
41+
private val uriContentProvider: URIContentProvider,
42+
private val cp: CompilerClassPath
4243
) : TextDocumentService, Closeable {
4344
private lateinit var client: LanguageClient
4445
private val async = AsyncExecutor()
@@ -115,7 +116,7 @@ class KotlinTextDocumentService(
115116
LOG.info("Go-to-definition at {}", describePosition(position))
116117

117118
val (file, cursor) = recover(position, Recompile.NEVER)
118-
goToDefinition(file, cursor, uriContentProvider.classContentProvider, tempDirectory, config.externalSources)
119+
goToDefinition(file, cursor, uriContentProvider.classContentProvider, tempDirectory, config.externalSources, cp)
119120
?.let(::listOf)
120121
?.let { Either.forLeft<List<Location>, List<LocationLink>>(it) }
121122
?: noResult("Couldn't find definition at ${describePosition(position)}", Either.forLeft(emptyList()))

server/src/main/kotlin/org/javacs/kt/definition/GoToDefinition.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.eclipse.lsp4j.Location
44
import org.eclipse.lsp4j.Range
55
import java.nio.file.Path
66
import org.javacs.kt.CompiledFile
7+
import org.javacs.kt.CompilerClassPath
78
import org.javacs.kt.LOG
89
import org.javacs.kt.ExternalSourcesConfiguration
910
import org.javacs.kt.externalsources.ClassContentProvider
@@ -18,6 +19,8 @@ import org.javacs.kt.util.parseURI
1819
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
1920
import org.jetbrains.kotlin.psi.KtNamedDeclaration
2021
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
22+
import java.io.File
23+
import java.nio.file.Paths
2124

2225
private val cachedTempFiles = mutableMapOf<KlsURI, Path>()
2326
private val definitionPattern = Regex("(?:class|interface|object|fun)\\s+(\\w+)")
@@ -27,7 +30,8 @@ fun goToDefinition(
2730
cursor: Int,
2831
classContentProvider: ClassContentProvider,
2932
tempDir: TemporaryDirectory,
30-
config: ExternalSourcesConfiguration
33+
config: ExternalSourcesConfiguration,
34+
cp: CompilerClassPath
3135
): Location? {
3236
val (_, target) = file.referenceExpressionAtPoint(cursor) ?: return null
3337

@@ -42,7 +46,7 @@ fun goToDefinition(
4246
if (destination != null) {
4347
val rawClassURI = destination.uri
4448

45-
if (isInsideArchive(rawClassURI)) {
49+
if (isInsideArchive(rawClassURI, cp)) {
4650
parseURI(rawClassURI).toKlsURI()?.let { klsURI ->
4751
val (klsSourceURI, content) = classContentProvider.contentOf(klsURI)
4852

@@ -86,4 +90,7 @@ fun goToDefinition(
8690
return destination
8791
}
8892

89-
private fun isInsideArchive(uri: String) = uri.contains("!")
93+
private fun isInsideArchive(uri: String, cp: CompilerClassPath) =
94+
uri.contains(".jar!") || uri.contains(".zip!") || cp.javaHome?.let {
95+
Paths.get(parseURI(uri)).toString().startsWith(File(it).path)
96+
} ?: false

0 commit comments

Comments
 (0)