lsp/eval: Correct usages for import specs
package x
import "y.com/z"
out: fun(z)
If we ask for the usages of either `z` on line 3, or `y.com/z" on line
2, the same thing happens: we look for usages of the import. This does
correctly find the `z` on line 3, but the way it traverses up the
evaluation tree also means it reaches the top-level pkg navigable, which
means it's marked as escaping from the pkg and so other pkgs in the same
module then get searched and evaluated.
This behaviour is correct except for imports. Imports do not get
automatically exported by the current pkg. So we need to detect this
situation and make sure we cannot consider it escaped from the current
pkg.
The old behaviour wouldn't result in the wrong results, it would just do
unnecessary work. The new code is already exercised by the existing
tests (checked with code coverage). Adding a dedicated test to check
that in this scenario we do not regress and perform extra work would be
extremely difficult, as there's no sensible way to observe the amount of
work done.
Signed-off-by: Matthew Sackman <matthew@cue.works>
Change-Id: I68c84ec3251ca568370a9710fe3722d9ce0f0fa4
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1228807
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>