lsp/sema: analyse struct method bodies (record their references)

analyzeTopLevelDecl skipped struct_decl entirely, so identifiers used inside method bodies were never recorded as references — find-references (and reference-based features) missed method callers. Each method body is now analysed in its own scope. Verified: references to generate_legal_moves now include game.sx's call inside update_valid_targets.
This commit is contained in:
agra
2026-05-31 11:55:58 +03:00
parent 28e02a8372
commit 4f7d4b7725

View File

@@ -690,7 +690,20 @@ pub const Analyzer = struct {
try self.analyzeNode(val);
}
},
.enum_decl, .struct_decl, .union_decl, .array_type_expr, .slice_type_expr, .array_literal, .parameterized_type_expr, .index_expr, .slice_expr, .insert_expr, .ufcs_alias => {},
.struct_decl => |sd| {
// Analyse method bodies (each in its own scope) so identifiers
// used inside them are recorded as references.
for (sd.methods) |mnode| {
if (mnode.data == .fn_decl) {
const m = mnode.data.fn_decl;
try self.pushScope();
try self.analyzeParams(m.params);
try self.analyzeNode(m.body);
self.popScope();
}
}
},
.enum_decl, .union_decl, .array_type_expr, .slice_type_expr, .array_literal, .parameterized_type_expr, .index_expr, .slice_expr, .insert_expr, .ufcs_alias => {},
.namespace_decl => |ns| {
try self.pushScope();
for (ns.decls) |d| {