diff --git a/client/src/components/Infoview.tsx b/client/src/components/Infoview.tsx index e8b0eae..7f3bd54 100644 --- a/client/src/components/Infoview.tsx +++ b/client/src/components/Infoview.tsx @@ -14,7 +14,8 @@ function toLanguageServerPosition (pos: monaco.Position): ls.Position { function Infoview({ editor, editorApi, leanClient } : {editor: monaco.editor.IStandaloneCodeEditor, editorApi: EditorApi, leanClient: LeanClient}) { const [rpcSession, setRpcSession] = useState() const [goals, setGoals] = useState(null) - const [errors, setErrors] = useState(undefined) + const [completed, setCompleted] = useState(false) + const [diagnostics, setDiagnostics] = useState(undefined) const [uri, setUri] = useState() console.log(rpcSession) const fetchInteractiveGoals = () => { @@ -34,12 +35,12 @@ function Infoview({ editor, editorApi, leanClient } : {editor: monaco.editor.ISt }) leanClient.sendRequest("$/lean/rpc/call", {"method":"Game.getDiagnostics", - "params":{"textDocument":{uri}, "position": pos}, + "params":{"textDocument":{uri}, "lineRange": {start: pos.line, end: pos.line + 1}}, "sessionId":rpcSession, "textDocument":{uri}, "position": pos }).then((res) => { - setErrors(res ? res : undefined) + setDiagnostics(res ? res : undefined) console.log(res) }).catch((err) => { console.error(err) @@ -48,6 +49,22 @@ function Infoview({ editor, editorApi, leanClient } : {editor: monaco.editor.ISt } } + const checkCompleted = () => { + const pos = toLanguageServerPosition(editor.getPosition()) + // Get all diagnostics independent of cursor position + leanClient.sendRequest("$/lean/rpc/call", {"method":"Game.getDiagnostics", + "params":{"textDocument":{uri},}, + "sessionId":rpcSession, + "textDocument":{uri}, + "position": pos + }).then((res) => { + // Check that there are no errors and no warnings + setCompleted(!res.some(({severity}) => severity <= 2)) + }).catch((err) => { + console.error(err) + }) + } + useEffect(() => { if (editor) { fetchInteractiveGoals() @@ -76,12 +93,13 @@ function Infoview({ editor, editorApi, leanClient } : {editor: monaco.editor.ISt useEffect(() => { const t = leanClient.didChange(async (ev) => { fetchInteractiveGoals() + checkCompleted() }) return () => { t.dispose() } }, [editor, leanClient, rpcSession]) return (
- +
) } diff --git a/client/src/components/TacticState.tsx b/client/src/components/TacticState.tsx index ee68035..3807fd3 100644 --- a/client/src/components/TacticState.tsx +++ b/client/src/components/TacticState.tsx @@ -52,8 +52,8 @@ function Goal({ goal }) { ) } -function TacticState({ goals, errors, completed }) { - const hasError = typeof errors === "object" && errors.length > 0 +function TacticState({ goals, diagnostics, completed }) { + const hasError = typeof diagnostics === "object" && diagnostics.length > 0 const hasGoal = goals !== null && goals.length > 0 const hasManyGoal = hasGoal && goals.length > 1 return ( @@ -62,7 +62,7 @@ function TacticState({ goals, errors, completed }) { {hasGoal && Main goal at cursor } {completed && Level completed ! 🎉} {hasError && - {errors.map(({severity, message}) => {message})} + {diagnostics.map(({severity, message}) => {message})} } {hasManyGoal && Other goals