Skip to main content

Module refined_request

Module refined_request 

Source
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 eight Predicate kinds, with its numbers and its Matches pattern 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 over value, kept for clients that predate predicate. Evaluating it (the extension used a fresh node:vm context with a time limit) is safe only while the printer escapes the one user-written part, a Matches pattern, correctly; node:vm is not a security boundary. It goes once clients have moved to predicate.

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.
RefinedModel
The bynk/refinedTypeModel response.
RefinedParams
The bynk/refinedTypeModel request payload — a text-document position.

Enums§

Bound
A range bound: a JSON integer for an Int type, a number for a Float. A float is always finite — the lexer refuses an overflowing literal (bynk.lex.float_literal_overflow) — so it never serialises as null.
Predicate
A clause’s condition in structured form: the eight predicate forms, each holding exactly when the emitter’s check for it does. Serialised with its variant in kind ({ "kind": "range", "min": 1, "max": 100 }).

Constants§

CLIENT_CAPABILITY
The ClientCapabilities.experimental key a client sets to true to say it implements EXPLORE_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.ts in 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 type declaration called name in source, 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 None unless it is a refined (or opaque) Int, Float or String that carries at least one predicate. with_examples is false on the hover path, which reads only the clauses: drawing examples there would be work done on every hover for nothing.