Skip to content

[codex] Fix C preprocessor-heavy symbol extraction#579

Merged
buger merged 1 commit into
mainfrom
codex/fix-c-preprocessor-symbols
Jun 26, 2026
Merged

[codex] Fix C preprocessor-heavy symbol extraction#579
buger merged 1 commit into
mainfrom
codex/fix-c-preprocessor-symbols

Conversation

@buger

@buger buger commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #577.
Fixes #578.

This PR hardens C/C++ function extraction for preprocessor-heavy source files and fixes JSON symbol names for C functions.

Root Cause

C tree-sitter function_definition nodes do not expose the function identifier through the generic name field. The generic symbol extractor fell through to the type field, so JSON output reported return types such as void, NORETURN, size_t, and char as function names.

For #ifdef-heavy C bodies, tree-sitter can also fail to expose some function definitions as normal symbol nodes. In the rsync repro, acls.c omitted change_sacl_perms because of nested preprocessor conditionals inside the function body.

Changes

  • Extract C/C++ function names from nested declarator identifiers instead of generic type/name fields.
  • Add C/C++ function signature extraction that stops before the function body.
  • Add a constrained C/C++ function recovery pass for probe symbols so preprocessor-heavy function bodies are still emitted.
  • Reuse that recovery path for C/C++ function-enumeration probe query patterns without widening body-specific queries.
  • Add focused regression tests for the wrong-name bug and the preprocessor-heavy function omission.

Validation

  • cargo test extract::symbols --lib
  • cargo test test_query_c_function_inside_preprocessor_heavy_body --test query_command_tests
  • cargo test test_query_c_recovery_does_not_widen_body_specific_patterns --test query_command_tests
  • cargo check --bin probe
  • cargo test test_c_outline_basic_symbols --test c_outline_format_tests

Manual repro checks against local rsync source:

  • probe symbols --format json io.c now reports check_timeout, whine_about_eof, safe_read, what_fd_is, safe_write instead of return types.
  • probe symbols --format json acls.c now includes change_sacl_perms and does not include earlier fallback false positives such as if or versions.
  • probe query '$RET $NAME($$$PARAMS) { $$$BODY }' acls.c --language c --format json now includes change_sacl_perms.

@buger buger marked this pull request as ready for review June 26, 2026 15:31
@buger buger merged commit cb337f9 into main Jun 26, 2026
1 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant