wasm-idle 0.4.0 → 0.5.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.
- package/README.md +111 -2
- package/dist/clang/app.d.ts +4 -0
- package/dist/clang/app.js +330 -15
- package/dist/clang/index.d.ts +10 -0
- package/dist/clang/index.js +284 -25
- package/dist/debug/controller.svelte.d.ts +43 -0
- package/dist/debug/controller.svelte.js +268 -0
- package/dist/debug/editor/index.d.ts +2 -1
- package/dist/debug/editor/index.js +1 -1
- package/dist/debug/editor/monaco.d.ts +8 -0
- package/dist/debug/editor/monaco.js +23 -0
- package/dist/debug/expression.d.ts +24 -0
- package/dist/debug/expression.js +307 -138
- package/dist/debug/index.d.ts +4 -1
- package/dist/debug/index.js +2 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +3 -3
- package/dist/playground/assetBridge.d.ts +20 -0
- package/dist/playground/assetBridge.js +192 -0
- package/dist/playground/assets.d.ts +37 -0
- package/dist/playground/assets.js +105 -0
- package/dist/playground/clang.d.ts +11 -1
- package/dist/playground/clang.js +58 -4
- package/dist/playground/index.d.ts +5 -5
- package/dist/playground/index.js +48 -6
- package/dist/playground/java.d.ts +7 -2
- package/dist/playground/java.js +31 -5
- package/dist/playground/javaStdin.js +235 -2
- package/dist/playground/options.d.ts +18 -0
- package/dist/playground/options.js +15 -1
- package/dist/playground/python.d.ts +7 -1
- package/dist/playground/python.js +50 -5
- package/dist/playground/rust.d.ts +32 -0
- package/dist/playground/rust.js +175 -0
- package/dist/playground/sandbox.d.ts +19 -4
- package/dist/playground/wasmRustVersion.d.ts +1 -0
- package/dist/playground/wasmRustVersion.js +1 -0
- package/dist/playground/worker/assets.d.ts +12 -0
- package/dist/playground/worker/assets.js +257 -0
- package/dist/playground/worker/clang.js +22 -6
- package/dist/playground/worker/java.js +15 -35
- package/dist/playground/worker/python.js +13 -33
- package/dist/playground/worker/rust.d.ts +1 -0
- package/dist/playground/worker/rust.js +159 -0
- package/dist/terminal/Terminal.svelte +121 -18
- package/dist/terminal/Terminal.svelte.d.ts +4 -0
- package/dist/terminal/theme.js +2 -2
- package/dist/terminal/types.d.ts +4 -0
- package/package.json +19 -13
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { fromStore, get, writable } from 'svelte/store';
|
|
2
|
+
export function createDebugSessionController(options = {}) {
|
|
3
|
+
const activeStore = writable(false);
|
|
4
|
+
const pausedStore = writable(false);
|
|
5
|
+
const pausedLineStore = writable(null);
|
|
6
|
+
const localsStore = writable([]);
|
|
7
|
+
const callStackStore = writable([]);
|
|
8
|
+
const runToCursorLineStore = writable(null);
|
|
9
|
+
const watchInputStore = writable('');
|
|
10
|
+
const watchExpressionsStore = writable([]);
|
|
11
|
+
const watchValuesStore = writable([]);
|
|
12
|
+
const breakpointsStore = writable([...(options.breakpoints || [])]);
|
|
13
|
+
const cursorLineStore = writable(options.cursorLine ?? null);
|
|
14
|
+
const terminalStore = writable(options.terminal);
|
|
15
|
+
const adapterStore = writable(options.adapter ?? null);
|
|
16
|
+
const activeState = fromStore(activeStore);
|
|
17
|
+
const pausedState = fromStore(pausedStore);
|
|
18
|
+
const pausedLineState = fromStore(pausedLineStore);
|
|
19
|
+
const localsState = fromStore(localsStore);
|
|
20
|
+
const callStackState = fromStore(callStackStore);
|
|
21
|
+
const runToCursorLineState = fromStore(runToCursorLineStore);
|
|
22
|
+
const watchInputState = fromStore(watchInputStore);
|
|
23
|
+
const watchExpressionsState = fromStore(watchExpressionsStore);
|
|
24
|
+
const watchValuesState = fromStore(watchValuesStore);
|
|
25
|
+
const breakpointsState = fromStore(breakpointsStore);
|
|
26
|
+
const cursorLineState = fromStore(cursorLineStore);
|
|
27
|
+
const terminalState = fromStore(terminalStore);
|
|
28
|
+
const adapterState = fromStore(adapterStore);
|
|
29
|
+
let watchRequestVersion = 0;
|
|
30
|
+
function shouldSyncBreakpoints() {
|
|
31
|
+
if (typeof options.syncBreakpointsWhile === 'function') {
|
|
32
|
+
return options.syncBreakpointsWhile();
|
|
33
|
+
}
|
|
34
|
+
if (typeof options.syncBreakpointsWhile === 'boolean') {
|
|
35
|
+
return options.syncBreakpointsWhile;
|
|
36
|
+
}
|
|
37
|
+
return get(activeStore);
|
|
38
|
+
}
|
|
39
|
+
function getEffectiveBreakpoints() {
|
|
40
|
+
const lines = [...get(breakpointsStore)];
|
|
41
|
+
const runToCursorLine = get(runToCursorLineStore);
|
|
42
|
+
if (runToCursorLine !== null && !lines.includes(runToCursorLine))
|
|
43
|
+
lines.push(runToCursorLine);
|
|
44
|
+
return lines.sort((left, right) => left - right);
|
|
45
|
+
}
|
|
46
|
+
function refreshWatchValues() {
|
|
47
|
+
const expressions = [...get(watchExpressionsStore)];
|
|
48
|
+
const adapter = get(adapterStore);
|
|
49
|
+
const localVariables = [...get(localsStore)];
|
|
50
|
+
const paused = get(pausedStore);
|
|
51
|
+
const terminal = get(terminalStore);
|
|
52
|
+
const version = ++watchRequestVersion;
|
|
53
|
+
if (!expressions.length) {
|
|
54
|
+
watchValuesStore.set([]);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (paused && terminal?.debugEvaluate) {
|
|
58
|
+
watchValuesStore.set(expressions.map((expression) => ({ expression, value: '...' })));
|
|
59
|
+
(async () => {
|
|
60
|
+
const resolved = [];
|
|
61
|
+
for (const expression of expressions) {
|
|
62
|
+
resolved.push({
|
|
63
|
+
expression,
|
|
64
|
+
value: await terminal.debugEvaluate(expression)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (version === watchRequestVersion)
|
|
68
|
+
watchValuesStore.set(resolved);
|
|
69
|
+
})().catch(() => {
|
|
70
|
+
if (version === watchRequestVersion) {
|
|
71
|
+
watchValuesStore.set(expressions.map((expression) => ({ expression, value: 'error' })));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
watchValuesStore.set(expressions.map((expression) => {
|
|
77
|
+
try {
|
|
78
|
+
return {
|
|
79
|
+
expression,
|
|
80
|
+
value: adapter ? adapter.evaluateExpression(expression, localVariables) : 'error'
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return {
|
|
85
|
+
expression,
|
|
86
|
+
value: error instanceof Error && error.message === 'unavailable' ? '?' : 'error'
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
function syncBreakpoints() {
|
|
92
|
+
const terminal = get(terminalStore);
|
|
93
|
+
if (!shouldSyncBreakpoints() || !terminal?.setBreakpoints)
|
|
94
|
+
return;
|
|
95
|
+
void terminal.setBreakpoints(getEffectiveBreakpoints());
|
|
96
|
+
}
|
|
97
|
+
function clearPauseState() {
|
|
98
|
+
runToCursorLineStore.set(null);
|
|
99
|
+
pausedLineStore.set(null);
|
|
100
|
+
localsStore.set([]);
|
|
101
|
+
callStackStore.set([]);
|
|
102
|
+
pausedStore.set(false);
|
|
103
|
+
}
|
|
104
|
+
function reset() {
|
|
105
|
+
activeStore.set(false);
|
|
106
|
+
clearPauseState();
|
|
107
|
+
refreshWatchValues();
|
|
108
|
+
}
|
|
109
|
+
function begin() {
|
|
110
|
+
activeStore.set(true);
|
|
111
|
+
clearPauseState();
|
|
112
|
+
refreshWatchValues();
|
|
113
|
+
syncBreakpoints();
|
|
114
|
+
}
|
|
115
|
+
function handleEvent(event) {
|
|
116
|
+
if (event.type === 'pause') {
|
|
117
|
+
activeStore.set(true);
|
|
118
|
+
runToCursorLineStore.set(null);
|
|
119
|
+
pausedLineStore.set(event.line);
|
|
120
|
+
localsStore.set(event.locals);
|
|
121
|
+
callStackStore.set(event.callStack);
|
|
122
|
+
pausedStore.set(true);
|
|
123
|
+
refreshWatchValues();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (event.type === 'resume') {
|
|
127
|
+
pausedStore.set(false);
|
|
128
|
+
pausedLineStore.set(null);
|
|
129
|
+
localsStore.set([]);
|
|
130
|
+
callStackStore.set([]);
|
|
131
|
+
refreshWatchValues();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
reset();
|
|
135
|
+
}
|
|
136
|
+
function setTerminal(terminal) {
|
|
137
|
+
terminalStore.set(terminal);
|
|
138
|
+
refreshWatchValues();
|
|
139
|
+
syncBreakpoints();
|
|
140
|
+
}
|
|
141
|
+
function setAdapter(adapter) {
|
|
142
|
+
adapterStore.set(adapter);
|
|
143
|
+
refreshWatchValues();
|
|
144
|
+
}
|
|
145
|
+
function setBreakpoints(lines) {
|
|
146
|
+
breakpointsStore.set([...lines]);
|
|
147
|
+
syncBreakpoints();
|
|
148
|
+
}
|
|
149
|
+
function setCursorLine(line) {
|
|
150
|
+
cursorLineStore.set(line);
|
|
151
|
+
}
|
|
152
|
+
function addWatchExpression(expression) {
|
|
153
|
+
const watchInput = get(watchInputStore);
|
|
154
|
+
const watchExpressions = get(watchExpressionsStore);
|
|
155
|
+
const nextExpression = (expression || watchInput).trim();
|
|
156
|
+
if (!nextExpression || watchExpressions.includes(nextExpression))
|
|
157
|
+
return false;
|
|
158
|
+
watchExpressionsStore.set([...watchExpressions, nextExpression]);
|
|
159
|
+
watchInputStore.set('');
|
|
160
|
+
refreshWatchValues();
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
function removeWatchExpression(expression) {
|
|
164
|
+
watchExpressionsStore.set(get(watchExpressionsStore).filter((entry) => entry !== expression));
|
|
165
|
+
refreshWatchValues();
|
|
166
|
+
}
|
|
167
|
+
function clearWatches() {
|
|
168
|
+
watchInputStore.set('');
|
|
169
|
+
watchExpressionsStore.set([]);
|
|
170
|
+
refreshWatchValues();
|
|
171
|
+
}
|
|
172
|
+
async function sendCommand(command) {
|
|
173
|
+
const terminal = get(terminalStore);
|
|
174
|
+
if (!terminal || !get(pausedStore))
|
|
175
|
+
return false;
|
|
176
|
+
await terminal.debugCommand(command);
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
async function runToCursor(targetLine = get(cursorLineStore)) {
|
|
180
|
+
const terminal = get(terminalStore);
|
|
181
|
+
const breakpoints = get(breakpointsStore);
|
|
182
|
+
if (!terminal ||
|
|
183
|
+
!get(pausedStore) ||
|
|
184
|
+
!targetLine ||
|
|
185
|
+
targetLine === get(pausedLineStore) ||
|
|
186
|
+
!terminal.setBreakpoints) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const nextBreakpoints = breakpoints.includes(targetLine)
|
|
190
|
+
? [...breakpoints]
|
|
191
|
+
: [...breakpoints, targetLine].sort((left, right) => left - right);
|
|
192
|
+
runToCursorLineStore.set(breakpoints.includes(targetLine) ? null : targetLine);
|
|
193
|
+
await terminal.setBreakpoints(nextBreakpoints);
|
|
194
|
+
await terminal.debugCommand('continue');
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
async function stop() {
|
|
198
|
+
const terminal = get(terminalStore);
|
|
199
|
+
if (!terminal)
|
|
200
|
+
return false;
|
|
201
|
+
reset();
|
|
202
|
+
await terminal.stop?.();
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
get active() {
|
|
207
|
+
return activeState.current;
|
|
208
|
+
},
|
|
209
|
+
get paused() {
|
|
210
|
+
return pausedState.current;
|
|
211
|
+
},
|
|
212
|
+
get pausedLine() {
|
|
213
|
+
return pausedLineState.current;
|
|
214
|
+
},
|
|
215
|
+
get locals() {
|
|
216
|
+
return localsState.current;
|
|
217
|
+
},
|
|
218
|
+
get callStack() {
|
|
219
|
+
return callStackState.current;
|
|
220
|
+
},
|
|
221
|
+
get runToCursorLine() {
|
|
222
|
+
return runToCursorLineState.current;
|
|
223
|
+
},
|
|
224
|
+
get breakpoints() {
|
|
225
|
+
return breakpointsState.current;
|
|
226
|
+
},
|
|
227
|
+
get effectiveBreakpoints() {
|
|
228
|
+
return getEffectiveBreakpoints();
|
|
229
|
+
},
|
|
230
|
+
get cursorLine() {
|
|
231
|
+
return cursorLineState.current;
|
|
232
|
+
},
|
|
233
|
+
get canRunToCursor() {
|
|
234
|
+
const cursorLine = cursorLineState.current;
|
|
235
|
+
const terminal = terminalState.current;
|
|
236
|
+
return (pausedState.current &&
|
|
237
|
+
cursorLine !== null &&
|
|
238
|
+
cursorLine > 0 &&
|
|
239
|
+
cursorLine !== pausedLineState.current &&
|
|
240
|
+
!!terminal?.setBreakpoints);
|
|
241
|
+
},
|
|
242
|
+
get watchInput() {
|
|
243
|
+
return watchInputState.current;
|
|
244
|
+
},
|
|
245
|
+
set watchInput(value) {
|
|
246
|
+
watchInputStore.set(value);
|
|
247
|
+
},
|
|
248
|
+
get watchExpressions() {
|
|
249
|
+
return watchExpressionsState.current;
|
|
250
|
+
},
|
|
251
|
+
get watchValues() {
|
|
252
|
+
return watchValuesState.current;
|
|
253
|
+
},
|
|
254
|
+
begin,
|
|
255
|
+
reset,
|
|
256
|
+
handleEvent,
|
|
257
|
+
setTerminal,
|
|
258
|
+
setAdapter,
|
|
259
|
+
setBreakpoints,
|
|
260
|
+
setCursorLine,
|
|
261
|
+
sendCommand,
|
|
262
|
+
runToCursor,
|
|
263
|
+
stop,
|
|
264
|
+
addWatchExpression,
|
|
265
|
+
removeWatchExpression,
|
|
266
|
+
clearWatches
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { MonacoDebugView } from './monaco';
|
|
1
|
+
export { MonacoDebugView, attachMonacoDebugActions } from './monaco';
|
|
2
|
+
export type { MonacoDebugActionsOptions } from './monaco';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { MonacoDebugView } from './monaco';
|
|
1
|
+
export { MonacoDebugView, attachMonacoDebugActions } from './monaco';
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { DebugVariable } from '../../playground/options';
|
|
2
2
|
import type { DebugLanguageAdapter } from '../language';
|
|
3
3
|
import type monaco from 'monaco-editor';
|
|
4
|
+
export type MonacoDebugActionsOptions = {
|
|
5
|
+
runToCursorLabel?: string;
|
|
6
|
+
onCursorLineChange?: (line: number | null) => void;
|
|
7
|
+
onRunToCursor?: (line: number | null) => void;
|
|
8
|
+
};
|
|
4
9
|
export declare class MonacoDebugView {
|
|
5
10
|
Monaco: typeof monaco;
|
|
6
11
|
editor: monaco.editor.IStandaloneCodeEditor;
|
|
@@ -16,3 +21,6 @@ export declare class MonacoDebugView {
|
|
|
16
21
|
setPauseState(pausedLine: number | null, locals: DebugVariable[], adapter: DebugLanguageAdapter | null): void;
|
|
17
22
|
dispose(): void;
|
|
18
23
|
}
|
|
24
|
+
export declare function attachMonacoDebugActions(editor: monaco.editor.IStandaloneCodeEditor, options?: MonacoDebugActionsOptions): {
|
|
25
|
+
dispose(): void;
|
|
26
|
+
};
|
|
@@ -103,3 +103,26 @@ export class MonacoDebugView {
|
|
|
103
103
|
this.mouseHandler = null;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
export function attachMonacoDebugActions(editor, options = {}) {
|
|
107
|
+
const disposables = [];
|
|
108
|
+
disposables.push(editor.onDidChangeCursorPosition((event) => {
|
|
109
|
+
options.onCursorLineChange?.(event.position?.lineNumber || null);
|
|
110
|
+
}));
|
|
111
|
+
options.onCursorLineChange?.(editor.getPosition()?.lineNumber || 1);
|
|
112
|
+
if (options.onRunToCursor) {
|
|
113
|
+
disposables.push(editor.addAction({
|
|
114
|
+
id: 'wasm-idle-run-to-cursor',
|
|
115
|
+
label: options.runToCursorLabel || 'Run to Cursor',
|
|
116
|
+
contextMenuGroupId: 'navigation',
|
|
117
|
+
contextMenuOrder: 0.5,
|
|
118
|
+
run: () => options.onRunToCursor?.(editor.getPosition()?.lineNumber || null)
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
dispose() {
|
|
123
|
+
while (disposables.length)
|
|
124
|
+
disposables.pop()?.dispose();
|
|
125
|
+
options.onCursorLineChange?.(null);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
import type { DebugVariable } from '../playground/options';
|
|
2
|
+
export type DebugExpressionScalar = number | boolean | string | null;
|
|
3
|
+
export type DebugExpressionArray = DebugExpressionValue[] & {
|
|
4
|
+
truncated?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export interface DebugExpressionIndexedValue {
|
|
7
|
+
__debugExpressionKind: 'array';
|
|
8
|
+
length?: number;
|
|
9
|
+
truncated?: boolean;
|
|
10
|
+
get: (index: number) => DebugExpressionValue;
|
|
11
|
+
keys?: () => number[];
|
|
12
|
+
}
|
|
13
|
+
export interface DebugExpressionObjectValue {
|
|
14
|
+
__debugExpressionKind: 'object';
|
|
15
|
+
has: (name: string) => boolean;
|
|
16
|
+
get: (name: string) => DebugExpressionValue;
|
|
17
|
+
keys?: () => string[];
|
|
18
|
+
}
|
|
19
|
+
export interface DebugExpressionRecord {
|
|
20
|
+
[key: string]: DebugExpressionValue;
|
|
21
|
+
}
|
|
22
|
+
export type DebugExpressionValue = DebugExpressionScalar | DebugExpressionArray | DebugExpressionIndexedValue | DebugExpressionObjectValue | DebugExpressionRecord;
|
|
23
|
+
export declare const parseStoredDebugValue: (value: string) => DebugExpressionValue;
|
|
24
|
+
export declare const formatDebugExpressionValue: (value: DebugExpressionValue) => string;
|
|
25
|
+
export declare const evaluateDebugExpressionWithResolver: (expression: string, resolveIdentifier: (name: string) => DebugExpressionValue) => string;
|
|
2
26
|
export declare function evaluateDebugExpression(expression: string, variables: DebugVariable[]): string;
|