Skip to main content

Module introduce_variable

Module introduce_variable 

Source
Expand description

Introduce-variable recipe: extract an expression at a given range into a named variable binding.

Algorithm:

  1. Parse the file with tree-sitter.
  2. Find the innermost complete expression node covering the given byte range.
  3. Walk up to the parent statement of that expression.
  4. Insert let <name> = <expr>; (or the language-appropriate binding) before the statement.
  5. 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§

ByteRange
A byte range selected by the user.
IntroduceVariableOutcome
Outcome of a successful introduce-variable plan.

Functions§

parse_line_col_range
Parse a line:col-line:col range string into a byte range.
plan_introduce_variable
Build an introduce-variable plan without touching the filesystem.