@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
2020import org.jetbrains.kotlin.resolve.scopes.LexicalScope
2121import org.jetbrains.kotlin.types.KotlinType
2222import org.eclipse.lsp4j.Location
23+ import java.nio.file.Path
2324import java.nio.file.Paths
2425
2526class CompiledFile (
@@ -32,6 +33,8 @@ class CompiledFile(
3233 val isScript : Boolean = false ,
3334 val kind : CompilationKind = CompilationKind .DEFAULT
3435) {
36+ val path: Path by lazy { parse.containingFile.toPath() }
37+
3538 /* *
3639 * Find the type of the expression at `cursor`
3740 */
@@ -86,7 +89,7 @@ class CompiledFile(
8689 private fun referenceFromContext (cursor : Int , context : BindingContext ): Pair <KtExpression , DeclarationDescriptor >? {
8790 val targets = context.getSliceContents(BindingContext .REFERENCE_TARGET )
8891 return targets.asSequence()
89- .filter { cursor in it.key.textRange }
92+ .filter { cursor in it.key.textRange && it.key.containingFile.toPath() == path }
9093 .sortedBy { it.key.textRange.length }
9194 .map { it.toPair() }
9295 .firstOrNull()
@@ -222,7 +225,11 @@ class CompiledFile(
222225 fun scopeAtPoint (cursor : Int ): LexicalScope ? {
223226 val oldCursor = oldOffset(cursor)
224227 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+ }
226233 .sortedBy { it.key.textRange.length }
227234 .map { it.value }
228235 .firstOrNull()
0 commit comments