introduce_factory
Introduce a factory for a class and rewrite existing constructor calls to use it. Dry-run preview by default; set apply=true to apply changes.
Instructions
Introduce a factory for a class and route instantiations through it. Point at the class name (0-based LSP line/character, UTF-16 units). By default the factory is a static method named factory_name on the class; global_factory=true creates a module-level function instead. Existing constructor calls across the project are rewritten to the factory. Defaults to a Dry Run preview; set apply=true to write. Supply expected_symbol when edits may have intervened since your LSP answer, so a stale Position fails safely. Locate the class with your LSP first; this tool only changes code.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"file": "<file>",
"line": "<line>",
"character": "<character>",
"factory_name": "<factory_name>"
},
"name": "introduce_factory"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | ||
| line | Yes | ||
| root | No | ||
| apply | No | ||
| character | Yes | ||
| factory_name | Yes | ||
| global_factory | No | ||
| expected_symbol | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||