Fix assumption display in inventory and editor mode #84

world_overviews
joneugster 3 years ago
parent 2b159f508f
commit b5927a1024

@ -44,7 +44,7 @@ export function DualEditor({ level, codeviewRef, levelId, worldId, worldSize })
const { typewriterMode } = React.useContext(InputModeContext) const { typewriterMode } = React.useContext(InputModeContext)
return <> return <>
<div className={typewriterMode ? 'hidden' : ''}> <div className={typewriterMode ? 'hidden' : ''}>
<ExerciseStatement data={level} /> <ExerciseStatement data={level} showLeanStatement={true} />
<div ref={codeviewRef} className={'codeview'}></div> <div ref={codeviewRef} className={'codeview'}></div>
</div> </div>
{ec ? {ec ?
@ -131,12 +131,23 @@ function DualEditorMain({ worldId, levelId, level, worldSize }: { worldId: strin
* - Theorem xyz: description * - Theorem xyz: description
* - Theorem xyz * - Theorem xyz
* - Exercises: description * - Exercises: description
*
* If `showLeanStatement` is true, it will additionally display the lean code.
*/ */
function ExerciseStatement({ data }) { function ExerciseStatement({ data, showLeanStatement = false }) {
if (!data?.descrText) { return <></> } if (!(data?.descrText || data?.descrFormat)) { return <></> }
return <div className="exercise-statement"><Markdown> return <>
{(data?.displayName ? `**Theorem** \`${data?.displayName}\`: ` : data?.descrText && "**Exercise**: ") + `${data?.descrText}`} <div className="exercise-statement">
</Markdown></div> {data?.descrText &&
<Markdown>
{(data?.displayName ? `**Theorem** \`${data?.displayName}\`: ` : data?.descrText && "**Exercise**: ") + data?.descrText}
</Markdown>
}
{data?.descrFormat && showLeanStatement &&
<p><code className="lean-code">{data?.descrFormat}</code></p>
}
</div>
</>
} }
// TODO: This is only used in `EditorInterface` // TODO: This is only used in `EditorInterface`

@ -41,6 +41,20 @@
padding-right: .5em; padding-right: .5em;
} }
.exercise-statement {
padding-top: 1em;
padding-bottom: 1em;
}
.exercise-statement p {
margin: 0;
}
.exercise-statement .lean-code {
color: rgba(0, 32, 90, 0.87);
font-size: 12px; /* TODO: is the monaco font-size hardcoded? */
}
.conclusion { .conclusion {
padding: 1em; padding: 1em;
} }

@ -255,31 +255,17 @@ elab "DefinitionDoc" name:ident "as" displayName:str template:str : command =>
/-! ## Add inventory items -/ /-! ## Add inventory items -/
-- namespace Lean.PrettyPrinter
-- def ppSignature' (c : Name) : MetaM String := do
-- let decl ← getConstInfo c
-- let e := .const c (decl.levelParams.map mkLevelParam)
-- let (stx, _) ← delabCore e (delab := Delaborator.delabConstWithSignature)
-- let f ← ppTerm stx
-- return toString f
-- end Lean.PrettyPrinter
def getStatement (name : Name) : CommandElabM MessageData := do def getStatement (name : Name) : CommandElabM MessageData := do
-- let c := name.getId
let decl ← getConstInfo name
-- -- TODO: How to go between CommandElabM and MetaM
-- addCompletionInfo <| .id name c (danglingDot := false) {} none
return ← addMessageContextPartial (.ofPPFormat { pp := fun return ← addMessageContextPartial (.ofPPFormat { pp := fun
| some ctx => ctx.runMetaM <| ppExpr decl.type | some ctx => ctx.runMetaM <| PrettyPrinter.ppSignature name
-- PrettyPrinter.ppSignature' c
-- PrettyPrinter.ppSignature c
| none => return "that's a bug." }) | none => return "that's a bug." })
-- Note: We use `String` because we can't send `MessageData` as json, but -- Note: We use `String` because we can't send `MessageData` as json, but
-- `MessageData` might be better for interactive highlighting. -- `MessageData` might be better for interactive highlighting.
/-- Get a string of the form `my_lemma (n : ) : n + n = 2 * n`. -/ /-- Get a string of the form `my_lemma (n : ) : n + n = 2 * n`.
Note: A statement like `theorem abc : ∀ x : Nat, x ≥ 0` would be turned into
`theorem abc (x : Nat) : x ≥ 0` by `PrettyPrinter.ppSignature`. -/
def getStatementString (name : Name) : CommandElabM String := do def getStatementString (name : Name) : CommandElabM String := do
try try
return ← (← getStatement name).toString return ← (← getStatement name).toString
@ -489,13 +475,11 @@ elab doc:docComment ? attrs:Parser.Term.attributes ?
-- the namespace? -- the namespace?
let currNamespace ← getCurrNamespace let currNamespace ← getCurrNamespace
let st ← match statementName with -- Format theorem statement for displaying
| some name => getStatementString <| currNamespace ++ name.getId let sigString := sig.raw.reprint.getD ""
| none => getStatementString <| currNamespace ++ (defaultDeclName).getId let descrFormat : String := match statementName with
| some name => s!"theorem {name.getId} {sigString} := by"
let head := match statementName with | none => s!"example {sigString} := by"
| some name => Format.join ["theorem ", (currNamespace ++ name.getId).toString]
| none => "example"
modifyCurLevel fun level => pure { level with modifyCurLevel fun level => pure { level with
module := env.header.mainModule module := env.header.mainModule
@ -505,7 +489,7 @@ elab doc:docComment ? attrs:Parser.Term.attributes ?
statementName := match statementName with statementName := match statementName with
| none => default | none => default
| some name => currNamespace ++ name.getId | some name => currNamespace ++ name.getId
descrFormat := (Format.join [head, " ", st, " := by"]).pretty 10 descrFormat := descrFormat
hints := hints hints := hints
tactics := {level.tactics with used := usedInventory.tactics.toArray} tactics := {level.tactics with used := usedInventory.tactics.toArray}
definitions := {level.definitions with used := usedInventory.definitions.toArray} definitions := {level.definitions with used := usedInventory.definitions.toArray}

Loading…
Cancel
Save