fwcd / kotlin-language-server

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
MIT License
1.62k stars 203 forks source link

Filter by path when querying `BindingContext` #509

Closed fwcd closed 11 months ago

fwcd commented 11 months ago

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:

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 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:

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.