codeintel: Lower lsifstore Ranges memory usage
Created by: efritz
Fixes https://github.com/sourcegraph/sourcegraph/issues/18247. The current Ranges implementation gathers all the ranges that intersect the given window of lines, extracts each definition and result id, queries all related locations, then inverts the location results to be keyed on range.
The implementation post-filters the reference locations that do not occur within the source document. This PR ensures that we don't build a map containing reference locations in external documents. This also reduces the number of total database queries we need to make.