@crowdedkingdoms/crowdyjs 8.22.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/MIGRATION.md +66 -0
  2. package/README.md +111 -7
  3. package/dist/crowdy-client.d.ts +3 -0
  4. package/dist/crowdy-client.d.ts.map +1 -1
  5. package/dist/crowdy-client.js +2 -0
  6. package/dist/domains/playerCodeProjects.d.ts +25 -0
  7. package/dist/domains/playerCodeProjects.d.ts.map +1 -0
  8. package/dist/domains/playerCodeProjects.js +299 -0
  9. package/dist/domains/playerCompute.d.ts +1 -1
  10. package/dist/domains/playerCompute.js +1 -1
  11. package/dist/generated/graphql.d.ts +792 -7
  12. package/dist/generated/graphql.d.ts.map +1 -1
  13. package/dist/generated/graphql.js +57 -0
  14. package/dist/index.d.ts +3 -5
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -5
  17. package/dist/kit/npcs.d.ts.map +1 -1
  18. package/dist/kit/social.d.ts.map +1 -1
  19. package/dist/live-coding/assets/browser-authoring-index.json +1 -0
  20. package/dist/live-coding/assets/manifest.json +19 -0
  21. package/dist/live-coding/assets/tree-sitter-rust.wasm +0 -0
  22. package/dist/live-coding/assets/web-tree-sitter.wasm +0 -0
  23. package/dist/live-coding/browser-authoring-index.generated.d.ts +2 -0
  24. package/dist/live-coding/browser-authoring-index.generated.d.ts.map +1 -0
  25. package/dist/live-coding/browser-authoring-index.generated.js +5127 -0
  26. package/dist/live-coding/lsp-protocol.d.ts +98 -0
  27. package/dist/live-coding/lsp-protocol.d.ts.map +1 -0
  28. package/dist/live-coding/lsp-protocol.js +70 -0
  29. package/dist/live-coding/monaco-services.d.ts +22 -0
  30. package/dist/live-coding/monaco-services.d.ts.map +1 -0
  31. package/dist/live-coding/monaco-services.js +69 -0
  32. package/dist/live-coding/platform-index.d.ts +29 -0
  33. package/dist/live-coding/platform-index.d.ts.map +1 -0
  34. package/dist/live-coding/platform-index.js +281 -0
  35. package/dist/live-coding/rust-analysis.d.ts +24 -0
  36. package/dist/live-coding/rust-analysis.d.ts.map +1 -0
  37. package/dist/live-coding/rust-analysis.js +375 -0
  38. package/dist/live-coding/rust-lsp-server.d.ts +43 -0
  39. package/dist/live-coding/rust-lsp-server.d.ts.map +1 -0
  40. package/dist/live-coding/rust-lsp-server.js +455 -0
  41. package/dist/live-coding/rust-lsp.worker.d.ts +2 -0
  42. package/dist/live-coding/rust-lsp.worker.d.ts.map +1 -0
  43. package/dist/live-coding/rust-lsp.worker.js +26 -0
  44. package/dist/live-coding/vfs.d.ts +41 -0
  45. package/dist/live-coding/vfs.d.ts.map +1 -0
  46. package/dist/live-coding/vfs.js +174 -0
  47. package/dist/live-coding/worker-transport.d.ts +63 -0
  48. package/dist/live-coding/worker-transport.d.ts.map +1 -0
  49. package/dist/live-coding/worker-transport.js +217 -0
  50. package/dist/mod-studio/controller.d.ts +188 -0
  51. package/dist/mod-studio/controller.d.ts.map +1 -0
  52. package/dist/mod-studio/controller.js +915 -0
  53. package/dist/mod-studio/diagnostics.d.ts +22 -0
  54. package/dist/mod-studio/diagnostics.d.ts.map +1 -0
  55. package/dist/mod-studio/diagnostics.js +141 -0
  56. package/dist/mod-studio/dom-shell.d.ts +55 -0
  57. package/dist/mod-studio/dom-shell.d.ts.map +1 -0
  58. package/dist/mod-studio/dom-shell.js +527 -0
  59. package/dist/mod-studio/editor.d.ts +17 -0
  60. package/dist/mod-studio/editor.d.ts.map +1 -0
  61. package/dist/mod-studio/editor.js +1 -0
  62. package/dist/mod-studio/index.d.ts +10 -0
  63. package/dist/mod-studio/index.d.ts.map +1 -0
  64. package/dist/mod-studio/index.js +9 -0
  65. package/dist/mod-studio/models.d.ts +149 -0
  66. package/dist/mod-studio/models.d.ts.map +1 -0
  67. package/dist/mod-studio/models.js +62 -0
  68. package/dist/mod-studio/monaco-editor.d.ts +16 -0
  69. package/dist/mod-studio/monaco-editor.d.ts.map +1 -0
  70. package/dist/mod-studio/monaco-editor.js +548 -0
  71. package/dist/mod-studio/mount.d.ts +17 -0
  72. package/dist/mod-studio/mount.d.ts.map +1 -0
  73. package/dist/mod-studio/mount.js +86 -0
  74. package/dist/mod-studio/starter-projects.d.ts +11 -0
  75. package/dist/mod-studio/starter-projects.d.ts.map +1 -0
  76. package/dist/mod-studio/starter-projects.js +102 -0
  77. package/dist/mod-studio/styles.d.ts +2 -0
  78. package/dist/mod-studio/styles.d.ts.map +1 -0
  79. package/dist/mod-studio/styles.js +14 -0
  80. package/dist/mod-studio/textarea-editor.d.ts +8 -0
  81. package/dist/mod-studio/textarea-editor.d.ts.map +1 -0
  82. package/dist/mod-studio/textarea-editor.js +71 -0
  83. package/package.json +18 -6
  84. package/dist/live-coding/ide.d.ts +0 -16
  85. package/dist/live-coding/ide.d.ts.map +0 -1
  86. package/dist/live-coding/ide.js +0 -399
  87. package/dist/live-coding/live-coding-controller.d.ts +0 -75
  88. package/dist/live-coding/live-coding-controller.d.ts.map +0 -1
  89. package/dist/live-coding/live-coding-controller.js +0 -141
  90. package/dist/live-coding/mount.d.ts +0 -26
  91. package/dist/live-coding/mount.d.ts.map +0 -1
  92. package/dist/live-coding/mount.js +0 -108
  93. package/dist/live-coding/templates.d.ts +0 -17
  94. package/dist/live-coding/templates.d.ts.map +0 -1
  95. package/dist/live-coding/templates.js +0 -59
