diff --git a/client/src/components/Infoview.tsx b/client/src/components/Infoview.tsx index b6b1ba1..1bf3038 100644 --- a/client/src/components/Infoview.tsx +++ b/client/src/components/Infoview.tsx @@ -11,43 +11,63 @@ function toLanguageServerPosition (pos: monaco.Position): ls.Position { return {line : pos.lineNumber - 1, character: pos.column - 1} } -function Infoview({ ready, editor, editorApi, uri, leanClient } : {ready: boolean, editor: monaco.editor.IStandaloneCodeEditor, editorApi: EditorApi, uri: any, leanClient: LeanClient}) { +function Infoview({ editor, editorApi, leanClient } : {editor: monaco.editor.IStandaloneCodeEditor, editorApi: EditorApi, leanClient: LeanClient}) { const [rpcSession, setRpcSession] = useState() const [goals, setGoals] = useState(null) - const liftOff = async () => { - const rpcSession = await editorApi.createRpcSession(uri) - const fetchInteractiveGoals = () => { + const [uri, setUri] = useState() + console.log(rpcSession) + const fetchInteractiveGoals = () => { + console.log(rpcSession) + if (editor && rpcSession) { const pos = toLanguageServerPosition(editor.getPosition()) leanClient.sendRequest("$/lean/rpc/call", {"method":"Game.getGoals", "params":{"textDocument":{uri}, "position": pos}, "sessionId":rpcSession, "textDocument":{uri}, "position": pos - }).then(({ goals }) => { - setGoals(goals) + }).then((res) => { + setGoals(res ? res.goals : null) console.log(goals) }).catch((err) => { console.error(err) }) } - setRpcSession(rpcSession) - editor.onDidChangeCursorPosition((ev) => { - fetchInteractiveGoals() - }) - leanClient.didChange(async (ev) => { - fetchInteractiveGoals() - }) } useEffect(() => { - if (ready) { - liftOff() + if (editor) { + const t = editor.onDidChangeModel((ev) => { + if (ev.newModelUrl) { + setRpcSession(undefined) + setUri(ev.newModelUrl.toString()) + editorApi.createRpcSession(ev.newModelUrl.toString()).then((rpcSession) => { + setRpcSession(rpcSession) + fetchInteractiveGoals() + }) + } + }) + return () => {t.dispose()} } - }, [ready]) - // Lean.Widget.getInteractiveGoals + }, [editor, rpcSession]); + + useEffect(() => { + if (editor) { + const t = editor.onDidChangeCursorPosition(async (ev) => { + fetchInteractiveGoals() + }) + return () => { t.dispose() } + } + }, [editor, rpcSession]) + + useEffect(() => { + const t = leanClient.didChange(async (ev) => { + fetchInteractiveGoals() + }) + return () => { t.dispose() } + }, [editor, leanClient, rpcSession]) return (
- +
) } diff --git a/client/src/components/Level.tsx b/client/src/components/Level.tsx index e141280..6312d80 100644 --- a/client/src/components/Level.tsx +++ b/client/src/components/Level.tsx @@ -7,7 +7,7 @@ import '@fontsource/roboto/700.css'; import ReactMarkdown from 'react-markdown'; import { MathJax } from "better-react-mathjax"; -import { Button } from '@mui/material'; +import { Button, FormControlLabel, FormGroup, Switch } from '@mui/material'; import Grid from '@mui/material/Unstable_Grid2'; import LeftPanel from './LeftPanel'; @@ -40,6 +40,8 @@ function Level({ nbLevels, level, setCurLevel, setLevelTitle, setFinished }: Lev const [editor, setEditor] = useState(null) const [infoProvider, setInfoProvider] = useState(null) const [infoviewApi, setInfoviewApi] = useState(null) + const [expertInfoview, setExpertInfoview] = useState(false) + const [leanData, setLeanData] = useState({goals: []}) const [history, setHistory] = useState([]) @@ -129,7 +131,7 @@ function Level({ nbLevels, level, setCurLevel, setLevelTitle, setFinished }: Lev processResponse(res) }); - return () => { model.dispose(); } + return () => { model.dispose(); setReady(false) } } }, [editor, level, leanClient]) @@ -157,9 +159,13 @@ function Level({ nbLevels, level, setCurLevel, setLevelTitle, setFinished }: Lev -
- - {/* */} +
+
+ +
+ + { setExpertInfoview(!expertInfoview) }} control={} label="Expert mode" /> +
) diff --git a/client/src/components/TacticState.tsx b/client/src/components/TacticState.tsx index 5442cd8..b739d03 100644 --- a/client/src/components/TacticState.tsx +++ b/client/src/components/TacticState.tsx @@ -25,8 +25,8 @@ function Goal({ goal }) { } {hasAssumption && Assumptions - {goal.assumptions.map((item) => {item[0]} : - {item[1]})} + {goal.assumptions.map((item) => {item.userName} : + {item.type})} } Prove: {goal.goal} @@ -51,7 +51,8 @@ function TacticState({ goals, errors, completed }) { } return ( - {hasGoal && Current goal } + {goals === null && No goals at cursor position} + {hasGoal && Main goal at cursor } {completed && Level completed ! 🎉} {hasError && Spell invocation failed {col}{msg}