From 6d567a696f836f9cbecd7ecd3ba8196b878b3910 Mon Sep 17 00:00:00 2001 From: Alexander Bentkamp Date: Fri, 27 Jan 2023 12:14:08 +0100 Subject: [PATCH] add command line #26 --- client/src/app.css | 2 +- client/src/components/Level.tsx | 5 +- .../src/components/infoview/CommandLine.tsx | 53 +++++++++++++++++++ client/src/components/infoview/goals.tsx | 4 +- client/src/components/infoview/infoview.css | 8 +++ 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 client/src/components/infoview/CommandLine.tsx diff --git a/client/src/app.css b/client/src/app.css index b103e85..a5bca4c 100644 --- a/client/src/app.css +++ b/client/src/app.css @@ -4,7 +4,7 @@ --clr-primary: #1976d2; --clr-code: rgba(0, 32, 90, 0.87); --ff-primary: Roboto; - --ff-code: Roboto Mono; + --ff-code: "Roboto Mono"; } diff --git a/client/src/components/Level.tsx b/client/src/components/Level.tsx index bcdbdd5..49392c0 100644 --- a/client/src/components/Level.tsx +++ b/client/src/components/Level.tsx @@ -100,6 +100,7 @@ const Drawer = styled(MuiDrawer, { shouldForwardProp: (prop) => prop !== 'open' /** End Drawer Test */ +export const MonacoEditorContext = React.createContext(null as any); function Level() { @@ -194,7 +195,9 @@ function Level() { - {editorConnection &&
} + + {editorConnection &&
} + diff --git a/client/src/components/infoview/CommandLine.tsx b/client/src/components/infoview/CommandLine.tsx new file mode 100644 index 0000000..41a453c --- /dev/null +++ b/client/src/components/infoview/CommandLine.tsx @@ -0,0 +1,53 @@ +import * as React from 'react' +import { useRef, useState } from 'react' +import { LspDiagnosticsContext } from '../../../../node_modules/lean4-infoview/src/infoview/contexts'; +import { useServerNotificationEffect } from '../../../../node_modules/lean4-infoview/src/infoview/util'; +import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js' +import { DiagnosticSeverity, PublishDiagnosticsParams } from 'vscode-languageserver-protocol'; +import { MonacoEditorContext } from '../Level' + + +export function CommandLine() { + + const editor = React.useContext(MonacoEditorContext) + const commandInput = useRef() + const [processing, setProcessing] = useState(false) + + // const allDiags = React.useContext(LspDiagnosticsContext) + // const fileDiags = allDiags.get(editor.getModel().uri.toString()) + + + const handleSubmit : React.FormEventHandler = (ev) => { + ev.preventDefault() + var selection = monaco.Selection.fromPositions( + editor.getPosition(), + editor.getModel().getFullModelRange().getEndPosition() + ); + var text = commandInput.current!.value + "\n"; + var op = {range: selection, text: text, forceMoveMarkers: false}; + editor.executeEdits("my-source", [op], editor.getSelections()); + setProcessing(true) + } + + useServerNotificationEffect('textDocument/publishDiagnostics', (params: PublishDiagnosticsParams) => { + if (params.uri == editor.getModel().uri.toString()) { + setProcessing(false) + const hasErrorsOrWarnings = params.diagnostics.some( + (d) => + !d.message.startsWith("unsolved goals") && + (d.severity == DiagnosticSeverity.Error || d.severity == DiagnosticSeverity.Warning) + ) + if (!hasErrorsOrWarnings) { + commandInput.current!.value = ""; + editor.setPosition(editor.getModel().getFullModelRange().getEndPosition()) + } + } + }, []); + + return
+
+ + +
+
+} diff --git a/client/src/components/infoview/goals.tsx b/client/src/components/infoview/goals.tsx index e879e67..6b7f198 100644 --- a/client/src/components/infoview/goals.tsx +++ b/client/src/components/infoview/goals.tsx @@ -8,6 +8,7 @@ import { EditorContext } from '../../../../node_modules/lean4-infoview/src/infov import { Locations, LocationsContext, SelectableLocation } from '../../../../node_modules/lean4-infoview/src/infoview/goalLocation'; import { InteractiveGoal, InteractiveGoals, InteractiveHypothesisBundle } from './rpcApi'; import { Hints } from './hints'; +import { CommandLine } from './CommandLine'; /** Returns true if `h` is inaccessible according to Lean's default name rendering. */ function isInaccessibleName(h: string): boolean { @@ -133,7 +134,7 @@ export const Goal = React.memo((props: GoalProps) => { undefined, [locs, goal.mvarId]) const goalLi =
-
Goal:
+
Target:
@@ -156,6 +157,7 @@ export const Goal = React.memo((props: GoalProps) => { { assumptionHyps.length > 0 &&
Assumptions:
{assumptionHyps.map((h, i) => )}
} + {!filter.reverse && goalLi} {showHints && hints}
diff --git a/client/src/components/infoview/infoview.css b/client/src/components/infoview/infoview.css index bfe049e..d1e6e4b 100644 --- a/client/src/components/infoview/infoview.css +++ b/client/src/components/infoview/infoview.css @@ -35,3 +35,11 @@ font-size: 1.8rem; font-weight: 500; } + +.command-line { + font-family: var(--ff-primary); +} + +.command-line input[type="text"] { + font-family: var(--vscode-editor-font-family); +}