Our BindingContexts may span several files, presumably because we compile changed modules in batch and then store the same context across all of these SourceFiles:
This had the unfortunate side effect that the implicit assumption (?) in methods such as CompiledFile.referenceFromContext or scopeAtPoint that all entries are in the same file (and thus that it is sufficient to filter by position within the file), does not hold:
Since other files sometimes contain matching scopes, this would cause definition lookups to occasionally return bogus results since they also included elements at the same position within other files.
Our
BindingContext
s may span several files, presumably because we compile changed modules in batch and then store the same context across all of theseSourceFile
s:https://github.com/fwcd/kotlin-language-server/blob/5aa94dad4ef2e2a56b9f6d2907feff52386cf7bf/server/src/main/kotlin/org/javacs/kt/SourcePath.kt#L221-L233
This had the unfortunate side effect that the implicit assumption (?) in methods such as
CompiledFile.referenceFromContext
orscopeAtPoint
that all entries are in the same file (and thus that it is sufficient to filter by position within the file), does not hold:https://github.com/fwcd/kotlin-language-server/blob/5aa94dad4ef2e2a56b9f6d2907feff52386cf7bf/server/src/main/kotlin/org/javacs/kt/CompiledFile.kt#L86-L93
Since other files sometimes contain matching scopes, this would cause definition lookups to occasionally return bogus results since they also included elements at the same position within other files.
This fixes this by checking the file path too.