@@ -4,6 +4,7 @@ import org.eclipse.lsp4j.Location
4
4
import org.eclipse.lsp4j.Range
5
5
import java.nio.file.Path
6
6
import org.javacs.kt.CompiledFile
7
+ import org.javacs.kt.CompilerClassPath
7
8
import org.javacs.kt.LOG
8
9
import org.javacs.kt.ExternalSourcesConfiguration
9
10
import org.javacs.kt.externalsources.ClassContentProvider
@@ -18,6 +19,8 @@ import org.javacs.kt.util.parseURI
18
19
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
19
20
import org.jetbrains.kotlin.psi.KtNamedDeclaration
20
21
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
22
+ import java.io.File
23
+ import java.nio.file.Paths
21
24
22
25
private val cachedTempFiles = mutableMapOf<KlsURI , Path >()
23
26
private val definitionPattern = Regex (" (?:class|interface|object|fun)\\ s+(\\ w+)" )
@@ -27,7 +30,8 @@ fun goToDefinition(
27
30
cursor : Int ,
28
31
classContentProvider : ClassContentProvider ,
29
32
tempDir : TemporaryDirectory ,
30
- config : ExternalSourcesConfiguration
33
+ config : ExternalSourcesConfiguration ,
34
+ cp : CompilerClassPath
31
35
): Location ? {
32
36
val (_, target) = file.referenceExpressionAtPoint(cursor) ? : return null
33
37
@@ -42,7 +46,7 @@ fun goToDefinition(
42
46
if (destination != null ) {
43
47
val rawClassURI = destination.uri
44
48
45
- if (isInsideArchive(rawClassURI)) {
49
+ if (isInsideArchive(rawClassURI, cp )) {
46
50
parseURI(rawClassURI).toKlsURI()?.let { klsURI ->
47
51
val (klsSourceURI, content) = classContentProvider.contentOf(klsURI)
48
52
@@ -86,4 +90,7 @@ fun goToDefinition(
86
90
return destination
87
91
}
88
92
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