Enable Java recipes for Python via ty LSP type attribution#6593
Merged
jkschneider merged 2 commits intomainfrom Jan 26, 2026
Merged
Enable Java recipes for Python via ty LSP type attribution#6593jkschneider merged 2 commits intomainfrom
jkschneider merged 2 commits intomainfrom
Conversation
This change enables 7 Java building-block recipes to work on Python code:
- FindMethods
- FindTypes
- ChangeMethodName
- ChangeType
- DeleteMethodArgument
- ReorderMethodArguments
- ChangePackage (via recipes.csv entry)
Key changes:
1. Type attribution via ty LSP client
- New TyLspClient that runs `ty server` as a long-lived subprocess
- Communicates via LSP protocol over stdin/stdout
- Provides hover-based type information for Python code
2. Enhanced PythonTypeMapping
- Maps Python types to JavaType equivalents for MethodMatcher
- Parses method signatures from ty hover responses to extract
parameter names and types
- Handles declaring type resolution for both builtins and modules
3. Python-specific import recipes
- AddImport: Add Python imports with proper formatting
- RemoveImport: Remove unused Python imports
- ChangeImport: Migrate imports between modules
4. Dependency workspace support
- DependencyWorkspace.java manages cached venvs for type resolution
- LRU cache with automatic cleanup of evicted entries
- Enables type attribution for external packages
5. Integration tests for all 7 recipes
- Tests use builtin types (str, list) that work without dependencies
- Validates both positive matches and negative cases
Technical notes:
- ty is required for full type attribution; without it, recipes fall back
to placeholder parameter names
- Parameter names are parsed from ty hover responses like:
`def split(sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]`
Remove debugging statements that were used during development: - python_sender.py: Remove _DEBUG_SENDER flag and _debug() calls - python_receiver.py: Remove logger.debug() in _visit_method_invocation and _receive_search_result - receive_queue.py: Remove logger.debug() calls in receive() and _do_change()
2 tasks
timtebeek
added a commit
that referenced
this pull request
Apr 28, 2026
…7510) These cross-ecosystem rows were inadvertently removed in #6991 when recipes.csv was regenerated by `MavenRecipeMarketplaceGenerator`, which overwrites the file from a pure classpath scan and does not preserve the manually-added rows that advertise these Java recipes to the JavaScript (#6485), Python (#6593), and C# (#6678) ecosystems. Restores `ChangeMethodName`, `ChangePackage`, `ChangeType`, `DeleteMethodArgument`, `ReorderMethodArguments`, `search.FindMethods`, and `search.FindTypes` for each of those three ecosystems, derived from the current Java rows so they stay in sync with the latest option and data table metadata.
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
This PR enables 7 Java building-block recipes to work on Python code by implementing proper type attribution via the ty type checker:
FindMethods- Find method usages by patternFindTypes- Find type references by nameChangeMethodName- Rename a methodChangeType- Change a given type to anotherDeleteMethodArgument- Delete an argument from method invocationsReorderMethodArguments- Reorder method argumentsChangePackage- Rename package/module nameKey Implementation Details
Type Attribution via ty LSP
TyLspClientrunsty serveras a long-lived subprocessJavaType.Methodwith full declaring type, parameter names, and parameter typesPythonTypeMapping Enhancements
def split(sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str])str,list,dict) and module typesPython Import Recipes
AddImport- Add Python imports with proper formattingRemoveImport- Remove unused Python importsChangeImport- Migrate imports between modules (e.g.,collections.Mapping→collections.abc.Mapping)Dependency Workspace
DependencyWorkspace.javamanages cached virtual environments for type resolutionTest plan