@@ -276,13 +276,35 @@ pub const Tree = struct {
276276
277277 const suggestions_start = suggestions .items .len ;
278278 log .debug ("tree with {} children" , .{tree .children .items .len });
279-
279+ var struct_end_loc : ? Token.Loc = null ;
280280 while (child_id < tree .children .items .len ) : (child_id += 1 ) {
281281 const field = tree .children .items [child_id ];
282- // valid tokens here are either lb, comma or rb.
283- // we expect syntax errors are already reported.
284- if (field == .token ) continue ;
285-
282+ // log.debug("field {}", .{field});
283+ switch (field ) {
284+ .token = > | t | {
285+ struct_end_loc = t .loc ;
286+ switch (t .tag ) {
287+ .comma , .lb , .rb = > {},
288+ else = > try addErrorCheck (gpa , diag , .{
289+ .unknown_field = .{
290+ .name = field .token .loc .src (ziggy_code ),
291+ .sel = field .token .loc .getSelection (ziggy_code ),
292+ },
293+ }),
294+ }
295+ continue ;
296+ },
297+ .tree = > | field_tree | switch (field_tree .tag ) {
298+ .struct_field = > {},
299+ else = > try addErrorCheck (gpa , diag , .{
300+ .unknown_field = .{
301+ .name = field_tree .loc ().src (ziggy_code ),
302+ .sel = field_tree .loc ().getSelection (ziggy_code ),
303+ },
304+ }),
305+ },
306+ }
307+ // log.debug("field tree {}", .{field.tree.fmt(ziggy_code)});
286308 if (field .tree .children .items .len < 2 ) {
287309 try suggestions .append (.{
288310 .loc = .{
@@ -363,11 +385,11 @@ pub const Tree = struct {
363385 .snippet = v .help .snippet ,
364386 });
365387 }
366- // FIXME: this loc isn't correct for nested
367- // structs, only top level. figure out how
368- // to get parent loc.
369- var dloc = doc . loc () ;
370- dloc . start = dloc . end - | 1 ;
388+ const dloc = struct_end_loc orelse loc : {
389+ var l = doc . loc ();
390+ l . start = l . end - | 1 ;
391+ break : loc l ;
392+ } ;
371393 assert (dloc .start <= dloc .end );
372394 try addErrorCheck (gpa , diag , .{
373395 .missing_field = .{
0 commit comments