Skip to content

Deduplicate repeated language extractor logic via shared helpers#28

Merged
daedalus merged 2 commits into
masterfrom
copilot/deduplicate-code-carefully
May 13, 2026
Merged

Deduplicate repeated language extractor logic via shared helpers#28
daedalus merged 2 commits into
masterfrom
copilot/deduplicate-code-carefully

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

Nine language extractors contained copy-pasted deduplication and union-parsing blocks. Consolidated into two shared helpers in languages/lib/shared.py.

New helpers

  • dedupe_signatures_by_fqname(signatures) — replaces identical seen/unique/sort post-processing blocks across all regex-fallback extractors
  • split_pipe_union_members(type_str) — replaces identical "A | B" splitting logic in parse_union_members() for languages where the implementation is the same

Updated extractors

go, java, javascript, kotlin, rust, swift, ruby, zig, typescript

Left unchanged (intentionally):

  • haskell.pyparse_union_members adds a "->" branch for function types; tree-sitter dedup is per-file inside a recursive walk, not a final pass
  • c.py — dedup block is inside a shared function serving both CExtractor and CppExtractor; parse_union_members returns a singleton with no pipe-splitting

Example

Before (repeated 9×):

seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
    if sig["fqname"] not in seen:
        seen.add(sig["fqname"])
        unique.append(sig)
unique.sort(key=lambda x: x["fqname"])
return unique

After:

return dedupe_signatures_by_fqname(all_funcs)

Summary by Sourcery

Deduplicate shared language extractor logic by introducing reusable helpers and wiring them into multiple language backends.

Enhancements:

  • Introduce shared helpers for signature deduplication and pipe-separated union parsing in the language utilities module.
  • Update Go, Java, JavaScript, Kotlin, Rust, Swift, Ruby, Zig, and TypeScript extractors to use the new shared helpers for consistent behavior and reduced duplication.

Copilot AI and others added 2 commits May 13, 2026 14:34
@daedalus daedalus marked this pull request as ready for review May 13, 2026 14:50
@daedalus daedalus merged commit 7dab800 into master May 13, 2026
1 of 2 checks passed
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 13, 2026

Reviewer's Guide

Refactors multiple language extractors to share common logic for fqname-based signature deduplication and pipe-delimited union type parsing via new helpers in the shared language library.

File-Level Changes

Change Details Files
Introduce shared helpers for fqname-based signature deduplication and pipe-delimited union parsing in the shared language library.
  • Add dedupe_signatures_by_fqname(signatures) to remove duplicate signature dicts by fqname and return results sorted by fqname.
  • Add split_pipe_union_members(type_str) to normalize parsing of "A
B" style union type strings into frozensets of trimmed members.
Refactor regex-based extractors to use the shared fqname deduplication helper instead of inlined loops.
  • Replace inlined seen/unique/set-based deduplication loops with dedupe_signatures_by_fqname(all_funcs) in regex fallback extractors.
  • Ensure behavior remains identical by preserving sort-by-fqname ordering via the helper.
src/impactguard/languages/go.py
src/impactguard/languages/java.py
src/impactguard/languages/javascript.py
src/impactguard/languages/kotlin.py
src/impactguard/languages/ruby.py
src/impactguard/languages/rust.py
src/impactguard/languages/swift.py
src/impactguard/languages/typescript.py
src/impactguard/languages/zig.py
Refactor union type parsing across multiple languages to use the shared pipe-splitting helper.
  • Replace language-local parse_union_members implementations that strip and split on '
' with split_pipe_union_members(type_str).
  • Preserve per-language docstrings and semantics while delegating the core splitting behavior to the shared helper.

  • Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    Copy link
    Copy Markdown

    @sourcery-ai sourcery-ai Bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Hey - I've reviewed your changes and they look great!


    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    @codacy-production
    Copy link
    Copy Markdown

    Up to standards ✅

    🟢 Issues 0 issues

    Results:
    0 new issues

    View in Codacy

    🟢 Metrics -25 complexity · -26 duplication

    Metric Results
    Complexity -25
    Duplication -26

    View in Codacy

    NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
    TIP This summary will be updated as you push new changes.

    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