Skip to content

move analyzeCode logic into wsRun #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions ui/src/components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,6 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
// const pod = useStore(store, (state) => state.pods[id]);
const wsRun = useStore(store, (state) => state.wsRun);
const clearResults = useStore(store, (s) => s.clearResults);
const setSymbolTable = useStore(store, (s) => s.setSymbolTable);
const setPodVisibility = useStore(store, (s) => s.setPodVisibility);
const ref = useRef(null);
const [target, setTarget] = React.useState<any>(null);
const [frame] = React.useState({
Expand Down Expand Up @@ -381,18 +379,8 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
deleteNodeById(id);
break;
case ToolTypes.play:
{
// analyze code and set symbol table
// TODO maybe put this logic elsewhere?
let { ispublic, names } = analyzeCode(pod.content);
setPodVisibility(id, ispublic);
console.log("names", names);
if (names) {
setSymbolTable(data.id, names);
}
clearResults(data.id);
wsRun(data.id);
}
clearResults(data.id);
wsRun(data.id);
break;
case ToolTypes.layout:
setLayout(layout === "bottom" ? "right" : "bottom");
Expand Down
9 changes: 8 additions & 1 deletion ui/src/lib/runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createStore, StateCreator, StoreApi } from "zustand";

// FIXME cyclic import
import { RepoSlice } from "./store";
import { rewriteCode } from "./parser";
import { analyzeCode, rewriteCode } from "./parser";

function getChildExports({ id, pods }) {
// get all the exports and reexports. The return would be:
Expand Down Expand Up @@ -711,6 +711,13 @@ export const createRuntimeSlice: StateCreator<
});
return;
}
// Analyze code and set symbol table
let { ispublic, names } = analyzeCode(get().pods[id].content);
get().setPodVisibility(id, ispublic);
if (names) {
get().setSymbolTable(id, names);
}
// Run the code in remote kernel.
doRun({
id,
socket: {
Expand Down