Skip to content

Commit 36e127c

Browse files
committed
fix(extract): Class node lines property always 0
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>
1 parent 3d4236e commit 36e127c

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎internal/cbm/extract_defs.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,7 @@ static void extract_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
33233323
def.file_path = ctx->rel_path;
33243324
def.start_line = ts_node_start_point(node).row + TS_LINE_OFFSET;
33253325
def.end_line = ts_node_end_point(node).row + TS_LINE_OFFSET;
3326+
def.lines = (int)(def.end_line - def.start_line + TS_LINE_OFFSET);
33263327
def.is_exported = cbm_is_exported(name, ctx->language);
33273328
def.base_classes = extract_base_classes(a, node, ctx->source, ctx->language);
33283329
def.decorators = extract_decorators(a, node, ctx->source, ctx->language, spec);

‎tests/test_incremental.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,19 @@ TEST(tool_qg_defines_method_more_than_10) {
964964
PASS();
965965
}
966966

967+
TEST(tool_qg_class_lines_nonzero) {
968+
double ms;
969+
char *r =
970+
call_tool_timed("query_graph", &ms,
971+
"{\"project\":\"%s\","
972+
"\"query\":\"MATCH (c:Class) WHERE c.lines > 0 RETURN count(c) AS n\"}",
973+
g_project);
974+
TOOL_OK(r, ms);
975+
ASSERT(strstr(r, "\"0\"") == NULL);
976+
free(r);
977+
PASS();
978+
}
979+
967980
TEST(tool_list_projects_has_current) {
968981
double ms;
969982
char *r = call_tool_timed("list_projects", &ms, "{}");
@@ -3105,6 +3118,7 @@ SUITE(incremental) {
31053118
RUN_TEST(tool_qg_handles);
31063119
RUN_TEST(tool_qg_defines_method);
31073120
RUN_TEST(tool_qg_defines_method_more_than_10);
3121+
RUN_TEST(tool_qg_class_lines_nonzero);
31083122
RUN_TEST(tool_qg_no_limit);
31093123
RUN_TEST(tool_qg_empty_result);
31103124

0 commit comments

Comments
 (0)