ek9_inline_variable

Deletes a single-assignment local's declaration and substitutes its initialiser at every use site (including `${...}` holes); answers status, edits[] and conflicts[] (variable-reassigned, impure-initialiser-multi-use, ...).

Category: Editor · Compare: Refactor → Inline Variable (IntelliJ) / LSP Inline Variable

When to use it

'Inline the local subtotal' is one call with file + symbol:'subtotal' - no line needed; 'inline both locals' is one call with symbols:['prefix','message']. Use it on a LOCAL whose name adds no clarity over its short initialiser, or one an earlier refactor extracted and no longer needs.

When not to use it

Details

A call-free initialiser inlines at any number of uses; a call-bearing one only at a SINGLE use site (V1 refuses multi-use: impure-initialiser-multi-use). Other conflict kinds: variable-reassigned, multi-line-initialiser, variable-is-guard, variable-has-no-references; fields, parameters, return variables and lines not on a local declaration return status:error. Pairs with ek9_extract_method to collapse the destructuring locals a multiReturn container leaves at the call site.

Arguments

ArgumentTypeRequiredWhat it is
filestringyesWorkspace-relative path to the .ek9 source file holding the local declaration.
lineinteger1-based line of the declaration or a reference - OMIT it and pass symbol:'<name>' to let the tool find the line (a model counting lines in a file miscounts); if you do count, use ek9_read_file(lineNumbers:true).
symbolstringThe identifier you mean (e.g. 'total'); the tool finds its declaration line in file. Pass line only to anchor one specific occurrence.
symbolsarray of stringSeveral locals to inline as ONE change, in this order (e.g. ['prefix','message']) - all or none. Instead of symbol.

It also takes the arguments every tool takes.

Recorded calls

Real calls, recorded against small projects and checked on every build - a changed answer fails it.

Two locals one change

Request

{
  "file" : "task.ek9",
  "symbols" : [ "prefix", "message" ]
}

Response

{
  "conflicts" : [ ],
  "edits" : [ {
    "after" : "      rtn: \"Hello, \" + name",
    "before" : "      prefix <- \"Hello, \"\n      message <- prefix + name\n      rtn: message",
    "endLine" : 11,
    "file" : "task.ek9",
    "startLine" : 9,
    "type" : "replace"
  } ],
  "meta" : {
    "serverMs" : "<timing>"
  },
  "resolvedPath" : "<workspace-root>/task.ek9",
  "risk" : {
    "crossesModuleBoundary" : false,
    "estimatedSeverity" : "trivial",
    "fileCount" : 1,
    "lineCount" : 3,
    "touchesPublicApi" : false,
    "touchesTests" : false
  },
  "status" : "applied",
  "summary" : "Would inline 'prefix' (1 use) — remove declaration + substitute 1 line; Would inline 'message' (1 use) — remove declaration + substitute 1 line",
...

Cut short here: 4 more lines. The whole recorded call.

See also