refactor(extraction): deduplicate verbatim helper copies across language extractors - #203
Merged
Merged
Conversation
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.rsmodules 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:
extraction::commonclean_comment: C-style variant (3 copies: c/go/glsl →clean_c_comment) and///-aware variant (2 copies: cpp/objc →clean_c_doc_comment)extract_impl_method_docstring→docstring_from_preceding_comments, parameterized by the cleaner)#-comment docstring loop (2 copies: bash/ruby →docstring_from_hash_comments)extract_call_sites→common::extract_call_expression_sites(4 verbatim copies: c/cpp/glsl/hlsl; per-language fns remain as thin wrappers over their privateExtractionState)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)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 looppowershell_extractor::find_descendant_by_kind— iterative and, unlike the deleted copies, matches the start node itself; not a verbatim copytypescript_extractor::has_child_kind— different semantics from the glsl/hlsl copiesextract_call_sites/extract_docstringvariants — each keys on language-specific node kinds/fields; unifying them would need per-language parameterization that isn't a natural abstractionvisit_childrendispatch loops (~38 files) could route throughtraversal::visit_children, but that's a style migration rather than deleting verbatim helper copiesEach 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; unifyingExtractionStateitself is a separate, larger refactor.Test plan
ExtractionResultJSON for alltests/fixtures/**files plus inline go/scala/hlsl/wgsl snippets (languages without fixtures) on the merge-base and after the refactor —diffcleancargo fmt --all --checkcargo clippy --all-targets -- -D warningscargo check --all-targetscargo nextest run -E 'binary(extraction_suite)'— 689/689 passedcargo nextest run --profile ci— 3341/3341 passed