Skip to content

fix(extract): Class.lines always 0 for all languages#449

Open
isc-tdyar wants to merge 1 commit into
DeusData:mainfrom
isc-tdyar:fix/class-lines-zero
Open

fix(extract): Class.lines always 0 for all languages#449
isc-tdyar wants to merge 1 commit into
DeusData:mainfrom
isc-tdyar:fix/class-lines-zero

Conversation

@isc-tdyar

Copy link
Copy Markdown
Contributor

Class.lines always 0 for all languages

Discovered while trying to sort classes by size. Every class node had lines = 0 regardless of actual length.

Root cause

In extract_class_def(), start_line and end_line are correctly set from tree-sitter node positions, but def.lines is never computed — it stays 0 from the memset that zeroes the struct. The equivalent computation exists and is correct in push_method_def():

// push_method_def — correct
def.lines = (int)(def.end_line - def.start_line + TS_LINE_OFFSET);

// extract_class_def — missing this line entirely
// def.lines was always 0

Fix

Add the same one-liner to extract_class_def() after end_line is set. Affects all languages — any tree-sitter grammar that produces class nodes goes through this path.

Regression test

tool_qg_class_lines_nonzero in tests/test_incremental.c — indexes a project in full mode and asserts that at least one class node has lines > 0 via a query_graph tool call. Before the fix this assertion always failed.

@DeusData

Copy link
Copy Markdown
Owner

Thanks for the contribution — CI is fully green here too. Class.lines always being 0 is exactly the kind of quiet quality bug worth fixing; will review when time allows.

@DeusData

Copy link
Copy Markdown
Owner

Thanks @isc-tdyar — this one reviewed clean and is ready to merge, but it now conflicts with main (it shares tests/test_incremental.c with a just-merged PR). Could you rebase on latest main? I'll merge as soon as it's conflict-free. 🙏

@DeusData

Copy link
Copy Markdown
Owner

Thanks @isc-tdyar — the one-line Class.lines fix is correct, but the diff is now stale against main (conflicting; the extraction files moved under recent changes). Could you rebase on latest main? Worth double-checking while you're there that the class-lines path isn't already covered upstream. I'll merge once it's rebased. 🙏

@isc-tdyar isc-tdyar force-pushed the fix/class-lines-zero branch from 2bd71e5 to 378b475 Compare June 23, 2026 22:33
extract_class_def() sets start_line and end_line from the tree-sitter
node span, but left def.lines = 0 (zeroed by memset at function entry).
The equivalent function push_method_def() correctly computes
  def.lines = end_line - start_line + 1
The same one-liner was simply missing from the class extraction path.

This affects all languages — Python, TypeScript, Go, and any other
language where Class nodes are extracted via extract_class_def().

Regression test: after indexing a project, at least one Class node must
have c.lines > 0.

Signed-off-by: Thomas Dyar <tdyar@intersystems.com>
@isc-tdyar isc-tdyar force-pushed the fix/class-lines-zero branch from 378b475 to 36e127c Compare June 23, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants