bynk_syntax/semantic_tokens.rs
1//! The semantic-token legend's names: the single source for the language
2//! server's legend and for the editor contract (`cargo xtask editor-contract`).
3//!
4//! **Array order is the wire encoding** (clients index into these arrays):
5//! entries are append-only, never reordered, and `bynk-lsp`'s
6//! `legend_is_frozen` test pins them. Token types are standard where faithful
7//! (`type`, `function`) and custom for the Bynk-distinctive kinds
8//! (`capability`, `service`, `agent`, `provider`). They live here, a leaf
9//! crate with no LSP dependency, so tooling that only needs the names does not
10//! link the language server.
11
12/// The token types, in wire order.
13pub const TOKEN_TYPES: &[&str] = &[
14 "type",
15 "function",
16 "capability",
17 "service",
18 "agent",
19 "provider",
20 // v0.31 (ADR 0064): local bindings + params. Standard LSP type — VS Code
21 // themes it by default, no extension declaration needed.
22 "variable",
23 // v0.36 (ADR 0069): instance methods. Appended (never reordered) so
24 // existing legend indices are unchanged. Standard LSP type.
25 "method",
26 // v0.36 (ADR 0069, slice 2): record fields. Appended. Standard LSP
27 // type. (Capability ops reuse `method` — they're operation calls.)
28 "property",
29 // v0.45: actor declarations. Appended at index 9 (never reordered).
30 // Custom type — the VS Code extension declares it in package.json.
31 "actor",
32 // v0.140 (ADR 0163): handler-position annotations (`@cache` and its
33 // argument labels). Appended at index 10. Standard LSP type — VS Code
34 // themes `decorator` by default.
35 "decorator",
36 // message-bundles slice 1: `messages <tag> { ... }` bundles.
37 // Appended at index 11 (never reordered). Custom type — the VS
38 // Code extension declares it in package.json.
39 "messages",
40 // #1888: a `--|` doc line. Appended at index 12 (never
41 // reordered); standard LSP type, with the `documentation`
42 // modifier. #2203: no longer emitted (one-line docs, like `---`
43 // blocks, are left to the editor grammars), but the legend is
44 // append-only, so the entry stays.
45 "comment",
46 // #1883: `asset` names (static files). Appended at index 13
47 // (never reordered). Custom type — the VS Code extension declares
48 // it in package.json, as a `variable` subtype.
49 "asset",
50 // #2387: `embed` names (embedded text). Appended at index 14
51 // (never reordered); a custom type the VS Code extension declares.
52 "embed",
53 // Constrained generics slice 0: constraint names in a bound (`T: Eq`,
54 // `where A: Eq`). Appended at index 15 (never reordered); standard LSP
55 // type.
56 "interface",
57 // #2617: `const` names (named constants). Appended at index 16 (never
58 // reordered); a custom type the VS Code extension declares.
59 "constant",
60 // #2618: a contextual keyword the editor grammars cannot tell from an
61 // identifier by spelling alone: `private` in modifier position.
62 // Appended at index 17 (never reordered); standard LSP type.
63 "keyword",
64 // #2619: an escape sequence inside a string literal (`\n`, `\u{1F600}`).
65 // Appended at index 18 (never reordered); a custom type the VS Code
66 // extension declares, as a `string` subtype.
67 "escape",
68 // #2619: a raw string's delimiters (`r#"`, `"#`). Appended at index 19;
69 // standard LSP type.
70 "string",
71];
72
73/// The token modifiers, in wire order (bit 0 first).
74pub const TOKEN_MODIFIERS: &[&str] = &[
75 "declaration",
76 "refined",
77 "opaque",
78 "platformNative",
79 // #1888: on a `--|` doc line's `comment` token. Appended at bit 4.
80 // #2203: no longer emitted; kept, as the legend is append-only.
81 "documentation",
82];
83
84/// The LSP-standard token types an editor extension does NOT redeclare: VS Code
85/// provides and themes them. Every other entry of [`TOKEN_TYPES`] is
86/// Bynk-custom and must be declared (and scope-mapped) by the extension.
87pub const STANDARD_TYPES: &[&str] = &[
88 "type",
89 "function",
90 "variable",
91 "method",
92 "property",
93 "decorator",
94 "interface",
95 // #1888: `--|` doc lines (no longer emitted since #2203; the legend is
96 // append-only).
97 "comment",
98 // #2618: contextual keywords in keyword position (`private`).
99 "keyword",
100 // #2619: a raw string's delimiters.
101 "string",
102];
103
104/// The LSP-standard token modifiers, likewise.
105pub const STANDARD_MODIFIERS: &[&str] = &["declaration", "documentation"];