lsp/eval: Path resolution must force eval of import specs
The LSP evaluator processes import specs super lazily so that linking
the import spec to the remote pkg evaluator is done as late as possible.
Without this, booting an evaluator would also boot every evaluator for
every imported package. And the transitive closure. So everything in the
import graph would get booted, which we don't want.
So the remote pkg evaluator only gets booted when we really pass into
it. E.g.
-- a.cue --
package a
import "b"
x: b.y
-- b.cue --
package b
y: 12
Only when we resolve the `y` of the path `b.y` do we boot pkg `b`.
But this causes a problem because it means that if you use the entire
package (e.g. changing `x: b.y` to just `x: b`) then pkg b never gets
booted and so we would also never record that pkg b is used by pkg a.
This CL fixes this by detecting when a path component resolves to an
ImportSpec and forcing the evaluation at that time. This still should
ensure that we don't fully evaluate import specs too early, but it does
ensure that the "usedBy" of packages is now correct.
The old behaviour was flakey, and for that reason it's not possible to
write a test that shows the bad behaviour. But manually backporting the
new test and running with -count 10 will show Usages being flakey.
Signed-off-by: Matthew Sackman <matthew@cue.works>
Change-Id: I5d02df1a5ccb17a9fd38deb22d0581c9f581e8c6
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1228808
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>