lean4monaco 1.0.28 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![GitHub license](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/hhu-adam/lean4monaco/blob/main/LICENSE)
2
+ [![npm version](https://img.shields.io/npm/v/lean4monaco.svg)](https://www.npmjs.com/package/lean4monaco)
3
+ [![(Runtime) Build and Test](https://github.com/hhu-adam/lean4monaco/actions/workflows/test.yml/badge.svg)](https://github.com/hhu-adam/lean4monaco/actions/workflows/test.yml)
4
+
1
5
  # Lean 4 Monaco
2
6
 
3
7
  Provides browser support for running Lean in a Monaco editor.
@@ -21,25 +25,51 @@ one or more editors can be created using `LeanMonacoEditor`. Here is an example
21
25
  how to use the classes using React:
22
26
 
23
27
  ```ts
24
- import { LeanMonaco, LeanMonacoEditor } from 'lean4monaco'
28
+ import { LeanMonaco, LeanMonacoEditor, LeanMonacoOptions } from 'lean4monaco'
25
29
 
26
30
  [...]
27
31
 
28
- useEffect(() => {
29
- const leanMonaco = new LeanMonaco()
30
- const leanMonacoEditor = new LeanMonacoEditor()
31
-
32
- ;(async () => {
33
- await leanMonaco.start({websocket: {url: 'ws://localhost:8080/'}})
34
- leanMonaco.setInfoviewElement(infoviewRef.current)
35
- await leanMonacoEditor.start(codeviewRef.current!, '/project/test.lean', '#check Nat')
36
- })()
37
-
38
- return () => {
39
- leanMonacoEditor.dispose()
40
- leanMonaco.dispose()
41
- }
32
+ // Refs for the editor and infoview
33
+ const editorRef = useRef<HTMLDivElement>(null)
34
+ const infoviewRef = useRef<HTMLDivElement>(null)
35
+
36
+ // Lean4monaco options
37
+ const [options, setOptions] = useState<LeanMonacoOptions>({
38
+ websocket: {
39
+ url: 'ws://localhost:8080/'
40
+ },
41
+ htmlElement: undefined, // The wrapper div for monaco
42
+ vscode: {
43
+ "editor.wordWrap": true,
44
+ }
42
45
  })
46
+
47
+ // Optional: restrict monaco's extend (e.g. context menu) to the editor itself
48
+ useEffect(() => {
49
+ setOptions({...options, htmlElement: editorRef.current ?? undefined})
50
+ }, [editorRef])
51
+
52
+ // Start infoview and editor(s)
53
+ useEffect(() => {
54
+ // You must create a single `LeanMonaco` instance (infoview), but you can create multiple
55
+ // `LeanMonacoEditor` instances (editor)
56
+ // You must await `leanMonaco.start` or use `await leanMonaco.whenReady` before
57
+ // starting the editors!
58
+ const leanMonaco = new LeanMonaco()
59
+ const leanMonacoEditor = new LeanMonacoEditor()
60
+
61
+ leanMonaco.setInfoviewElement(infoviewRef.current!)
62
+
63
+ ;(async () => {
64
+ await leanMonaco.start(options)
65
+ await leanMonacoEditor.start(editorRef.current!, '/project/test.lean', '#check Nat')
66
+ })()
67
+
68
+ return () => {
69
+ leanMonaco.dispose()
70
+ leanMonacoEditor.dispose()
71
+ }
72
+ }, [options, infoviewRef, editorRef])
43
73
  ```
44
74
 
45
75
  ### Configure vite
@@ -136,7 +166,10 @@ export default {
136
166
 
137
167
  `lean4monaco` contains a sample project `lean4monaco/demo/` which you can use for comparison.
138
168
 
139
- If you cloned `lean4monaco`, you can run the demo with
169
+ Ideally you clone this repo using `git clone --recurse-submodules <ssh/https address>` to load the included submodule.
170
+ (alternatively, call `git submodule init && git submodule update` inside the cloned the repo).
171
+
172
+ Afterwards, you can run the demo with
140
173
 
141
174
  ```
142
175
  cd lean4monaco
@@ -160,4 +193,15 @@ Some random errors we encountered. If you have more, please share them.
160
193
  ### Warnings on `npm install`
161
194
 
162
195
  * Warnings about `glob` and `inflight` come from `copyfiles`: see [copyfiles#132](https://github.com/calvinmetcalf/copyfiles/pull/132)
163
- * Warning about ` @types/cypress` comes from `cypress-iframe`
196
+ * Warning about ` @types/cypress` comes from `cypress-iframe`
197
+
198
+ ## Development
199
+
200
+ You can run
201
+
202
+ ```
203
+ npm install
204
+ npm run test
205
+ ```
206
+
207
+ for the automated cypress tests.
@@ -32,13 +32,7 @@ export class LeanMonaco {
32
32
  infoviewEl;
33
33
  disposed = false;
34
34
  async start(options) {
35
- if (!options.htmlElement) {
36
- console.debug('[LeanMonaco]: not starting because container is null');
37
- return;
38
- }
39
- else {
40
- console.debug('[LeanMonaco]: starting');
41
- }
35
+ console.debug('[LeanMonaco]: starting');
42
36
  if (LeanMonaco.activeInstance == this) {
43
37
  console.warn('A LeanMonaco instance cannot be started twice.');
44
38
  return;
@@ -68,7 +62,10 @@ export class LeanMonaco {
68
62
  ...getConfigurationServiceOverride(),
69
63
  ...getLanguagesServiceOverride(),
70
64
  ...getModelServiceOverride()
71
- }, options.htmlElement, {
65
+ },
66
+ // The wrapper HTML element determines the extend of certain monaco features
67
+ // such as the right-click context menu.
68
+ options.htmlElement ?? undefined, {
72
69
  workspaceProvider: {
73
70
  trusted: true,
74
71
  workspace: {
@@ -181,7 +178,7 @@ export class LeanMonaco {
181
178
  ...packageJson,
182
179
  contributes: {
183
180
  ...packageJson.contributes,
184
- configuration: packageJson.contributes.configuration,
181
+ configuration: packageJson.contributes.configuration, // Apparently `IExtensionContributions.configuration` has type `any`
185
182
  // TODO: This is suspect, the thrid entry does not have "language", yet it doesn't complain
186
183
  // look into that.
187
184
  grammars: packageJson.contributes.grammars,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lean4monaco",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "Monaco Editor support for the Lean 4 theorem prover.",
5
5
  "keywords": [
6
6
  "lean",
@@ -33,11 +33,12 @@
33
33
  "url": "https://github.com/hhu-adam/lean4monaco"
34
34
  },
35
35
  "scripts": {
36
- "start": "concurrently \"tsc -w --preserveWatchOutput\" \"webpack --watch\" \"npm run watch:copyfiles\" \"cd demo && npm run start_client\" \"cd demo && npm run start_server\" -n tsc,webpack,copyfiles,vite,server -c \"bgGreen.bold,bgBlue.bold,bgCyan.bold,bgYellow.bold,bgMagenta.bold\"",
36
+ "setup_demo": "concurrently \"(cd demo && npm install)\" \"npm run build\" -n install,build -c \"bgCyan.bold,bgBlue.bold\"",
37
+ "start": "npm run setup_demo && concurrently \"tsc -w --preserveWatchOutput\" \"webpack --watch\" \"npm run watch:copyfiles\" \"cd demo && npm run start_client\" \"cd demo && npm run start_server\" -n tsc,webpack,copyfiles,vite,server -c \"bgGreen.bold,bgBlue.bold,bgCyan.bold,bgYellow.bold,bgMagenta.bold\"",
37
38
  "watch:copyfiles": "nodemon --watch ./src --exec \"npm run build:copyfiles\"",
38
39
  "build": "tsc && webpack && npm run build:copyfiles",
39
40
  "build:copyfiles": "cd src && copyfiles \"**/*.json\" \"**/*.css\" \"**/*.ttf\" \"**/*.otf\" \"**/*.svg\" ../dist/",
40
- "test": "(cd demo && npm install && npm run build_server) && concurrently --kill-others \"npm start 1> /dev/null\" \"wait-on http://localhost:5173 && cypress run\" -n server,cypress -s command-cypress"
41
+ "test": "concurrently --hide 0 --kill-others \"npm start\" \"wait-on http://localhost:5173 && cypress run\" -n server,cypress -s command-cypress"
41
42
  },
42
43
  "dependencies": {
43
44
  "@leanprover/infoview": "^0.7.3",