this repo has no description
0
fork

Configure Feed

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

lsp/eval: add support for comprehension else/fallback

This is not perfect, but it's exposed that jump-to-definition sometimes
acts as a "MUST" (i.e. we guarantee that every result is unified
together) and sometimes acts as a "MAY" (i.e. the results may be unified
together depending on other inputs, e.g. a disjunction). This comes to a
head with else/fallback on comprehensions. A better solution will be
developed in time, possibly using other LSP functionality. But for now,
this gets the feature supported albeit imperfectly.

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

+194
+4
internal/lsp/eval/eval.go
··· 1985 1985 case *ast.Comprehension: 1986 1986 clause := node.Clauses[0] 1987 1987 unprocessed = append(unprocessed, clause) 1988 + if fallback := node.Fallback; fallback != nil { 1989 + f.newFrame(fallback.Body, f.navigable) 1990 + } 1988 1991 // We don't know how many child frames we'll need to 1989 1992 // process clause. So we stash whatever remains of this 1990 1993 // comprehension and can later find it once we've finished ··· 2005 2008 // appropriate child/descendant. 2006 2009 nodeCopy := *node 2007 2010 nodeCopy.Clauses = node.Clauses[1:] 2011 + nodeCopy.Fallback = nil 2008 2012 comprehensionsStash[clause] = &nodeCopy 2009 2013 } 2010 2014
+190
internal/lsp/eval/eval_test.go
··· 4514 4514 or1(117): {f: []string{"d"}, e: []string{"a", "c", "x"}}, 4515 4515 }, 4516 4516 }, 4517 + 4518 + { 4519 + // - `else` is used only with single `if` or single `try` clause 4520 + // - `fallback` is used for everything else (multiple clauses, for clauses, combinations) 4521 + name: "Comprehension_Else", 4522 + archive: `-- a.cue -- 4523 + @experiment(try) 4524 + let x = _ 4525 + if true { 4526 + z: _ 4527 + } else { 4528 + a: z 4529 + b: x 4530 + } 4531 + 4532 + for k, v in s { 4533 + z: _ 4534 + } fallback { 4535 + a: k & v 4536 + b: x 4537 + } 4538 + 4539 + try k = true 4540 + let v = true { 4541 + z: _ 4542 + } fallback { 4543 + a: k & v 4544 + b: x 4545 + } 4546 + `, 4547 + expectDefinitions: map[position][]position{ 4548 + // TODO: It's highly doubtful that this is what's really wanted 4549 + ln(6, 1, "z"): {ln(4, 1, "z"), ln(11, 1, "z"), ln(19, 1, "z")}, 4550 + 4551 + ln(7, 1, "x"): {ln(2, 1, "x")}, 4552 + ln(14, 1, "x"): {ln(2, 1, "x")}, 4553 + ln(22, 1, "x"): {ln(2, 1, "x")}, 4554 + 4555 + ln(2, 1, "x"): {self}, 4556 + ln(4, 1, "z"): {self, ln(11, 1, "z"), ln(19, 1, "z")}, 4557 + ln(6, 1, "a"): {self, ln(13, 1, "a"), ln(21, 1, "a")}, 4558 + ln(7, 1, "b"): {self, ln(14, 1, "b"), ln(22, 1, "b")}, 4559 + 4560 + ln(10, 1, "k"): {self}, 4561 + ln(10, 1, "v"): {self}, 4562 + ln(11, 1, "z"): {self, ln(4, 1, "z"), ln(19, 1, "z")}, 4563 + ln(13, 1, "a"): {self, ln(6, 1, "a"), ln(21, 1, "a")}, 4564 + ln(14, 1, "b"): {self, ln(7, 1, "b"), ln(22, 1, "b")}, 4565 + 4566 + ln(17, 1, "k"): {self}, 4567 + ln(18, 1, "v"): {self}, 4568 + ln(19, 1, "z"): {self, ln(4, 1, "z"), ln(11, 1, "z")}, 4569 + ln(21, 1, "a"): {self, ln(6, 1, "a"), ln(13, 1, "a")}, 4570 + ln(22, 1, "b"): {self, ln(7, 1, "b"), ln(14, 1, "b")}, 4571 + }, 4572 + expectCompletions: map[offsetRange]fieldEmbedCompletions{ 4573 + or(16, 25): {f: []string{"a", "b", "z"}}, 4574 + or(25, 27): {e: []string{"x"}}, 4575 + or(27, 30): {f: []string{"a", "b", "z"}}, 4576 + or1(34): {e: []string{"x"}}, 4577 + or(35, 38): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4578 + or(38, 40): {f: []string{"a", "b", "z"}}, 4579 + or(40, 43): {e: []string{"x", "z"}}, 4580 + or1(43): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4581 + or(45, 50): {f: []string{"a", "b", "z"}}, 4582 + or(50, 53): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4583 + or(53, 55): {f: []string{"a", "b", "z"}}, 4584 + or(55, 58): {e: []string{"a", "b", "x"}}, 4585 + or1(58): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4586 + or(59, 61): {f: []string{"a", "b", "z"}}, 4587 + or(61, 64): {e: []string{"a", "b", "x"}}, 4588 + or1(64): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4589 + or(66, 71): {f: []string{"a", "b", "z"}}, 4590 + or1(73): {e: []string{"x"}}, 4591 + or(76, 81): {e: []string{"k", "x"}}, 4592 + or(81, 84): {f: []string{"a", "b", "z"}, e: []string{"k", "v", "x"}}, 4593 + or(84, 86): {f: []string{"a", "b", "z"}}, 4594 + or(86, 89): {e: []string{"k", "v", "x", "z"}}, 4595 + or1(89): {f: []string{"a", "b", "z"}, e: []string{"k", "v", "x"}}, 4596 + or(91, 100): {f: []string{"a", "b", "z"}}, 4597 + or(100, 103): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4598 + or(103, 105): {f: []string{"a", "b", "z"}}, 4599 + or(105, 112): {e: []string{"a", "b", "x"}}, 4600 + or1(112): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4601 + or(113, 115): {f: []string{"a", "b", "z"}}, 4602 + or(115, 118): {e: []string{"a", "b", "x"}}, 4603 + or1(118): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4604 + or(120, 125): {f: []string{"a", "b", "z"}}, 4605 + or(127, 129): {e: []string{"x"}}, 4606 + or1(133): {e: []string{"x"}}, 4607 + or(134, 138): {e: []string{"k", "x"}}, 4608 + or(140, 142): {e: []string{"k", "x"}}, 4609 + or1(146): {e: []string{"k", "x"}}, 4610 + or(147, 150): {f: []string{"a", "b", "z"}, e: []string{"k", "v", "x"}}, 4611 + or(150, 152): {f: []string{"a", "b", "z"}}, 4612 + or(152, 155): {e: []string{"k", "v", "x", "z"}}, 4613 + or1(155): {f: []string{"a", "b", "z"}, e: []string{"k", "v", "x"}}, 4614 + or(157, 166): {f: []string{"a", "b", "z"}}, 4615 + or(166, 169): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4616 + or(169, 171): {f: []string{"a", "b", "z"}}, 4617 + or(171, 178): {e: []string{"a", "b", "x"}}, 4618 + or1(178): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4619 + or(179, 181): {f: []string{"a", "b", "z"}}, 4620 + or(181, 184): {e: []string{"a", "b", "x"}}, 4621 + or1(184): {f: []string{"a", "b", "z"}, e: []string{"x"}}, 4622 + }, 4623 + }, 4624 + 4625 + { 4626 + name: "Comprehension_Else_Scopes", 4627 + archive: `-- a.cue -- 4628 + @experiment(try) 4629 + out: { 4630 + if true { 4631 + x: a 4632 + y: b 4633 + c: _ 4634 + d: _ 4635 + } else { 4636 + x: c 4637 + y: d 4638 + a: _ 4639 + b: _ 4640 + } 4641 + b: _ 4642 + d: _ 4643 + } 4644 + `, 4645 + expectDefinitions: map[position][]position{ 4646 + ln(4, 1, "a"): {}, 4647 + ln(5, 1, "b"): {ln(12, 1, "b"), ln(14, 1, "b")}, 4648 + 4649 + ln(9, 1, "c"): {}, 4650 + ln(10, 1, "d"): {ln(7, 1, "d"), ln(15, 1, "d")}, 4651 + 4652 + ln(2, 1, "out"): {self}, 4653 + 4654 + ln(4, 1, "x"): {self, ln(9, 1, "x")}, 4655 + ln(5, 1, "y"): {self, ln(10, 1, "y")}, 4656 + ln(6, 1, "c"): {self}, 4657 + ln(7, 1, "d"): {self, ln(15, 1, "d")}, 4658 + 4659 + ln(9, 1, "x"): {self, ln(4, 1, "x")}, 4660 + ln(10, 1, "y"): {self, ln(5, 1, "y")}, 4661 + ln(11, 1, "a"): {self}, 4662 + ln(12, 1, "b"): {self, ln(14, 1, "b")}, 4663 + 4664 + ln(14, 1, "b"): {self, ln(12, 1, "b")}, 4665 + ln(15, 1, "d"): {self, ln(7, 1, "d")}, 4666 + }, 4667 + expectCompletions: map[offsetRange]fieldEmbedCompletions{ 4668 + or(16, 21): {f: []string{"out"}}, 4669 + or(21, 28): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"out"}}, 4670 + or1(32): {e: []string{"b", "d", "out"}}, 4671 + or(33, 37): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4672 + or(37, 39): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4673 + or(39, 42): {e: []string{"b", "c", "d", "out", "x", "y"}}, 4674 + or(42, 44): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4675 + or(44, 46): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4676 + or(46, 49): {e: []string{"b", "c", "d", "out", "x", "y"}}, 4677 + or(49, 51): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4678 + or(51, 53): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4679 + or(53, 56): {e: []string{"b", "c", "d", "out", "x", "y"}}, 4680 + or(56, 58): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4681 + or(58, 60): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4682 + or(60, 63): {e: []string{"b", "c", "d", "out", "x", "y"}}, 4683 + or(63, 65): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4684 + or(66, 71): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"out"}}, 4685 + or(71, 75): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4686 + or(75, 77): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4687 + or(77, 80): {e: []string{"a", "b", "d", "out", "x", "y"}}, 4688 + or(80, 82): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4689 + or(82, 84): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4690 + or(84, 87): {e: []string{"a", "b", "d", "out", "x", "y"}}, 4691 + or(87, 89): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4692 + or(89, 91): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4693 + or(91, 94): {e: []string{"a", "b", "d", "out", "x", "y"}}, 4694 + or(94, 96): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4695 + or(96, 98): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4696 + or(98, 101): {e: []string{"a", "b", "d", "out", "x", "y"}}, 4697 + or(101, 103): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"b", "d", "out"}}, 4698 + or1(104): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"out"}}, 4699 + or(105, 107): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4700 + or(107, 110): {e: []string{"b", "d", "out"}}, 4701 + or1(110): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"out"}}, 4702 + or(111, 113): {f: []string{"a", "b", "c", "d", "x", "y"}}, 4703 + or(113, 116): {e: []string{"b", "d", "out"}}, 4704 + or1(116): {f: []string{"a", "b", "c", "d", "x", "y"}, e: []string{"out"}}, 4705 + }, 4706 + }, 4517 4707 }.run(t) 4518 4708 } 4519 4709