Expand description
Inline-variable recipe: replace all uses of a variable with its initializer and remove the binding.
Algorithm:
- Parse the file with tree-sitter.
- Locate the variable declaration node at the given position (line:col of the variable name).
- Extract: variable name, initializer expression text, declaration node byte range, and the scope node (the function/block that contains the declaration).
- Within that scope: walk all identifier nodes, collect those whose text matches the variable name (conservative: skip if ambiguous).
- Check for reassignments — error out if any exist.
- Replace each reference with the initializer expression text (wrapping in parens if needed).
- Remove the declaration statement line.
Language-specific declaration node kinds:
- Rust:
let_declaration— pattern child isidentifieror_pattern, value child via= - JS/TS:
lexical_declaration(const/let) /variable_declaration(var) — containsvariable_declaratorwhich hasname: identifierandvalue: <expr> - Python:
assignment— left child isidentifier, right is the value
Structs§
- Inline
Variable Outcome - Outcome of a successful inline-variable plan.
Functions§
- line_
col_ to_ byte - Convert a 1-based line:col pair to a byte offset in
content. - plan_
inline_ variable - Build an inline-variable plan without touching the filesystem.