@@ -0,0 +1,98 @@
1
+ export type JsonRpcId = number | string;
2
+ export interface JsonRpcRequest {
3
+ jsonrpc: '2.0';
4
+ id: JsonRpcId;
5
+ method: string;
6
+ params?: unknown;
7
+ }
8
+ export interface JsonRpcNotification {
9
+ jsonrpc: '2.0';
10
+ method: string;
11
+ params?: unknown;
12
+ }
13
+ export interface JsonRpcResponse {
14
+ jsonrpc: '2.0';
15
+ id: JsonRpcId | null;
16
+ result?: unknown;
17
+ error?: {
18
+ code: number;
19
+ message: string;
20
+ data?: unknown;
21
+ };
22
+ }
23
+ export type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
24
+ export interface Position {
25
+ line: number;
26
+ character: number;
27
+ }
28
+ export interface Range {
29
+ start: Position;
30
+ end: Position;
31
+ }
32
+ export interface Location {
33
+ uri: string;
34
+ range: Range;
35
+ }
36
+ export interface TextDocumentIdentifier {
37
+ uri: string;
38
+ }
39
+ export interface VersionedTextDocumentIdentifier extends TextDocumentIdentifier {
40
+ version: number;
41
+ }
42
+ export interface TextDocumentItem extends VersionedTextDocumentIdentifier {
43
+ languageId: string;
44
+ text: string;
45
+ }
46
+ export interface TextDocumentContentChangeEvent {
47
+ range?: Range;
48
+ text: string;
49
+ }
50
+ export interface Diagnostic {
51
+ range: Range;
52
+ severity: 1 | 2 | 3 | 4;
53
+ source: 'crowdy-rust';
54
+ code: string;
55
+ message: string;
56
+ }
57
+ export interface CompletionItem {
58
+ label: string;
59
+ kind: number;
60
+ detail?: string;
61
+ documentation?: string;
62
+ insertText?: string;
63
+ sortText?: string;
64
+ }
65
+ export interface Hover {
66
+ contents: {
67
+ kind: 'markdown';
68
+ value: string;
69
+ };
70
+ range?: Range;
71
+ }
72
+ export interface DocumentSymbol {
73
+ name: string;
74
+ detail?: string;
75
+ kind: number;
76
+ range: Range;
77
+ selectionRange: Range;
78
+ }
79
+ export declare const JSON_RPC_ERRORS: {
80
+ readonly parseError: -32700;
81
+ readonly invalidRequest: -32600;
82
+ readonly methodNotFound: -32601;
83
+ readonly invalidParams: -32602;
84
+ readonly internalError: -32603;
85
+ readonly requestCancelled: -32800;
86
+ readonly contentModified: -32801;
87
+ };
88
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
89
+ export declare function decodeJsonRpcMessage(value: unknown): {
90
+ ok: true;
91
+ message: JsonRpcMessage;
92
+ } | {
93
+ ok: false;
94
+ code: number;
95
+ message: string;
96
+ id: JsonRpcId | null;
97
+ };
98
+ //# sourceMappingURL=lsp-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lsp-protocol.d.ts","sourceRoot":"","sources":["../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C,EAAE,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE,CA2DrE"}
@@ -0,0 +1,70 @@
1
+ export const JSON_RPC_ERRORS = {
2
+ parseError: -32700,
3
+ invalidRequest: -32600,
4
+ methodNotFound: -32601,
5
+ invalidParams: -32602,
6
+ internalError: -32603,
7
+ requestCancelled: -32800,
8
+ contentModified: -32801,
9
+ };
10
+ export function isRecord(value) {
11
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
12
+ }
13
+ export function decodeJsonRpcMessage(value) {
14
+ let decoded = value;
15
+ if (typeof value === 'string') {
16
+ try {
17
+ decoded = JSON.parse(value);
18
+ }
19
+ catch {
20
+ return {
21
+ ok: false,
22
+ code: JSON_RPC_ERRORS.parseError,
23
+ message: 'Parse error',
24
+ id: null,
25
+ };
26
+ }
27
+ }
28
+ if (!isRecord(decoded) || decoded.jsonrpc !== '2.0') {
29
+ return {
30
+ ok: false,
31
+ code: JSON_RPC_ERRORS.invalidRequest,
32
+ message: 'Invalid Request',
33
+ id: null,
34
+ };
35
+ }
36
+ const hasId = Object.prototype.hasOwnProperty.call(decoded, 'id');
37
+ const id = typeof decoded.id === 'number' || typeof decoded.id === 'string'
38
+ ? decoded.id
39
+ : null;
40
+ if (typeof decoded.method === 'string') {
41
+ if (hasId && id === null) {
42
+ return {
43
+ ok: false,
44
+ code: JSON_RPC_ERRORS.invalidRequest,
45
+ message: 'Invalid Request',
46
+ id: null,
47
+ };
48
+ }
49
+ return {
50
+ ok: true,
51
+ message: {
52
+ jsonrpc: '2.0',
53
+ ...(id === null ? {} : { id }),
54
+ method: decoded.method,
55
+ ...('params' in decoded ? { params: decoded.params } : {}),
56
+ },
57
+ };
58
+ }
59
+ if (hasId &&
60
+ (id !== null || decoded.id === null) &&
61
+ ('result' in decoded || isRecord(decoded.error))) {
62
+ return { ok: true, message: decoded };
63
+ }
64
+ return {
65
+ ok: false,
66
+ code: JSON_RPC_ERRORS.invalidRequest,
67
+ message: 'Invalid Request',
68
+ id,
69
+ };
70
+ }
@@ -0,0 +1,22 @@
1
+ export type MonacoServicesInitializer = () => Promise<void>;
2
+ /**
3
+ * Process-wide one-shot gate for the monaco-vscode service collection.
4
+ * The upstream service registry is global and rejects a second initialize.
5
+ */
6
+ export declare class MonacoServicesBootstrap {
7
+ private initialization;
8
+ ensure(initializer: MonacoServicesInitializer): Promise<void>;
9
+ }
10
+ export declare function ensureMonacoServicesInitialized(): Promise<void>;
11
+ export interface MonacoWorkspaceLease {
12
+ uri: string;
13
+ release(): void;
14
+ }
15
+ /** Avoids Monaco's global model-URI collision across concurrent IDE mounts. */
16
+ export declare class MonacoWorkspacePool {
17
+ private readonly active;
18
+ private nextSuffix;
19
+ acquire(): MonacoWorkspaceLease;
20
+ }
21
+ export declare function acquireMonacoWorkspace(): MonacoWorkspaceLease;
22
+ //# sourceMappingURL=monaco-services.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monaco-services.d.ts","sourceRoot":"","sources":["../../src/live-coding/monaco-services.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5D;;;GAGG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,cAAc,CAA8B;IAEpD,MAAM,CAAC,WAAW,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;CAI9D;AAID,wBAAgB,+BAA+B,IAAI,OAAO,CAAC,IAAI,CAAC,CAE/D;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,+EAA+E;AAC/E,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,UAAU,CAAK;IAEvB,OAAO,IAAI,oBAAoB;CAgBhC;AAID,wBAAgB,sBAAsB,IAAI,oBAAoB,CAE7D"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Process-wide one-shot gate for the monaco-vscode service collection.
3
+ * The upstream service registry is global and rejects a second initialize.
4
+ */
5
+ export class MonacoServicesBootstrap {
6
+ constructor() {
7
+ this.initialization = null;
8
+ }
9
+ ensure(initializer) {
10
+ this.initialization ?? (this.initialization = Promise.resolve().then(initializer));
11
+ return this.initialization;
12
+ }
13
+ }
14
+ const defaultBootstrap = new MonacoServicesBootstrap();
15
+ export function ensureMonacoServicesInitialized() {
16
+ return defaultBootstrap.ensure(initializeDefaultMonacoServices);
17
+ }
18
+ /** Avoids Monaco's global model-URI collision across concurrent IDE mounts. */
19
+ export class MonacoWorkspacePool {
20
+ constructor() {
21
+ this.active = new Set();
22
+ this.nextSuffix = 2;
23
+ }
24
+ acquire() {
25
+ let uri = 'file:///player-mod';
26
+ while (this.active.has(uri)) {
27
+ uri = `file:///player-mod-${this.nextSuffix++}`;
28
+ }
29
+ this.active.add(uri);
30
+ let released = false;
31
+ return {
32
+ uri,
33
+ release: () => {
34
+ if (released)
35
+ return;
36
+ released = true;
37
+ this.active.delete(uri);
38
+ },
39
+ };
40
+ }
41
+ }
42
+ const defaultWorkspacePool = new MonacoWorkspacePool();
43
+ export function acquireMonacoWorkspace() {
44
+ return defaultWorkspacePool.acquire();
45
+ }
46
+ async function initializeDefaultMonacoServices() {
47
+ const [services, lifecycle] = await Promise.all([
48
+ import('@codingame/monaco-vscode-api/services'),
49
+ import('@codingame/monaco-vscode-api/lifecycle'),
50
+ ]);
51
+ if (lifecycle.servicesInitialized) {
52
+ await lifecycle.waitServicesReady();
53
+ return;
54
+ }
55
+ try {
56
+ // `initialize` supplies the package's base, environment, files, host,
57
+ // layout, extension and quick-access defaults. No workbench UI or language
58
+ // client override is needed for a configured standalone editor.
59
+ await services.initialize({}, document.body);
60
+ }
61
+ catch (error) {
62
+ // Cooperate with a host that won the initialization race.
63
+ if (lifecycle.servicesInitialized) {
64
+ await lifecycle.waitServicesReady();
65
+ return;
66
+ }
67
+ throw error;
68
+ }
69
+ }
@@ -0,0 +1,29 @@
1
+ export type PlatformSymbolKind = 'const' | 'enum' | 'field' | 'function' | 'macro' | 'method' | 'module' | 'reexport' | 'static' | 'struct' | 'trait' | 'type' | 'variant';
2
+ export interface PlatformSymbol {
3
+ module: string;
4
+ name: string;
5
+ kind: PlatformSymbolKind;
6
+ signature: string;
7
+ docs: string;
8
+ }
9
+ export interface PlatformCrate {
10
+ name: string;
11
+ version: string;
12
+ sourceHash: string;
13
+ }
14
+ export interface PlatformIndex {
15
+ schemaVersion: 2;
16
+ rustVersion: string;
17
+ sdkVersion: string;
18
+ abiVersion: number;
19
+ contentHash: string;
20
+ crates: PlatformCrate[];
21
+ symbols: PlatformSymbol[];
22
+ }
23
+ export declare const MAX_PLATFORM_INDEX_BYTES: number;
24
+ export declare const MAX_PLATFORM_CRATES = 256;
25
+ export declare const MAX_PLATFORM_CRATE_FIELD_LENGTH = 256;
26
+ export declare function loadPlatformIndex(input: unknown): PlatformIndex;
27
+ export declare function computePlatformIndexContentHash(index: Pick<PlatformIndex, 'schemaVersion' | 'rustVersion' | 'sdkVersion' | 'abiVersion' | 'crates' | 'symbols'>): string;
28
+ export declare const EMBEDDED_PLATFORM_INDEX: PlatformIndex;
29
+ //# sourceMappingURL=platform-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-index.d.ts","sourceRoot":"","sources":["../../src/live-coding/platform-index.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,kBAAkB,GAC1B,OAAO,GACP,MAAM,GACN,OAAO,GACP,UAAU,GACV,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,GACN,SAAS,CAAC;AAEd,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,kBAAkB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,CAAC,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAiBD,eAAO,MAAM,wBAAwB,QAAkB,CAAC;AACxD,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,+BAA+B,MAAM,CAAC;AAmBnD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAkE/D;AAED,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,IAAI,CACT,aAAa,EACX,eAAe,GACf,aAAa,GACb,YAAY,GACZ,YAAY,GACZ,QAAQ,GACR,SAAS,CACZ,GACA,MAAM,CAoBR;AA4LD,eAAO,MAAM,uBAAuB,EAAE,aAErC,CAAC"}
@@ -0,0 +1,281 @@
1
+ import { isRecord } from './lsp-protocol.js';
2
+ import { GENERATED_BROWSER_AUTHORING_INDEX } from './browser-authoring-index.generated.js';
3
+ const SYMBOL_KINDS = new Set([
4
+ 'const',
5
+ 'enum',
6
+ 'field',
7
+ 'function',
8
+ 'macro',
9
+ 'method',
10
+ 'module',
11
+ 'reexport',
12
+ 'static',
13
+ 'struct',
14
+ 'trait',
15
+ 'type',
16
+ 'variant',
17
+ ]);
18
+ export const MAX_PLATFORM_INDEX_BYTES = 2 * 1024 * 1024;
19
+ export const MAX_PLATFORM_CRATES = 256;
20
+ export const MAX_PLATFORM_CRATE_FIELD_LENGTH = 256;
21
+ const INDEX_KEYS = new Set([
22
+ 'schemaVersion',
23
+ 'rustVersion',
24
+ 'sdkVersion',
25
+ 'abiVersion',
26
+ 'contentHash',
27
+ 'crates',
28
+ 'symbols',
29
+ ]);
30
+ const CRATE_KEYS = new Set(['name', 'version', 'sourceHash']);
31
+ const SYMBOL_KEYS = new Set([
32
+ 'module',
33
+ 'name',
34
+ 'kind',
35
+ 'signature',
36
+ 'docs',
37
+ ]);
38
+ export function loadPlatformIndex(input) {
39
+ assertSerializedSize(input);
40
+ if (!isRecord(input))
41
+ throw new Error('Platform index must be an object');
42
+ assertExactKeys(input, INDEX_KEYS, 'platform index');
43
+ if (input.schemaVersion !== 2) {
44
+ throw new Error(`Unsupported platform index schemaVersion: ${String(input.schemaVersion)}`);
45
+ }
46
+ const rustVersion = requiredString(input.rustVersion, 'rustVersion');
47
+ const sdkVersion = requiredString(input.sdkVersion, 'sdkVersion');
48
+ if (!Number.isSafeInteger(input.abiVersion) || input.abiVersion < 0) {
49
+ throw new Error('abiVersion must be a non-negative safe integer');
50
+ }
51
+ const abiVersion = input.abiVersion;
52
+ const contentHash = requiredString(input.contentHash, 'contentHash');
53
+ if (!/^[a-f0-9]{64}$/u.test(contentHash)) {
54
+ throw new Error('contentHash must be a lowercase SHA-256 hex digest');
55
+ }
56
+ if (!Array.isArray(input.crates) || input.crates.length === 0) {
57
+ throw new Error('crates must be a non-empty array');
58
+ }
59
+ if (input.crates.length > MAX_PLATFORM_CRATES) {
60
+ throw new Error(`Platform index exceeds the ${MAX_PLATFORM_CRATES} crate limit`);
61
+ }
62
+ const crates = input.crates.map((entry, index) => loadCrate(entry, index));
63
+ const crateNames = new Set();
64
+ for (const crate of crates) {
65
+ if (crateNames.has(crate.name)) {
66
+ throw new Error(`Duplicate platform crate: ${crate.name}`);
67
+ }
68
+ crateNames.add(crate.name);
69
+ }
70
+ if (!Array.isArray(input.symbols)) {
71
+ throw new Error('symbols must be an array');
72
+ }
73
+ if (input.symbols.length > 20000) {
74
+ throw new Error('Platform index exceeds the 20,000 symbol limit');
75
+ }
76
+ const symbols = input.symbols.map((entry, index) => loadSymbol(entry, index));
77
+ const seen = new Set();
78
+ for (const symbol of symbols) {
79
+ const path = `${symbol.module}::${symbol.name}`;
80
+ const key = `${path}\0${symbol.kind}\0${symbol.signature}`;
81
+ if (seen.has(key))
82
+ throw new Error(`Duplicate platform symbol: ${path}`);
83
+ seen.add(key);
84
+ }
85
+ const loaded = {
86
+ schemaVersion: 2,
87
+ rustVersion,
88
+ sdkVersion,
89
+ abiVersion,
90
+ contentHash,
91
+ crates: Object.freeze(crates),
92
+ symbols: Object.freeze(symbols),
93
+ };
94
+ const computedHash = computePlatformIndexContentHash(loaded);
95
+ if (computedHash !== contentHash) {
96
+ throw new Error(`Platform index contentHash mismatch: expected ${contentHash}, computed ${computedHash}`);
97
+ }
98
+ assertSerializedSize(loaded);
99
+ return Object.freeze(loaded);
100
+ }
101
+ export function computePlatformIndexContentHash(index) {
102
+ const payload = {
103
+ schemaVersion: index.schemaVersion,
104
+ rustVersion: index.rustVersion,
105
+ sdkVersion: index.sdkVersion,
106
+ abiVersion: index.abiVersion,
107
+ crates: index.crates.map((crate) => ({
108
+ name: crate.name,
109
+ version: crate.version,
110
+ sourceHash: crate.sourceHash,
111
+ })),
112
+ symbols: index.symbols.map((symbol) => ({
113
+ module: symbol.module,
114
+ name: symbol.name,
115
+ kind: symbol.kind,
116
+ signature: symbol.signature,
117
+ docs: symbol.docs,
118
+ })),
119
+ };
120
+ return sha256Hex(JSON.stringify(payload));
121
+ }
122
+ function loadCrate(input, index) {
123
+ if (!isRecord(input))
124
+ throw new Error(`crates[${index}] must be an object`);
125
+ assertExactKeys(input, CRATE_KEYS, `crates[${index}]`);
126
+ const sourceHash = requiredString(input.sourceHash, `crates[${index}].sourceHash`);
127
+ if (!/^[a-f0-9]{64}$/u.test(sourceHash)) {
128
+ throw new Error(`crates[${index}].sourceHash must be a lowercase SHA-256 hex digest`);
129
+ }
130
+ return Object.freeze({
131
+ name: requiredCrateString(input.name, `crates[${index}].name`),
132
+ version: requiredCrateString(input.version, `crates[${index}].version`),
133
+ sourceHash,
134
+ });
135
+ }
136
+ function loadSymbol(input, index) {
137
+ if (!isRecord(input))
138
+ throw new Error(`symbols[${index}] must be an object`);
139
+ assertExactKeys(input, SYMBOL_KEYS, `symbols[${index}]`);
140
+ const kind = requiredString(input.kind, `symbols[${index}].kind`);
141
+ if (!SYMBOL_KINDS.has(kind)) {
142
+ throw new Error(`symbols[${index}].kind is unsupported`);
143
+ }
144
+ const symbol = {
145
+ module: requiredString(input.module, `symbols[${index}].module`),
146
+ name: requiredString(input.name, `symbols[${index}].name`),
147
+ kind: kind,
148
+ signature: requiredString(input.signature, `symbols[${index}].signature`),
149
+ docs: boundedString(input.docs, `symbols[${index}].docs`),
150
+ };
151
+ return Object.freeze(symbol);
152
+ }
153
+ function requiredString(value, field) {
154
+ if (typeof value !== 'string' || value.length === 0 || value.length > 16384) {
155
+ throw new Error(`${field} must be a non-empty bounded string`);
156
+ }
157
+ return value;
158
+ }
159
+ function requiredCrateString(value, field) {
160
+ if (typeof value !== 'string' ||
161
+ value.length === 0 ||
162
+ value.length > MAX_PLATFORM_CRATE_FIELD_LENGTH) {
163
+ throw new Error(`${field} must be a non-empty string of at most ${MAX_PLATFORM_CRATE_FIELD_LENGTH} characters`);
164
+ }
165
+ return value;
166
+ }
167
+ function boundedString(value, field) {
168
+ if (typeof value !== 'string' || value.length > 16384) {
169
+ throw new Error(`${field} must be a bounded string`);
170
+ }
171
+ return value;
172
+ }
173
+ function assertExactKeys(input, allowed, field) {
174
+ const unexpected = Object.keys(input).find((key) => !allowed.has(key));
175
+ if (unexpected)
176
+ throw new Error(`${field} has unexpected field ${unexpected}`);
177
+ const missing = [...allowed].find((key) => !(key in input));
178
+ if (missing)
179
+ throw new Error(`${field} is missing ${missing}`);
180
+ }
181
+ function assertSerializedSize(input) {
182
+ let serialized;
183
+ try {
184
+ serialized = JSON.stringify(input);
185
+ }
186
+ catch {
187
+ throw new Error('Platform index must be JSON-serializable');
188
+ }
189
+ if (serialized === undefined)
190
+ return;
191
+ const bytes = new TextEncoder().encode(serialized).byteLength;
192
+ if (bytes > MAX_PLATFORM_INDEX_BYTES) {
193
+ throw new Error(`Platform index is ${bytes} bytes; limit is ${MAX_PLATFORM_INDEX_BYTES}`);
194
+ }
195
+ }
196
+ function sha256Hex(value) {
197
+ const input = new TextEncoder().encode(value);
198
+ const paddedLength = Math.ceil((input.length + 9) / 64) * 64;
199
+ const padded = new Uint8Array(paddedLength);
200
+ padded.set(input);
201
+ padded[input.length] = 0x80;
202
+ const view = new DataView(padded.buffer);
203
+ const bitLength = input.length * 8;
204
+ view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296));
205
+ view.setUint32(paddedLength - 4, bitLength >>> 0);
206
+ const state = new Uint32Array([
207
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
208
+ 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
209
+ ]);
210
+ const words = new Uint32Array(64);
211
+ for (let offset = 0; offset < padded.length; offset += 64) {
212
+ for (let index = 0; index < 16; index++) {
213
+ words[index] = view.getUint32(offset + index * 4);
214
+ }
215
+ for (let index = 16; index < 64; index++) {
216
+ const left = words[index - 15];
217
+ const right = words[index - 2];
218
+ const sigma0 = rotateRight(left, 7) ^ rotateRight(left, 18) ^ (left >>> 3);
219
+ const sigma1 = rotateRight(right, 17) ^ rotateRight(right, 19) ^ (right >>> 10);
220
+ words[index] =
221
+ (words[index - 16] + sigma0 + words[index - 7] + sigma1) >>> 0;
222
+ }
223
+ let a = state[0];
224
+ let b = state[1];
225
+ let c = state[2];
226
+ let d = state[3];
227
+ let e = state[4];
228
+ let f = state[5];
229
+ let g = state[6];
230
+ let h = state[7];
231
+ for (let index = 0; index < 64; index++) {
232
+ const sum1 = rotateRight(e, 6) ^ rotateRight(e, 11) ^ rotateRight(e, 25);
233
+ const choice = (e & f) ^ (~e & g);
234
+ const temporary1 = (h + sum1 + choice + SHA256_CONSTANTS[index] + words[index]) >>> 0;
235
+ const sum0 = rotateRight(a, 2) ^ rotateRight(a, 13) ^ rotateRight(a, 22);
236
+ const majority = (a & b) ^ (a & c) ^ (b & c);
237
+ const temporary2 = (sum0 + majority) >>> 0;
238
+ h = g;
239
+ g = f;
240
+ f = e;
241
+ e = (d + temporary1) >>> 0;
242
+ d = c;
243
+ c = b;
244
+ b = a;
245
+ a = (temporary1 + temporary2) >>> 0;
246
+ }
247
+ state[0] = (state[0] + a) >>> 0;
248
+ state[1] = (state[1] + b) >>> 0;
249
+ state[2] = (state[2] + c) >>> 0;
250
+ state[3] = (state[3] + d) >>> 0;
251
+ state[4] = (state[4] + e) >>> 0;
252
+ state[5] = (state[5] + f) >>> 0;
253
+ state[6] = (state[6] + g) >>> 0;
254
+ state[7] = (state[7] + h) >>> 0;
255
+ }
256
+ return [...state]
257
+ .map((word) => word.toString(16).padStart(8, '0'))
258
+ .join('');
259
+ }
260
+ function rotateRight(value, bits) {
261
+ return (value >>> bits) | (value << (32 - bits));
262
+ }
263
+ const SHA256_CONSTANTS = new Uint32Array([
264
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
265
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
266
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
267
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
268
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
269
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
270
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
271
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
272
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
273
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
274
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
275
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
276
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
277
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
278
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
279
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
280
+ ]);
281
+ export const EMBEDDED_PLATFORM_INDEX = loadPlatformIndex(GENERATED_BROWSER_AUTHORING_INDEX);
@@ -0,0 +1,24 @@
1
+ import type { CompletionItem, Diagnostic, DocumentSymbol, Hover, Location, Position } from './lsp-protocol.js';
2
+ import type { PlatformIndex } from './platform-index.js';
3
+ import type { VirtualDocument } from './vfs.js';
4
+ export declare class RustAnalysis {
5
+ private readonly parser;
6
+ private readonly platformIndex;
7
+ private readonly cache;
8
+ private constructor();
9
+ static create(options: {
10
+ parserWasmUrl: string;
11
+ grammarWasmUrl: string;
12
+ platformIndex: PlatformIndex;
13
+ }): Promise<RustAnalysis>;
14
+ diagnostics(document: VirtualDocument): Diagnostic[];
15
+ completions(document: VirtualDocument, position: Position, workspace: readonly VirtualDocument[]): CompletionItem[];
16
+ hover(document: VirtualDocument, position: Position, workspace: readonly VirtualDocument[]): Hover | null;
17
+ documentSymbols(document: VirtualDocument): DocumentSymbol[];
18
+ definition(document: VirtualDocument, position: Position, workspace: readonly VirtualDocument[]): Location | null;
19
+ invalidate(uri: string): void;
20
+ dispose(): void;
21
+ private workspaceSymbols;
22
+ private analyze;
23
+ }
24
+ //# sourceMappingURL=rust-analysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rust-analysis.d.ts","sourceRoot":"","sources":["../../src/live-coding/rust-analysis.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,KAAK,EACL,QAAQ,EACR,QAAQ,EAET,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAEV,aA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