Skip to content

Commit

Permalink
hints and diags in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Feb 14, 2024
1 parent 976d1c6 commit c0acde1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
4 changes: 2 additions & 2 deletions client/src/components/hints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ function hasHiddenHints(step: InteractiveGoalsWithHints): boolean {
}


export function MoreHelpButton() {
export function MoreHelpButton({selected=null} : {selected?: number}) {

const {proof, setProof} = React.useContext(ProofContext)
const {deletedChat, setDeletedChat, showHelp, setShowHelp} = React.useContext(DeletedChatContext)

let k = proof.steps.length - (lastStepHasErrors(proof) ? 2 : 1)
let k = (selected === null) ? (proof.steps.length - (lastStepHasErrors(proof) ? 2 : 1)) : selected

const activateHiddenHints = (ev) => {
// If the last step (`k`) has errors, we want the hidden hints from the
Expand Down
31 changes: 31 additions & 0 deletions client/src/components/infoview/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,20 @@ export function Main(props: { world: string, level: number, data: LevelInfo}) {
const {worldId, levelId} = React.useContext(WorldLevelIdContext)

const { proof, setProof } = React.useContext(ProofContext)
const {selectedStep, setSelectedStep} = React.useContext(SelectionContext)
const { setDeletedChat, showHelp, setShowHelp } = React.useContext(DeletedChatContext)


function toggleSelection(line: number) {
return (ev) => {
console.debug('toggled selection')
if (selectedStep == line) {
setSelectedStep(undefined)
} else {
setSelectedStep(line)
}
}
}
console.debug(`template: ${props.data?.template}`)

// React.useEffect (() => {
Expand All @@ -182,6 +195,19 @@ export function Main(props: { world: string, level: number, data: LevelInfo}) {

const curUri = useEventResult(ec.events.changedCursorLocation, loc => loc?.uri);

const curPos: DocumentPosition | undefined =
useEventResult(ec.events.changedCursorLocation, loc => loc ? { uri: loc.uri, ...loc.range.start } : undefined)

// Effect when the cursor changes in the editor
React.useEffect(() => {
// TODO: this is a bit of a hack and will yield unexpected behaviour if lines
// are indented.
let newPos = curPos?.line + (curPos?.character == 0 ? 0 : 1)

// scroll the chat along
setSelectedStep(newPos)
}, [curPos])

useClientNotificationEffect(
'textDocument/didClose',
(params: DidCloseTextDocumentParams) => {
Expand All @@ -208,6 +234,11 @@ export function Main(props: { world: string, level: number, data: LevelInfo}) {
ret = <div className="infoview vscode-light">
{proof.completed && <div className="level-completed">Level completed! 🎉</div>}
<Infos />
<Hints hints={proof.steps[curPos?.line]?.goals[0]?.hints}
showHidden={showHelp.has(curPos?.line)} step={curPos?.line}
selected={selectedStep} toggleSelection={toggleSelection(curPos?.line)}
lastLevel={curPos?.line == proof.steps.length - 1}/>
<MoreHelpButton selected={curPos?.line}/>
</div>
}

Expand Down
14 changes: 11 additions & 3 deletions client/src/components/infoview/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,24 @@ export function AllMessages() {
</a>
</span>
</summary> */}
<AllMessagesBody uri={curPos.uri} key={curPos.uri} messages={iDiags0} />
<AllMessagesBody uri={curPos.uri} key={curPos.uri} messages={iDiags0} curPos={curPos} />
{/* </Details> */}
</RpcContext.Provider>
)
}

/** We factor out the body of {@link AllMessages} which lazily fetches its contents only when expanded. */
function AllMessagesBody({uri, messages}: {uri: DocumentUri, messages: () => Promise<InteractiveDiagnostic[]>}) {
function AllMessagesBody({uri, curPos, messages}: {uri: DocumentUri, curPos: DocumentPosition | undefined , messages: () => Promise<InteractiveDiagnostic[]>}) {
const [msgs, setMsgs] = React.useState<InteractiveDiagnostic[] | undefined>(undefined)
React.useEffect(() => { void messages().then(setMsgs) }, [messages])
React.useEffect(() => { void messages().then(
msgs => setMsgs(msgs.filter(
(d)=>{
//console.log(`message start: ${d.range.start.line}. CurPos: ${curPos.line}`)

// Only show the messages from the line where the cursor is.
return d.range.start.line == curPos.line
}))
) }, [messages, curPos])
if (msgs === undefined) return <div>Loading messages...</div>
else return <MessagesList uri={uri} messages={msgs}/>
}
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Level() {
</WorldLevelIdContext.Provider>
}

function ChatPanel({lastLevel}) {
function ChatPanel({lastLevel, visible = true}) {
const chatRef = useRef<HTMLDivElement>(null)
const {mobile} = useContext(PreferencesContext)
const gameId = useContext(GameIdContext)
Expand Down Expand Up @@ -122,7 +122,7 @@ function ChatPanel({lastLevel}) {

let introText: Array<string> = level?.data?.introduction.split(/\n(\s*\n)+/)

return <div className="chat-panel">
return <div className={`chat-panel ${visible ? '' : 'hidden'}`}>
<div ref={chatRef} className="chat">
{introText?.filter(t => t.trim()).map(((t, i) =>
// Show the level's intro text as hints, too
Expand Down Expand Up @@ -177,7 +177,7 @@ function ChatPanel({lastLevel}) {
}


function ExercisePanel({codeviewRef, visible=true}) {
function ExercisePanel({codeviewRef, visible=true}: {codeviewRef: React.MutableRefObject<HTMLDivElement>, visible?: boolean}) {
const gameId = React.useContext(GameIdContext)
const {worldId, levelId} = useContext(WorldLevelIdContext)
const level = useLoadLevelQuery({game: gameId, world: worldId, level: levelId})
Expand Down Expand Up @@ -602,7 +602,7 @@ function useLevelEditor(codeviewRef, initialCode, initialSelections, onDidChange
setInfoProvider(infoProvider)

// TODO: it looks like we get errors "File Changed" here.
client.restart()
client.restart("Lean4Game")

const editorApi = infoProvider.getApi()

Expand Down

0 comments on commit c0acde1

Please sign in to comment.