ek9_move_construct

Relocates one top-level construct to another .ek9 file, rewriting every workspace 'references' entry when the move changes module; answers status, edits[] (source DELETE, target INSERT, one rewrite per referring file) and conflicts[].

Category: Editor · Compare: Move Class (IntelliJ)

When to use it

'Move CustomerOrder into shared/order.ek9' is one call with symbol:'CustomerOrder', targetFile:'shared/order.ek9' - no source file, line or mode needed (the mode is derived from the two files' 'defines module' lines). Use it to relocate ONE top-level class/record/trait/function/component to another .ek9 file.

When not to use it

Details

Module membership is set by the target file's 'defines module' line, NOT by directory layout; the tool reads both files' declarations to derive same-module vs cross-module, and rejects a sent mode that mismatches the actual pair. Same module keeps the FQN and yields two edits only; cross-module changes the FQN and atomically rewrites every `references oldModule::Thing` edge workspace-wide. Conflict kinds: 'name-collision-in-module' (mechanical — pick another target or rename first); 'construct-references-not-resolvable-in-new-module' and 'circular-dependency-introduced' (escalation — restructure required); anything the up-front checks miss is caught as would-fail by the scratch-compile gate.

Arguments

ArgumentTypeRequiredWhat it is
filestringThe .ek9 file currently containing the construct - OPTIONAL when symbol is a construct name (the tool finds it workspace-wide).
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).
modestring: same-module | cross-moduleOptional - derived from the two files' 'defines module' lines: same-module (relocation) or cross-module (relocation + workspace-wide reference rewriting). A sent value that contradicts the files is rejected.
sourceFilestringAlias of file (the file currently containing the construct).
symbolstringA construct NAME alone ('Shape', 'sample.deps.core::Validator') - no file needed, the tool finds it workspace-wide; or, with file (+ line), the identifier you mean there.
targetFilestringyesDestination: workspace-relative path the construct should move to. Must already exist; its 'defines module' declaration determines the target module.

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. 3 of the 7 recorded are shown.

Move construct no construct error

Request

{
  "line" : 2,
  "mode" : "cross-module",
  "sourceFile" : "from.ek9",
  "targetFile" : "to.ek9"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ ],
  "error" : {
    "message" : "No top-level construct at: from.ek9:2 — place the line on (or inside the body of) the construct you want to move"
  },
  "meta" : {
    "serverMs" : "<timing>"
  },
  "status" : "error",
  "summary" : "No top-level construct at: from.ek9:2 — place the line on (or inside the body of) the construct you want to move",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

Move construct name collision conflicts

Request

{
  "line" : 5,
  "mode" : "cross-module",
  "sourceFile" : "from.ek9",
  "targetFile" : "to.ek9"
}

Response

{
  "conflicts" : [ {
    "kind" : "name-collision-in-module",
    "message" : "Module test.move.to already declares a construct named 'Mover' — rename one first, or pick a different target"
  } ],
  "edits" : [ ],
  "meta" : {
    "serverMs" : "<timing>"
  },
  "risk" : {
    "crossesModuleBoundary" : false,
    "estimatedSeverity" : "trivial",
    "fileCount" : 0,
    "lineCount" : 0,
    "touchesPublicApi" : false,
    "touchesTests" : false
  },
  "status" : "conflicts",
  "summary" : "Cannot move class Mover — 1 conflict",
  "workspaceHash" : "<workspace-hash>",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

Move construct into commented block apply

Request

{
  "line" : 8,
  "mode" : "same-module",
  "sourceFile" : "core.ek9",
  "targetFile" : "dest.ek9"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ {
    "before" : "\n    Mover\n      default operator ?",
    "endLine" : 9,
    "file" : "core.ek9",
    "startLine" : 7,
    "type" : "delete"
  }, {
    "after" : "\n    Mover\n      default operator ?",
    "endLine" : 13,
    "file" : "dest.ek9",
    "startLine" : 13,
    "type" : "insert"
  } ],
  "meta" : {
    "serverMs" : "<timing>"
  },
  "risk" : {
    "crossesModuleBoundary" : false,
    "estimatedSeverity" : "moderate",
    "fileCount" : 2,
    "lineCount" : 4,
    "touchesPublicApi" : false,
...

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

See also