Problem
handleCallers (src/mcp.zig) filters non-code languages, comment/blank lines, the definition site, substring matches, and — since the string-literal fix — quoted-only mentions. But isCommentOrBlank only rejects lines that start as comments, and hasWholeWordMatchOutsideStrings skips string literals only. A code line whose only mention of the symbol sits in a trailing comment passes every filter and is reported as a call site:
init(); // then renderX() draws the frame
codedb_callers renderX reports this line as a caller of renderX, though nothing on it invokes the symbol. Same shape as the string-literal false positives fixed in c23995e, one filter over.
Failing Test
Fails on current main (zig build test-mcp: 178/183, this test the only failure):
test "issue-XX: codedb_callers excludes a symbol mentioned only in a trailing comment" {
var arena = std.heap.ArenaAllocator.init(testing.allocator);
defer arena.deinit();
var out: std.ArrayList(u8) = .empty;
defer out.deinit(testing.allocator);
try renderCallersFixture(arena.allocator(), &.{
.{ "trail.zig", "pub fn callerA() void {\n init(); // then renderX() draws the frame\n}\n" },
.{ "call.zig", "pub fn callerB() void {\n renderX();\n}\n" },
}, "renderX", &out);
try testing.expect(std.mem.indexOf(u8, out.items, "1 call sites for 'renderX'") != null);
try testing.expect(std.mem.indexOf(u8, out.items, "trail.zig:2") == null);
try testing.expect(std.mem.indexOf(u8, out.items, "call.zig:2") != null);
}
Expected
1 call sites for 'renderX' — only call.zig:2. The trailing-comment mention is documentation, not an invocation.
Fix
Extend the line-local scan to stop at a language-appropriate line-comment marker outside string literals (// for the C family/Zig/Rust/Go/TS, # for Python/Ruby/shell, -- for SQL, etc. — same language table isCommentOrBlank uses) before anchoring whole-word matches, so hasWholeWordMatchOutsideStrings only sees the code prefix of the line. Careful with :// in URLs inside strings (already skipped as string spans) and with # in Zig/C where it is not a comment.
Problem
handleCallers(src/mcp.zig) filters non-code languages, comment/blank lines, the definition site, substring matches, and — since the string-literal fix — quoted-only mentions. ButisCommentOrBlankonly rejects lines that start as comments, andhasWholeWordMatchOutsideStringsskips string literals only. A code line whose only mention of the symbol sits in a trailing comment passes every filter and is reported as a call site:codedb_callers renderXreports this line as a caller ofrenderX, though nothing on it invokes the symbol. Same shape as the string-literal false positives fixed in c23995e, one filter over.Failing Test
Fails on current main (
zig build test-mcp: 178/183, this test the only failure):Expected
1 call sites for 'renderX'— onlycall.zig:2. The trailing-comment mention is documentation, not an invocation.Fix
Extend the line-local scan to stop at a language-appropriate line-comment marker outside string literals (
//for the C family/Zig/Rust/Go/TS,#for Python/Ruby/shell,--for SQL, etc. — same language tableisCommentOrBlankuses) before anchoring whole-word matches, sohasWholeWordMatchOutsideStringsonly sees the code prefix of the line. Careful with://in URLs inside strings (already skipped as string spans) and with#in Zig/C where it is not a comment.