@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
20
20
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
21
21
import org.jetbrains.kotlin.types.KotlinType
22
22
import org.eclipse.lsp4j.Location
23
+ import java.nio.file.Path
23
24
import java.nio.file.Paths
24
25
25
26
class CompiledFile (
@@ -32,6 +33,8 @@ class CompiledFile(
32
33
val isScript : Boolean = false ,
33
34
val kind : CompilationKind = CompilationKind .DEFAULT
34
35
) {
36
+ val path: Path by lazy { parse.containingFile.toPath() }
37
+
35
38
/* *
36
39
* Find the type of the expression at `cursor`
37
40
*/
@@ -86,7 +89,7 @@ class CompiledFile(
86
89
private fun referenceFromContext (cursor : Int , context : BindingContext ): Pair <KtExpression , DeclarationDescriptor >? {
87
90
val targets = context.getSliceContents(BindingContext .REFERENCE_TARGET )
88
91
return targets.asSequence()
89
- .filter { cursor in it.key.textRange }
92
+ .filter { cursor in it.key.textRange && it.key.containingFile.toPath() == path }
90
93
.sortedBy { it.key.textRange.length }
91
94
.map { it.toPair() }
92
95
.firstOrNull()
@@ -222,7 +225,11 @@ class CompiledFile(
222
225
fun scopeAtPoint (cursor : Int ): LexicalScope ? {
223
226
val oldCursor = oldOffset(cursor)
224
227
return compile.getSliceContents(BindingContext .LEXICAL_SCOPE ).asSequence()
225
- .filter { it.key.textRange.startOffset <= oldCursor && oldCursor <= it.key.textRange.endOffset }
228
+ .filter {
229
+ it.key.textRange.startOffset <= oldCursor
230
+ && oldCursor <= it.key.textRange.endOffset
231
+ && it.key.containingFile.toPath() == path
232
+ }
226
233
.sortedBy { it.key.textRange.length }
227
234
.map { it.value }
228
235
.firstOrNull()
0 commit comments