this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

lsp/eval: rework transitioning through imports

There was duplication in the existing code: import specs would be
processed both during their own evaluation, and when path evaluation led
to an imported package.

This CL avoids that duplication, leading to simplification of path
traversal code (`expandNavigables`), and greater consistency.

Signed-off-by: Matthew Sackman <matthew@cue.works>
Change-Id: I806f834a51031ddc746d01cb90d726a188bcbc57
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1229417
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+18 -25
+18 -25
internal/lsp/eval/eval.go
··· 1032 1032 // For all the packages that import us, find where usages of 1033 1033 // this package appears. 1034 1034 ip := nav.evaluator.ip 1035 - for _, remotePkgDfns := range nav.evaluator.pkgImporters() { 1036 - navsWorklist = append(navsWorklist, remotePkgDfns.initialNavsForImport(ip)...) 1035 + for _, remotePkg := range nav.evaluator.pkgImporters() { 1036 + navsWorklist = append(navsWorklist, remotePkg.initialNavsForImport(ip)...) 1037 1037 } 1038 1038 } 1039 1039 } ··· 1430 1430 1431 1431 nav.eval() 1432 1432 1433 - for _, fr := range nav.frames { 1434 - spec, ok := fr.node.(*ast.ImportSpec) 1435 - if !ok { 1436 - continue 1437 - } 1438 - pkgEval := fr.fileEvaluator.evaluator 1439 - ip := pkgEval.parseImportSpec(spec) 1440 - if ip == nil { 1441 - continue 1442 - } 1443 - pkgEval = pkgEval.forPackage(*ip) 1444 - if pkgEval == nil { 1445 - continue 1446 - } 1447 - pkgFrame := pkgEval.pkgFrame 1448 - pkgFrame.eval() 1449 - for _, fileFr := range pkgFrame.childFrames { 1450 - worklist = append(worklist, fileFr.navigable) 1451 - } 1452 - } 1453 - 1454 1433 worklist = slices.AppendSeq(worklist, maps.Keys(nav.resolvesTo)) 1455 1434 } 1456 1435 return navsSet ··· 1716 1695 remotePkgEvaluator = New(ast.ImportPath{}, nil, nil, nil) 1717 1696 } 1718 1697 1719 - // We add a path that records that the name of this import 1720 - // spec resolves to the remote package. 1698 + // DefinitionsForOffset always traverses a path, so here 1699 + // we add a path so that DefinitionsForOffset on this 1700 + // import spec reports the package declarations of the 1701 + // remote pkg. 1721 1702 p := &path{ 1722 1703 frame: f, 1723 1704 components: []pathComponent{{ ··· 1726 1707 }}, 1727 1708 } 1728 1709 f.childPaths = append(f.childPaths, p) 1710 + 1711 + // Any path that actually traverses into the remote pkg 1712 + // can do so by following the resolvesTo of this frame's 1713 + // navigable. Rather than resolving to the remove pkg 1714 + // declarations, we must resolve to the files that make up 1715 + // the remote pkg. 1716 + remotePkgFileFrames := remotePkgEvaluator.pkgFrame.childFrames 1717 + remotePkgNavs := make([]*navigable, len(remotePkgFileFrames)) 1718 + for i, remoteFileFr := range remotePkgFileFrames { 1719 + remotePkgNavs[i] = remoteFileFr.navigable 1720 + } 1721 + f.navigable.ensureResolvesTo(remotePkgNavs) 1729 1722 1730 1723 // We also record that we are using those package 1731 1724 // decls. This means that from the result of resolving the