Expand description
Introduce-variable recipe: extract an expression at a given range into a named variable binding.
Algorithm:
- Parse the file with tree-sitter.
- Find the innermost complete expression node covering the given byte range.
- Walk up to the parent statement of that expression.
- Insert
let <name> = <expr>;(or the language-appropriate binding) before the statement. - Replace the original expression text with
<name>.
Language-specific keyword mapping (everything else uses let):
- Python:
<name> = <expr>(no keyword) - JavaScript / TypeScript:
const <name> = <expr>; - Rust, Go, Swift, Kotlin, Scala, Dart, etc.:
let <name> = <expr>;
Structs§
- Byte
Range - A byte range selected by the user.
- Introduce
Variable Outcome - Outcome of a successful introduce-variable plan.
Functions§
- parse_
line_ col_ range - Parse a
line:col-line:colrange string into a byte range. - plan_
introduce_ variable - Build an introduce-variable plan without touching the filesystem.