Expand description
#2470: the refined-type explorer — bynk/refinedTypeModel, and the hover
link that opens it.
Hovering a refined type shows its base type and its predicates in readable
form, with a “Try values…” link (a client-side command, offered only to a
client that says it runs it — see client_supports_explorer_command).
The link opens a panel: a few example values, and a box that checks a
candidate against the predicate and names every clause that fails.
Where the check runs (DECISION A). In the client, over the same
condition the emitter lowers for .of — bynk_ts::pred_condition_and_message.
The server does not run anything. Each clause carries its condition twice:
predicate(#2587), the clause in structured form — one of a closed set of eightPredicatekinds, with its numbers and itsMatchespattern as plain JSON values. A client interprets it directly and runs no JavaScript, so nothing hangs on the server escaping a user-written pattern correctly. This is the form to use.check, the same condition printed to a JavaScript expression overvalue, kept for clients that predatepredicate. Evaluating it (the extension used a freshnode:vmcontext with a time limit) is safe only while the printer escapes the one user-written part, aMatchespattern, correctly;node:vmis not a security boundary. It goes once clients have moved topredicate.
Either way no project code is evaluated: a bynk eval driver would instead
compile and run the project’s output, which is the thing to avoid.
Examples (DECISION B). Drawn here, deterministically, from the domain
the test runtime’s for all generator uses (bynk-emit’s int_bounds,
float_bounds and str_min): the boundaries first, then draws from the
same PRNG as __bynkRng under a fixed SEED, so the list is identical on
every open. A Matches type has no generator (bynk.val.needs_pin); its
drawn strings are kept only if they match the pattern, usually none.
Structs§
- Clause
- One predicate of the refinement.
- Refined
Model - The
bynk/refinedTypeModelresponse. - Refined
Params - The
bynk/refinedTypeModelrequest payload — a text-document position.
Enums§
- Bound
- A
rangebound: a JSON integer for anInttype, a number for aFloat. A float is always finite — the lexer refuses an overflowing literal (bynk.lex.float_literal_overflow) — so it never serialises asnull. - Predicate
- A clause’s condition in structured form: the eight predicate forms, each
holding exactly when the emitter’s
checkfor it does. Serialised with its variant inkind({ "kind": "range", "min": 1, "max": 100 }).
Constants§
- CLIENT_
CAPABILITY - The
ClientCapabilities.experimentalkey a client sets totrueto say it implementsEXPLORE_COMMAND, and so wants the hover link. - EXPLORE_
COMMAND - The client-side command the hover link invokes, with
[uri, position]. The VS Code extension registers it (src/refinedExplorer.tsin bynk-lang/vscode-bynk). - SEED
- The fixed PRNG seed behind the examples: the same list on every open.
Functions§
- client_
supports_ explorer_ command - Whether the client advertised
experimental.refinedTypeExplorerCommand: true. - find_
type_ decl - The
typedeclaration callednameinsource, whichever unit kind holds it. - hover_
link - The hover link: a
command:URI carrying[uri, position], percent-encoded. - hover_
section - The hover text for a refined type: its base and each clause in words.
- model_
for - The explorer model for a declaration, or
Noneunless it is a refined (or opaque)Int,FloatorStringthat carries at least one predicate.with_examplesis false on the hover path, which reads only the clauses: drawing examples there would be work done on every hover for nothing.