Skip to content

Commit 16b419f

Browse files
authored
feat: add scoped Class (#302)
1 parent b4a714c commit 16b419f

File tree

3 files changed

+14
-50
lines changed

3 files changed

+14
-50
lines changed

ui/src/components/nodes/Code.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,7 @@ function MyFloatingToolbar({ id, layout, setLayout }) {
319319
// const pod = useStore(store, (state) => state.pods[id]);
320320
const wsRun = useStore(store, (state) => state.wsRun);
321321
const wsRunChain = useStore(store, (state) => state.wsRunChain);
322-
const wsRunNoRewrite = useStore(store, (state) => state.wsRunNoRewrite);
323322
// right, bottom
324-
const getPod = useStore(store, (state) => state.getPod);
325323
const isGuest = useStore(store, (state) => state.role === "GUEST");
326324
const clonePod = useStore(store, (state) => state.clonePod);
327325
const setPaneFocus = useStore(store, (state) => state.setPaneFocus);
@@ -390,17 +388,6 @@ function MyFloatingToolbar({ id, layout, setLayout }) {
390388
</IconButton>
391389
</Tooltip>
392390
)}
393-
{!isGuest && (
394-
<Tooltip title="Run without rewrite">
395-
<IconButton
396-
onClick={() => {
397-
wsRunNoRewrite(id);
398-
}}
399-
>
400-
<PlayDisabledIcon fontSize="inherit" />
401-
</IconButton>
402-
</Tooltip>
403-
)}
404391
<CopyToClipboard
405392
text="dummy"
406393
options={{ debug: true, format: "text/plain", onCopy } as any}

ui/src/lib/parser.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ export function analyzeCode(code: string): CodeAnalysisResult {
146146
}
147147
let tree = parser.parse(code);
148148

149-
const function_def = "(function_definition (identifier) @function)";
149+
// Only match module-level functions, to avoid Class methods.
150+
const function_def = "(module (function_definition (identifier) @function))";
151+
// Match module-level classes as well. Just record as a function.
152+
const class_def = "(module (class_definition (identifier) @class))";
150153

151154
const vardef = `
152155
(module (expression_statement (assignment (identifier) @vardef)))
@@ -156,6 +159,7 @@ export function analyzeCode(code: string): CodeAnalysisResult {
156159
let query_func = parser.getLanguage().query(`
157160
[
158161
${function_def}
162+
${class_def}
159163
]
160164
`);
161165
query_func.matches(tree.rootNode).forEach((match) => {
@@ -176,16 +180,16 @@ export function analyzeCode(code: string): CodeAnalysisResult {
176180
`);
177181

178182
query_var.matches(tree.rootNode).forEach((match) => {
179-
let node = match.captures[0].node;
180-
annotations.push({
181-
name: node.text, // the name of the function or variable
183+
let node = match.captures[0].node;
184+
annotations.push({
185+
name: node.text, // the name of the function or variable
182186
type: "vardef",
183-
startIndex: node.startIndex,
184-
endIndex: node.endIndex,
185-
startPosition: node.startPosition,
186-
endPosition: node.endPosition,
187-
});
188-
});
187+
startIndex: node.startIndex,
188+
endIndex: node.endIndex,
189+
startPosition: node.startPosition,
190+
endPosition: node.endPosition,
191+
});
192+
});
189193

190194
// Do the compilation: unbound variable analysis.
191195
let { unbound, errors } = compileModule(tree.rootNode);

ui/src/lib/store/runtimeSlice.tsx

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ export interface RuntimeSlice {
209209
wsRunScope: (id: string) => void;
210210
wsSendRun: (id: string) => void;
211211
wsRunNext: () => void;
212-
wsRunNoRewrite: (id: string) => void;
213212
chain: string[];
214213
wsRunChain: (id: string) => void;
215214
wsInterruptKernel: ({ lang }) => void;
@@ -452,32 +451,6 @@ export const createRuntimeSlice: StateCreator<MyState, [], [], RuntimeSlice> = (
452451
get().wsSendRun(id);
453452
}
454453
},
455-
wsRunNoRewrite: async (id) => {
456-
if (!get().socket) {
457-
get().addError({
458-
type: "error",
459-
msg: "Runtime not connected",
460-
});
461-
return;
462-
}
463-
const newcode = get().pods[id].content;
464-
465-
// Run the code in remote kernel.
466-
get().setRunning(id);
467-
let pod = get().pods[id];
468-
get().socket?.send(
469-
JSON.stringify({
470-
type: "runCode",
471-
payload: {
472-
lang: pod.lang,
473-
code: newcode,
474-
raw: true,
475-
podId: pod.id,
476-
sessionId: get().sessionId,
477-
},
478-
})
479-
);
480-
},
481454
wsInterruptKernel: ({ lang }) => {
482455
get().socket!.send(
483456
JSON.stringify({

0 commit comments

Comments
 (0)