this repo has no description
0
fork

Configure Feed

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

lsp/eval: fix field-value aliases

a: l={b: _, c: l.b}
d: a.b

`a.b` should resolve to the `b` field declaration within the inner
struct. That was not working because having resolved the `a`, the
navigable reached did not contain any bindings.

Find-references / usages of the `b` field within the inner struct must
be able to traverse past its name-less parent navigable in order to
ensure its parent navigable and frames are evaluated, which ensures the
usedBy field is correctly populated.

A number of different solutions are possible. The one chosen is to make
a frame-only binding for the alias ident `l` to an empty frame, who's
navigable then resolves back to the field's navigable. The alias's expr
is then added to the unprocessed worklist in the normal way. This seems
the most elegant: essentially the alias ident itself is the only thing
treated specially; its expr is just a normal expr within the field. No
changes to usages() and no weird and complex mutual resolvesTo setup is
needed.

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

+24 -12
+3 -1
internal/lsp/eval/eval.go
··· 1939 1939 1940 1940 case *ast.Alias: 1941 1941 // X=e (the old deprecated alias syntax) 1942 - f.newBinding(node.Ident, node.Expr) 1942 + childFr := f.newBinding(node.Ident, nil) 1943 + childFr.navigable.ensureResolvesTo([]*navigable{f.navigable}) 1944 + unprocessed = append(unprocessed, node.Expr) 1943 1945 1944 1946 case *ast.Ellipsis: 1945 1947 childFr := f.newFrame(node.Type, nil)
+21 -11
internal/lsp/eval/eval_test.go
··· 2098 2098 }, 2099 2099 expectCompletions: map[offsetRange]fieldEmbedCompletions{ 2100 2100 or(0, 2): {f: []string{"a"}}, 2101 - or1(2): {e: []string{"a"}}, 2102 - or1(5): {f: []string{"b", "c"}, e: []string{"a", "l"}}, 2101 + or1(2): {f: []string{"b", "c"}, e: []string{"a"}}, 2102 + or(3, 5): {f: []string{"b", "c"}}, 2103 + or1(5): {e: []string{"a"}}, 2103 2104 or(6, 8): {f: []string{"b", "c"}}, 2104 2105 or1(8): {e: []string{"a", "b", "c", "l"}}, 2105 2106 or1(10): {e: []string{"a", "b", "c", "l"}}, 2106 - or1(11): {f: []string{"b", "c"}, e: []string{"a", "l"}}, 2107 + or1(11): {e: []string{"a"}}, 2107 2108 or(12, 14): {f: []string{"b", "c"}}, 2108 2109 or(14, 17): {e: []string{"a", "b", "c", "l"}}, 2109 2110 or(17, 19): {e: []string{"b", "c"}}, 2111 + or1(19): {e: []string{"a"}}, 2110 2112 }, 2111 2113 }, 2112 2114 ··· 2125 2127 }, 2126 2128 expectCompletions: map[offsetRange]fieldEmbedCompletions{ 2127 2129 or(0, 2): {f: []string{"a"}}, 2128 - or1(2): {e: []string{"a"}}, 2130 + or1(2): {f: []string{"b", "c"}, e: []string{"a"}}, 2131 + or(3, 5): {f: []string{"b", "c"}}, 2129 2132 or1(5): {f: []string{"b", "c"}, e: []string{"a", "l"}}, 2130 2133 or(6, 8): {f: []string{"b", "c"}}, 2131 2134 or1(8): {e: []string{"a", "b", "l"}}, ··· 2154 2157 }, 2155 2158 expectCompletions: map[offsetRange]fieldEmbedCompletions{ 2156 2159 or(0, 2): {f: []string{"a"}}, 2157 - or1(2): {e: []string{"a"}}, 2158 - or(5, 7): {f: []string{"b", "c"}, e: []string{"a", "l"}}, 2160 + or1(2): {f: []string{"b", "c"}, e: []string{"a"}}, 2161 + or(3, 5): {f: []string{"b", "c"}}, 2162 + or1(5): {e: []string{"a"}}, 2163 + or1(6): {f: []string{"b", "c"}, e: []string{"a", "l"}}, 2159 2164 or(7, 9): {f: []string{"b", "c"}}, 2160 2165 or1(9): {e: []string{"a", "b", "l"}}, 2161 2166 or1(11): {e: []string{"a", "b", "l"}}, ··· 2163 2168 or(16, 18): {f: []string{"b", "c"}}, 2164 2169 or(18, 21): {e: []string{"a", "c", "l"}}, 2165 2170 or(21, 23): {e: []string{"b", "c"}}, 2166 - or1(24): {e: []string{"a", "l"}}, 2171 + or1(24): {e: []string{"a"}}, 2167 2172 }, 2168 2173 }, 2169 2174 ··· 2178 2183 ln(2, 1, "l"): {}, 2179 2184 ln(2, 1, "b"): {}, 2180 2185 ln(3, 1, "a"): {ln(1, 1, "a")}, 2181 - ln(3, 1, "b"): {}, // This is WRONG it should be {ln(1, 1, "b")}, 2186 + ln(3, 1, "b"): {ln(1, 1, "b")}, 2182 2187 2183 2188 ln(1, 1, "a"): {self}, 2184 2189 ln(1, 1, "l"): {self}, ··· 2189 2194 }, 2190 2195 expectCompletions: map[offsetRange]fieldEmbedCompletions{ 2191 2196 or(0, 2): {f: []string{"a", "c", "d"}}, 2192 - or1(2): {e: []string{"a", "c", "d"}}, 2193 - or1(5): {f: []string{"b"}, e: []string{"a", "c", "d", "l"}}, 2197 + or1(2): {f: []string{"b"}, e: []string{"a", "c", "d"}}, 2198 + or(3, 5): {f: []string{"b"}}, 2199 + or1(5): {e: []string{"a", "c", "d"}}, 2194 2200 or(6, 8): {f: []string{"b"}}, 2195 2201 or1(8): {e: []string{"a", "b", "c", "d", "l"}}, 2196 2202 or1(10): {e: []string{"a", "b", "c", "d", "l"}}, 2203 + or1(11): {e: []string{"a", "c", "d"}}, 2197 2204 or(12, 14): {f: []string{"a", "c", "d"}}, 2198 2205 or(14, 17): {e: []string{"a", "c", "d"}}, 2199 2206 or(19, 21): {f: []string{"a", "c", "d"}}, 2200 2207 or(21, 24): {e: []string{"a", "c", "d"}}, 2208 + or(24, 26): {e: []string{"b"}}, 2201 2209 }, 2202 2210 }, 2203 2211 ··· 2218 2226 or1(2): {e: []string{"a"}}, 2219 2227 or1(5): {e: []string{"a", "n"}}, 2220 2228 or(7, 18): {e: []string{"a", "n"}}, 2221 - or(19, 31): {e: []string{"a", "n"}}, 2229 + or(19, 23): {e: []string{"a", "n"}}, 2230 + or(23, 25): {e: []string{"a"}}, 2231 + or(25, 31): {e: []string{"a", "n"}}, 2222 2232 or(34, 36): {e: []string{"a", "n"}}, 2223 2233 or(49, 51): {e: []string{"a", "n"}}, 2224 2234 },