Skip to content

JetBrains: add jet_brains_find_unused_code tool#1535

Open
MischaPanch wants to merge 1 commit into
mainfrom
feature/jb_find_unused_code
Open

JetBrains: add jet_brains_find_unused_code tool#1535
MischaPanch wants to merge 1 commit into
mainfrom
feature/jb_find_unused_code

Conversation

@MischaPanch
Copy link
Copy Markdown
Member

Summary

Adds a new JetBrains-backend tool, jet_brains_find_unused_code, which reports code symbols
(classes, methods, fields, …) declared in a file that have no references anywhere in the project
i.e. code that is likely unused/dead.

It is a thin client over a new /findUnusedCode endpoint in the Serena JetBrains plugin: the plugin
walks the IDE's structure-view declaration tree and flags each declaration whose PSI reference search
comes back empty.

Changes

  • jetbrains/jetbrains_plugin_client.py: new find_unused_code(relative_path, include_quick_info)
    client method (calls /findUnusedCode; version-gated to plugin 2023.2.17+).
  • tools/jetbrains_tools.py: new JetBrainsFindUnusedCodeTool (ToolMarkerSymbolicRead,
    ToolMarkerOptional, ToolMarkerBeta); groups results by file/type, or returns a "none found" message.
  • resources/config/internal_modes/jetbrains.yml: register jet_brains_find_unused_code in
    included_optional_tools (so the JetBrains language backend exposes it) and mention it in the mode prompt.
  • CHANGELOG.md: entry under Unreleased → JetBrains.

Caveats (documented in the tool description)

This is a usage-based heuristic via the IDE's reference search:

  • entry points (e.g. main methods, public API consumed outside the project) and reflective/framework
    usages are not accounted for and may produce false positives;
  • transitively-dead code (a private member used only by other dead code) is not reported.

So results should be reviewed before deletion.

Requirements

Requires the Serena JetBrains plugin 2023.2.17+ (which adds the /findUnusedCode endpoint). The
client raises a clear "update the plugin" error against older versions.

Testing

Verified end-to-end against the plugin's headless Docker harness (the serena MCP server built from this
checkout, driving the plugin in IntelliJ): on a sample project the tool reports the one unused private
method and omits the used members, via the full round-trip
MCP client → serena → plugin /findUnusedCode → IntelliJ PSI. poe format and poe type-check pass.

🤖 Generated with Claude Code

Add the jet_brains_find_unused_code tool (JetBrainsFindUnusedCodeTool) backed by a new find_unused_code plugin-client method that calls the plugin's /findUnusedCode endpoint, and enable it in the jetbrains internal mode. It reports code symbols (classes, methods, fields, ...) declared in a file that have no references in the project - a usage-based heuristic for finding likely-dead code.

Requires Serena JetBrains plugin version 2023.2.17+.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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