104 lines
4.6 KiB
Python
104 lines
4.6 KiB
Python
#!/usr/bin/env python3
|
|
"""The phase take 5 §P1 added: what an offer costs on a buffer that just
|
|
changed, as against one that did not.
|
|
|
|
Imported by `bench.py`, which owns the registry and the command line.
|
|
|
|
`offeredit` exists because §P1b's whole claim is that a *repeated* offer on an
|
|
unchanged buffer reuses the document's own parse. That claim would be easy to
|
|
dress up by quoting only the repeats, so the first request after a `didChange`
|
|
— where the document is rebuilt and nothing is reusable — gets its own row at
|
|
the same cursor, in the same session, with the same client shape. The tracker
|
|
compares the two.
|
|
|
|
The corpus is not written: a `didChange` is a notification about an in-memory
|
|
buffer, and the appended line never reaches disk.
|
|
"""
|
|
|
|
import os
|
|
|
|
import schema
|
|
from harness import (
|
|
ARGS, code_action_params, phase, record, samples, session, settled, sites,
|
|
)
|
|
|
|
#: (label, file, needle, cursor offset) — the cursors §P1 is judged at. The
|
|
#: first is the round's headline (a no-offer comment in a 42 192-line
|
|
#: generated file), the second the one small-file offer site, the third the
|
|
#: small-file no-offer control.
|
|
EDIT_CURSORS = [
|
|
("pinmux-comment", sites.PINMUX_REG_TOP, "// ", 2),
|
|
("aes-reg-instance", sites.AES, "aes_reg_top u_reg (", 0),
|
|
("tb-comment", sites.TB, "// ", 2),
|
|
]
|
|
|
|
|
|
def open_and_settle(s, relative, quiet=0.6):
|
|
"""Settle the scan, then open the file this row measures."""
|
|
settled(s)
|
|
s.did_open(sites.path(relative))
|
|
s.wait_quiet(quiet)
|
|
s.take_notifications()
|
|
|
|
|
|
def first_after_change(s, relative, text, params, tries):
|
|
"""One `codeAction` per `didChange`, each the first request after its edit.
|
|
|
|
The edit is a comment appended to the end of the buffer, so every cursor
|
|
this phase measures keeps the position it was resolved at. `samples(…, 1)`
|
|
is used rather than a repeat list because a repeat would no longer be the
|
|
first request after a change, which is the whole subject of the row.
|
|
"""
|
|
ms, statuses, counts = [], [], []
|
|
for version in range(2, 2 + tries):
|
|
s.did_change(sites.path(relative), text + "\n// take5 p1 %d\n" % version,
|
|
version)
|
|
got = samples(s, "textDocument/codeAction", params, 1)
|
|
ms.append(got.ms[0])
|
|
statuses.append((got.status, got.message))
|
|
counts.append(got.result_count)
|
|
return ms, statuses, counts
|
|
|
|
|
|
@phase("offeredit")
|
|
def phase_offeredit():
|
|
"""§P1 — the first offer after an edit, beside the repeated offer.
|
|
|
|
Two rows per cursor in one session: `didChange` → `codeAction` three
|
|
times over, then three `codeAction`s on the settled buffer. A lazy client,
|
|
which is the shape every reference row in the tracker used.
|
|
"""
|
|
for label, relative, needle, offset in EDIT_CURSORS:
|
|
with session("workspace", resolve_support=True) as s:
|
|
open_and_settle(s, relative)
|
|
with open(sites.path(relative), encoding="utf-8",
|
|
errors="replace") as handle:
|
|
text = handle.read()
|
|
params = code_action_params(relative, needle, offset=offset)
|
|
ms, statuses, counts = first_after_change(
|
|
s, relative, text, params, ARGS.tries)
|
|
status = schema.worst([one for one, _ in statuses])
|
|
record(phase="offeredit",
|
|
row="%s, first offer after didChange" % label,
|
|
ms=ms, status=status,
|
|
message=next((m for one, m in statuses if one != "ok"), None),
|
|
result_count=counts[-1], result_counts=counts,
|
|
client=s.client_shape(), file=relative,
|
|
position=params["range"]["start"], load=os.getloadavg(),
|
|
note="each try is the first codeAction after its own "
|
|
"didChange: the document is rebuilt, so nothing from "
|
|
"the previous revision can be reused")
|
|
# The buffer is now at its last edited revision and stays there:
|
|
# these are repeats on an unchanged document, the case §P1b's
|
|
# reuse is for.
|
|
got = samples(s, "textDocument/codeAction", params, ARGS.tries + 1)
|
|
offered = got.last.get("result") or []
|
|
record(phase="offeredit",
|
|
row="%s, repeated offer on the unchanged buffer" % label,
|
|
titles=[a.get("title") for a in offered],
|
|
client=s.client_shape(), file=relative,
|
|
position=params["range"]["start"], load=os.getloadavg(),
|
|
note="the same cursor and session as the row above, with "
|
|
"no didChange between the tries",
|
|
**got.row())
|