Skip to content

Commit

Permalink
feat: add scoped Class (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihebi committed May 10, 2023
1 parent b4a714c commit 16b419f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 50 deletions.
13 changes: 0 additions & 13 deletions ui/src/components/nodes/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ function MyFloatingToolbar({ id, layout, setLayout }) {
// const pod = useStore(store, (state) => state.pods[id]);
const wsRun = useStore(store, (state) => state.wsRun);
const wsRunChain = useStore(store, (state) => state.wsRunChain);
const wsRunNoRewrite = useStore(store, (state) => state.wsRunNoRewrite);
// right, bottom
const getPod = useStore(store, (state) => state.getPod);
const isGuest = useStore(store, (state) => state.role === "GUEST");
const clonePod = useStore(store, (state) => state.clonePod);
const setPaneFocus = useStore(store, (state) => state.setPaneFocus);
Expand Down Expand Up @@ -390,17 +388,6 @@ function MyFloatingToolbar({ id, layout, setLayout }) {
</IconButton>
</Tooltip>
)}
{!isGuest && (
<Tooltip title="Run without rewrite">
<IconButton
onClick={() => {
wsRunNoRewrite(id);
}}
>
<PlayDisabledIcon fontSize="inherit" />
</IconButton>
</Tooltip>
)}
<CopyToClipboard
text="dummy"
options={{ debug: true, format: "text/plain", onCopy } as any}
Expand Down
24 changes: 14 additions & 10 deletions ui/src/lib/parser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ export function analyzeCode(code: string): CodeAnalysisResult {
}
let tree = parser.parse(code);

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

const vardef = `
(module (expression_statement (assignment (identifier) @vardef)))
Expand All @@ -156,6 +159,7 @@ export function analyzeCode(code: string): CodeAnalysisResult {
let query_func = parser.getLanguage().query(`
[
${function_def}
${class_def}
]
`);
query_func.matches(tree.rootNode).forEach((match) => {
Expand All @@ -176,16 +180,16 @@ export function analyzeCode(code: string): CodeAnalysisResult {
`);

query_var.matches(tree.rootNode).forEach((match) => {
let node = match.captures[0].node;
annotations.push({
name: node.text, // the name of the function or variable
let node = match.captures[0].node;
annotations.push({
name: node.text, // the name of the function or variable
type: "vardef",
startIndex: node.startIndex,
endIndex: node.endIndex,
startPosition: node.startPosition,
endPosition: node.endPosition,
});
});
startIndex: node.startIndex,
endIndex: node.endIndex,
startPosition: node.startPosition,
endPosition: node.endPosition,
});
});

// Do the compilation: unbound variable analysis.
let { unbound, errors } = compileModule(tree.rootNode);
Expand Down
27 changes: 0 additions & 27 deletions ui/src/lib/store/runtimeSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ export interface RuntimeSlice {
wsRunScope: (id: string) => void;
wsSendRun: (id: string) => void;
wsRunNext: () => void;
wsRunNoRewrite: (id: string) => void;
chain: string[];
wsRunChain: (id: string) => void;
wsInterruptKernel: ({ lang }) => void;
Expand Down Expand Up @@ -452,32 +451,6 @@ export const createRuntimeSlice: StateCreator<MyState, [], [], RuntimeSlice> = (
get().wsSendRun(id);
}
},
wsRunNoRewrite: async (id) => {
if (!get().socket) {
get().addError({
type: "error",
msg: "Runtime not connected",
});
return;
}
const newcode = get().pods[id].content;

// Run the code in remote kernel.
get().setRunning(id);
let pod = get().pods[id];
get().socket?.send(
JSON.stringify({
type: "runCode",
payload: {
lang: pod.lang,
code: newcode,
raw: true,
podId: pod.id,
sessionId: get().sessionId,
},
})
);
},
wsInterruptKernel: ({ lang }) => {
get().socket!.send(
JSON.stringify({
Expand Down

0 comments on commit 16b419f

Please sign in to comment.