88 lines
4.1 KiB
Python
88 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
"""The take-5 **review** round's phase for R3a/R3c: `extractrefuse`.
|
|
|
|
The `execute` phase runs the two command-bearing offers as a *user* would, and
|
|
one of them — the extraction at `aes_wrap.sv` 66:2 — refuses after about
|
|
805 ms. That refusal turned out to be `extract/boundary.rs`'s, four stages past
|
|
anything a region-local preflight can reach, so §61.1's extract preflight
|
|
cannot and does not move it.
|
|
|
|
What the preflight *does* move is the other half of the refusal list: a new
|
|
name that is not an identifier, a target file that is already occupied, a
|
|
buffer that does not parse, and every refusal about the selection's own shape.
|
|
None of those had a row, so shipping the preflight would have rested on unit
|
|
tests alone. This phase gives them one, at the **same site** as the 805 ms
|
|
refusal so the two numbers are directly comparable: same file, same cursor,
|
|
same session, same fan-out — the only difference is which refusal is reached.
|
|
|
|
Rows are `executeCommand` round trips with no edit pushed, exactly as
|
|
`phases_p0.execute_row` records a refusal, so `ms` is the whole round trip.
|
|
"""
|
|
|
|
import phases_p0
|
|
import schema
|
|
import sites
|
|
from harness import ARGS, code_action_params, phase, record, session
|
|
|
|
#: The command the extract offer carries. Named here rather than read off an
|
|
#: offer, because these rows deliberately send arguments no offer would: the
|
|
#: point is the refusal, not the lightbulb.
|
|
EXTRACT = "lucisv.extractModule"
|
|
|
|
#: `(row, new_name, shift)` — refusals at the site whose *scope-dependent*
|
|
#: refusal costs 805 ms. `shift` extends the selection's end character forward
|
|
#: so the range stops inside the instantiation instead of after it, which is
|
|
#: `Region::read`'s "partial item" refusal — the one the preflight moves.
|
|
#:
|
|
#: The name row is the control, and it is expected **not** to move:
|
|
#: `plain_identifier` was already `extract_module`'s first statement, ahead of
|
|
#: `Extraction::plan` and so ahead of the scope build. Keeping it in the phase
|
|
#: is what makes the other row's improvement attributable to the preflight
|
|
#: rather than to the session.
|
|
CASES = [
|
|
("control: new name is not an identifier (already pre-scope)",
|
|
"1_not_an_ident", 0),
|
|
("refused early: selection covers no whole item", "pulled_out", 20),
|
|
]
|
|
|
|
|
|
@phase("extractrefuse")
|
|
def phase_extractrefuse():
|
|
"""The preflight-reachable extract refusals, timed at the 805 ms site."""
|
|
_, path, needle, occurrence, offset = next(
|
|
row for row in sites.REFACTOR_SITES if row[0] == "inline-module")
|
|
params = code_action_params(path, needle, occurrence, offset)
|
|
uri = params["textDocument"]["uri"]
|
|
for row, new_name, shift in CASES:
|
|
with session("workspace", resolve_support=True, apply_edit=True,
|
|
create_files=True) as s:
|
|
phases_p0.open_and_settle(s, path)
|
|
rng = selection(params["range"], shift)
|
|
call = {"command": EXTRACT, "arguments": [uri, rng, new_name]}
|
|
s.take_notifications()
|
|
total, statuses, pushed = [], [], []
|
|
for _ in range(ARGS.tries + 1):
|
|
_, _, three, message, pushes = phases_p0.execute_once(s, call)
|
|
total.append(three)
|
|
statuses.append(schema.status_of(message))
|
|
pushed = pushes or pushed
|
|
status, text = statuses[-1]
|
|
record(phase="extractrefuse", row=row, ms=total,
|
|
status=status, message=text, result_count=len(pushed),
|
|
client=s.client_shape(), command=EXTRACT,
|
|
arguments=len(call["arguments"]), file=path,
|
|
position=rng["start"], new_name=new_name,
|
|
note="no edit was pushed, so ms is the whole "
|
|
"executeCommand round trip; the same site whose "
|
|
"scope-dependent refusal costs about 805 ms")
|
|
|
|
|
|
def selection(base, shift):
|
|
"""`base`, with its end moved `shift` characters forward — 0 leaves it
|
|
alone, which is the cursor the offer itself is made at."""
|
|
if not shift:
|
|
return base
|
|
end = dict(base["end"])
|
|
end["character"] = end["character"] + shift
|
|
return {"start": base["start"], "end": end}
|