Skip to content

fix: scoped func/var annotation re-rendering on switch #194

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 3 commits into from
Jan 4, 2023
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
8 changes: 6 additions & 2 deletions ui/src/components/MyMonaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ export const MyMonaco = memo<MyMonacoProps>(function MyMonaco({
const { setNodes } = useReactFlow();
const annotations = useStore(store, (state) => state.pods[id].annotations);
const showAnnotations = useStore(store, (state) => state.showAnnotations);
const scopedVars = useStore(store, (state) => state.scopedVars);

const value = getPod(id).content || "";
let lang = getPod(id).lang || "javascript";
Expand All @@ -415,10 +416,13 @@ export const MyMonaco = memo<MyMonacoProps>(function MyMonaco({
}, [clearResults, store, wsRun]);

useEffect(() => {
if (editor && showAnnotations) {
if (!editor) return;
if (showAnnotations) {
highlightAnnotations(editor, annotations || []);
} else {
highlightAnnotations(editor, []);
}
}, [annotations, editor, showAnnotations]);
}, [annotations, editor, showAnnotations, scopedVars]);

if (lang === "racket") {
lang = "scheme";
Expand Down
76 changes: 41 additions & 35 deletions ui/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
import Grid from "@mui/material/Grid";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import RestartAltIcon from "@mui/icons-material/RestartAlt";
import Typography from "@mui/material/Typography";
import { useSnackbar, VariantType } from "notistack";

import { gql, useQuery, useMutation, useApolloClient } from "@apollo/client";
Expand Down Expand Up @@ -46,45 +47,48 @@ function SidebarSettings() {
);
return (
<Box>
Settings
<Box>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={scopedVars}
size="small"
color="warning"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setScopedVars(event.target.checked);
}}
/>
}
label="Scoped Vars"
/>
</FormGroup>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={showAnnotations}
size="small"
color="warning"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setShowAnnotations(event.target.checked);
}}
/>
}
label="Show Anotations"
/>
</FormGroup>
<Tooltip title={"Enable Scoped Variables"} disableInteractive>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={scopedVars}
size="small"
color="warning"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setScopedVars(event.target.checked);
}}
/>
}
label="Scoped Variables"
/>
</FormGroup>
</Tooltip>
<Tooltip title={"Show Annotations in Editor"} disableInteractive>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={showAnnotations}
size="small"
color="warning"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setShowAnnotations(event.target.checked);
}}
/>
}
label="Enable Annotations"
/>
</FormGroup>
</Tooltip>
{showAnnotations && (
<Stack spacing={0.5}>
<Box className="myDecoration-function">Function Def</Box>
<Box className="myDecoration-vardef">Variable Def</Box>
<Box className="myDecoration-varuse">Function/Var Use</Box>
<Box className="myDecoration-function">Function Definition</Box>
<Box className="myDecoration-vardef">Variable Definition</Box>
<Box className="myDecoration-varuse">Function/Variable Use</Box>
<Box className="myDecoration-varuse my-underline">
Undefined Vars
Undefined Variable
</Box>
</Stack>
)}
Expand Down Expand Up @@ -435,6 +439,8 @@ export const Sidebar: React.FC<SidebarProps> = ({
<SidebarRuntime />
</Grid>
<Grid item xs={12}>
<Divider />
<Typography variant="h6">Site Settings</Typography>
<SidebarSettings />
</Grid>
<ToastError />
Expand Down