Expand description
#2100 slice 1: the inline-variable refactor (refactor.inline). It
replaces every use of a let binding with the binding’s initialiser and
deletes the let.
Only a pure let name = value is inlined. A let name <- value performs an
effect where it stands, so moving or repeating it would change what the
program does: it is never offered. A let = initialiser has no effects (in
Bynk an effect needs <-), so repeating it at several uses keeps the
program’s meaning (DECISION B’s re-check still runs).
The action is offered with the cursor on the binding’s name or on any use. It declines when:
- the binding is
_, alet … elsedesugaring, or has no uses; - a name the initialiser reads would resolve to a different binding at a
use (an inner
letor parameter shadowing it). The re-check can’t see that, because the program would still type-check; - the
lethas a type annotation (Bynk has no ascription form to carry it, and dropping it could change the inferred type silently); - a use sits somewhere the walk doesn’t recognise (a record field label spelled the same is not a use);
- the
letshares its lines with other code, or carries a comment (deleting it would drop or orphan the comment).
A use as a record shorthand (T { name }) becomes T { name: value }. A
non-atomic initialiser is parenthesised at each use. Like fill-arms the
action rides the unfiltered lightbulb request: it is listed with no edit,
and codeAction/resolve computes the edit and re-checks it.
Structs§
- Offer
- What listing needs: the binding an inline is offered for.
- Plan
- A planned inline: the binding’s name, its definition span, and the edits.
- Target
- What a listed inline action’s
datanames.
Functions§
- listed
- The listed (unresolved)
refactor.inlineaction foroffer. - offerable
- Whether an inline is offered for the local binding at
offset(its name or a use) — every decline check, but none of the formattingplandoes, so the unfiltered lightbulb request stays cheap. - plan
- The inline of the local binding at
offset(its name or a use) intext, given the round’s local bindings for this file, as the edits to apply.Nonewhen there is none to offer (see the module docs).