Skip to content

refactor(extraction): deduplicate verbatim helper copies across language extractors - #203

Merged
ScriptedAlchemy merged 4 commits into
masterfrom
codex/refactor-extractor-dedup
Jul 2, 2026
Merged

refactor(extraction): deduplicate verbatim helper copies across language extractors#203
ScriptedAlchemy merged 4 commits into
masterfrom
codex/refactor-extractor-dedup

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Summary

Audit-driven refactor (item #2 of the latest structural health audit: the extractor duplication family). Deletes the helper functions that were copied verbatim across the ~25 src/extraction/*_extractor.rs modules and replaces them with shared implementations. No behavior change — bodies were moved unchanged, and extraction output was verified byte-identical (see test plan). Net −747 lines (766+/1513−) across 30 files.

One commit per helper family:

  1. Docstring/comment helpers → new extraction::common
    • clean_comment: C-style variant (3 copies: c/go/glsl → clean_c_comment) and ///-aware variant (2 copies: cpp/objc → clean_c_doc_comment)
    • preceding-comment docstring loop (7 copies: c/cpp/go/objc/pascal/glsl + objc's extract_impl_method_docstringdocstring_from_preceding_comments, parameterized by the cleaner)
    • #-comment docstring loop (2 copies: bash/ruby → docstring_from_hash_comments)
  2. extract_call_sitescommon::extract_call_expression_sites (4 verbatim copies: c/cpp/glsl/hlsl; per-language fns remain as thin wrappers over their private ExtractionState)
  3. Traversal helpers → existing extraction::traversal (which was added for exactly this migration and preserves search order)
    • find_child_by_kind (25 verbatim copies → find_direct_child_by_kind)
    • find_descendant_by_kind (4 verbatim copies: glsl/hlsl/objc/wgsl)
    • has_child_kind (2 verbatim copies: glsl/hlsl → has_direct_child_kind)
  4. BASIC subroutine-synthesis helpers → new extraction::basic_common (gwbasic/msbasic2, cfg-gated): BasicLine, find_subroutine_ranges, derive_function_name, and the shared top-level-line filter (for_each_top_level_line)

Near-copies deliberately left unmerged

  • rust_extractor::clean_comment — also strips //! inner doc comments (Rust-specific)
  • pascal_extractor::clean_comment — handles { ... } and (* ... *) Pascal comments; its docstring fn now passes it into the shared loop
  • powershell_extractor::find_descendant_by_kind — iterative and, unlike the deleted copies, matches the start node itself; not a verbatim copy
  • typescript_extractor::has_child_kind — different semantics from the glsl/hlsl copies
  • the remaining per-language extract_call_sites/extract_docstring variants — each keys on language-specific node kinds/fields; unifying them would need per-language parameterization that isn't a natural abstraction
  • follow-up candidate (not in this PR): the per-extractor visit_children dispatch loops (~38 files) could route through traversal::visit_children, but that's a style migration rather than deleting verbatim helper copies

Each extractor keeps its own private ExtractionState, so shared helpers take the pieces they need (source bytes, file path, unresolved-ref sink) rather than the state struct; unifying ExtractionState itself is a separate, larger refactor.

Test plan

  • Byte-identical output check: dumped normalized ExtractionResult JSON for all tests/fixtures/** files plus inline go/scala/hlsl/wgsl snippets (languages without fixtures) on the merge-base and after the refactor — diff clean
  • cargo fmt --all --check
  • cargo clippy --all-targets -- -D warnings
  • cargo check --all-targets
  • cargo nextest run -E 'binary(extraction_suite)' — 689/689 passed
  • Full cargo nextest run --profile ci — 3341/3341 passed

ScriptedAlchemy added 4 commits July 2, 2026 04:34
Move the verbatim extract_docstring / clean_comment copies into a new
extraction::common module: C-style comment cleaning (c/go/glsl), the
///-aware variant (cpp/objc), the preceding-comment docstring loop
(c/cpp/go/objc/pascal/glsl), and the #-comment docstring loop
(bash/ruby). Bodies are moved unchanged; no behavior change.
Replace the four verbatim extract_call_sites copies (c/cpp/glsl/hlsl)
with common::extract_call_expression_sites; the per-language functions
become thin wrappers over their ExtractionState. No behavior change.
Delete the per-extractor copies of find_child_by_kind (25 files),
find_descendant_by_kind (glsl/hlsl/objc/wgsl), and has_child_kind
(glsl/hlsl) in favor of the existing extraction::traversal versions,
which were added for exactly this migration and preserve search order.
PowerShell keeps its iterative find_descendant_by_kind: it also matches
the start node itself, so it is not a verbatim copy. No behavior change.
Move the verbatim gwbasic/msbasic2 copies of BasicLine,
find_subroutine_ranges, and derive_function_name into a new
extraction::basic_common module, and fold the shared top-level-line
filtering of extract_top_level_calls into for_each_top_level_line.
No behavior change.
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ce53aa0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ScriptedAlchemy
ScriptedAlchemy merged commit 53f6e46 into master Jul 2, 2026
14 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the codex/refactor-extractor-dedup branch July 4, 2026 01:13
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.

1 participant