lean4monaco 1.0.0

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.
Files changed (87) hide show
  1. package/README.md +79 -0
  2. package/dist/editor.d.ts +10 -0
  3. package/dist/editor.js +31 -0
  4. package/dist/importmetaurl.d.ts +2 -0
  5. package/dist/importmetaurl.js +26 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +2 -0
  8. package/dist/infowebview.d.ts +21 -0
  9. package/dist/infowebview.js +80 -0
  10. package/dist/leanmonaco.d.ts +26 -0
  11. package/dist/leanmonaco.js +205 -0
  12. package/dist/monaco-lean4/lean4-infoview/package.json +59 -0
  13. package/dist/monaco-lean4/lean4-infoview/src/infoview/index.css +272 -0
  14. package/dist/monaco-lean4/lean4-infoview/test/tsconfig.json +7 -0
  15. package/dist/monaco-lean4/lean4-infoview/tsconfig.json +34 -0
  16. package/dist/monaco-lean4/lean4-infoview-api/package.json +20 -0
  17. package/dist/monaco-lean4/lean4-infoview-api/tsconfig.json +29 -0
  18. package/dist/monaco-lean4/lean4-unicode-input/package.json +19 -0
  19. package/dist/monaco-lean4/lean4-unicode-input/src/abbreviations.json +1836 -0
  20. package/dist/monaco-lean4/lean4-unicode-input/tsconfig.json +18 -0
  21. package/dist/monaco-lean4/lean4-unicode-input-component/package.json +22 -0
  22. package/dist/monaco-lean4/lean4-unicode-input-component/tsconfig.json +18 -0
  23. package/dist/monaco-lean4/lerna.json +4 -0
  24. package/dist/monaco-lean4/package-lock.json +14153 -0
  25. package/dist/monaco-lean4/package.json +39 -0
  26. package/dist/monaco-lean4/vscode-lean4/abbreviationview/tsconfig.json +10 -0
  27. package/dist/monaco-lean4/vscode-lean4/language-configuration.json +157 -0
  28. package/dist/monaco-lean4/vscode-lean4/loogleview/static/index.css +94 -0
  29. package/dist/monaco-lean4/vscode-lean4/loogleview/tsconfig.json +10 -0
  30. package/dist/monaco-lean4/vscode-lean4/package.json +944 -0
  31. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/AbbreviationFeature.d.ts +8 -0
  32. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/AbbreviationFeature.js +20 -0
  33. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/AbbreviationHoverProvider.d.ts +12 -0
  34. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/AbbreviationHoverProvider.js +40 -0
  35. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/AbbreviationRewriterFeature.d.ts +19 -0
  36. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/AbbreviationRewriterFeature.js +77 -0
  37. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/VSCodeAbbreviationConfig.d.ts +13 -0
  38. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/VSCodeAbbreviationConfig.js +29 -0
  39. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/VSCodeAbbreviationRewriter.d.ts +27 -0
  40. package/dist/monaco-lean4/vscode-lean4/src/abbreviation/VSCodeAbbreviationRewriter.js +122 -0
  41. package/dist/monaco-lean4/vscode-lean4/src/config.d.ts +33 -0
  42. package/dist/monaco-lean4/vscode-lean4/src/config.js +119 -0
  43. package/dist/monaco-lean4/vscode-lean4/src/diagnostics/setupNotifs.d.ts +27 -0
  44. package/dist/monaco-lean4/vscode-lean4/src/diagnostics/setupNotifs.js +133 -0
  45. package/dist/monaco-lean4/vscode-lean4/src/infoview.d.ts +69 -0
  46. package/dist/monaco-lean4/vscode-lean4/src/infoview.js +711 -0
  47. package/dist/monaco-lean4/vscode-lean4/src/leanclient.d.ts +67 -0
  48. package/dist/monaco-lean4/vscode-lean4/src/leanclient.js +443 -0
  49. package/dist/monaco-lean4/vscode-lean4/src/rpc.d.ts +16 -0
  50. package/dist/monaco-lean4/vscode-lean4/src/rpc.js +102 -0
  51. package/dist/monaco-lean4/vscode-lean4/src/taskgutter.d.ts +11 -0
  52. package/dist/monaco-lean4/vscode-lean4/src/taskgutter.js +130 -0
  53. package/dist/monaco-lean4/vscode-lean4/src/utils/batch.d.ts +37 -0
  54. package/dist/monaco-lean4/vscode-lean4/src/utils/batch.js +203 -0
  55. package/dist/monaco-lean4/vscode-lean4/src/utils/clientProvider.d.ts +41 -0
  56. package/dist/monaco-lean4/vscode-lean4/src/utils/clientProvider.js +205 -0
  57. package/dist/monaco-lean4/vscode-lean4/src/utils/converters.d.ts +16 -0
  58. package/dist/monaco-lean4/vscode-lean4/src/utils/converters.js +129 -0
  59. package/dist/monaco-lean4/vscode-lean4/src/utils/elan.d.ts +3 -0
  60. package/dist/monaco-lean4/vscode-lean4/src/utils/elan.js +4 -0
  61. package/dist/monaco-lean4/vscode-lean4/src/utils/envPath.d.ts +21 -0
  62. package/dist/monaco-lean4/vscode-lean4/src/utils/envPath.js +53 -0
  63. package/dist/monaco-lean4/vscode-lean4/src/utils/exturi.d.ts +35 -0
  64. package/dist/monaco-lean4/vscode-lean4/src/utils/exturi.js +136 -0
  65. package/dist/monaco-lean4/vscode-lean4/src/utils/fsHelper.d.ts +17 -0
  66. package/dist/monaco-lean4/vscode-lean4/src/utils/fsHelper.js +36 -0
  67. package/dist/monaco-lean4/vscode-lean4/src/utils/leanInstaller.d.ts +37 -0
  68. package/dist/monaco-lean4/vscode-lean4/src/utils/leanInstaller.js +210 -0
  69. package/dist/monaco-lean4/vscode-lean4/src/utils/logger.d.ts +7 -0
  70. package/dist/monaco-lean4/vscode-lean4/src/utils/logger.js +20 -0
  71. package/dist/monaco-lean4/vscode-lean4/src/utils/notifs.d.ts +24 -0
  72. package/dist/monaco-lean4/vscode-lean4/src/utils/notifs.js +110 -0
  73. package/dist/monaco-lean4/vscode-lean4/src/utils/projectInfo.d.ts +9 -0
  74. package/dist/monaco-lean4/vscode-lean4/src/utils/projectInfo.js +125 -0
  75. package/dist/monaco-lean4/vscode-lean4/syntaxes/codeblock.json +45 -0
  76. package/dist/monaco-lean4/vscode-lean4/syntaxes/lean4-markdown.json +2637 -0
  77. package/dist/monaco-lean4/vscode-lean4/syntaxes/lean4.json +127 -0
  78. package/dist/monaco-lean4/vscode-lean4/tsconfig.json +18 -0
  79. package/dist/monaco-lean4/vscode-lean4/webview/tsconfig.json +11 -0
  80. package/dist/monacoleanclient.d.ts +4 -0
  81. package/dist/monacoleanclient.js +17 -0
  82. package/dist/preconditions.d.ts +4 -0
  83. package/dist/preconditions.js +3 -0
  84. package/dist/vscode.css +408 -0
  85. package/dist/webview.d.ts +1 -0
  86. package/dist/webview.js +9 -0
  87. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Lean 4 Monaco
2
+
3
+ ## Usage
4
+
5
+ Install this package in your npm project.
6
+ ```
7
+ npm install lean4monaco
8
+ ```
9
+
10
+ The package contains two main classes: `LeanMonaco` and `LeanMonacoEditor`. The
11
+ class `LeanMonaco` can only have exactly one active instance and arranges the
12
+ correct setup of the Monaco Services and the VSCode API. When it is started,
13
+ one or more editors can be created using `LeanMonacoEditor`. Here is an example
14
+ how to use the classes using React:
15
+
16
+ ```ts
17
+ import { LeanMonaco, LeanMonacoEditor } from 'lean4monaco'
18
+
19
+ [...]
20
+
21
+ useEffect(() => {
22
+ const leanMonaco = new LeanMonaco()
23
+ const leanMonacoEditor = new LeanMonacoEditor()
24
+
25
+ ;(async () => {
26
+ await leanMonaco.start('ws://localhost:8080/')
27
+ leanMonaco.setInfoviewElement(infoviewRef.current)
28
+ await leanMonacoEditor.start(codeviewRef.current!, '/project/test.lean', '#check Nat')
29
+ })()
30
+
31
+ return () => {
32
+ leanMonacoEditor.dispose()
33
+ leanMonaco.dispose()
34
+ }
35
+ })
36
+ ```
37
+
38
+ For some reason, the file (here `test.lean`) cannot be at the root of the file system, i.e., not `/test.lean` instead of `/project/test.lean`. (TODO: find out why)
39
+
40
+ The package uses the Lean 4 VSCode extension, which is intended to run in a nodejs runtime. Therefore, we need to install node polyfills.
41
+ Here is how this can be done if your project uses Vite:
42
+ ```
43
+ npm install vite-plugin-node-polyfills memfs
44
+ ```
45
+
46
+ ```ts
47
+ // vite.config.ts
48
+ import { nodePolyfills } from 'vite-plugin-node-polyfills'
49
+
50
+ export default {
51
+ plugins: [
52
+ nodePolyfills({
53
+ overrides: {
54
+ fs: 'memfs',
55
+ },
56
+ }),
57
+ ],
58
+ }
59
+ ```
60
+
61
+ For Vite dev mode to work properly, the following plugin is necessary:
62
+ ```
63
+ npm install 'https://gitpkg.vercel.app/abentkamp/monacotest2/esbuild-import-meta-url-plugin?ec9666e' --save-dev
64
+ ```
65
+ This could be replaced by `@codingame/esbuild-import-meta-url-plugin` when this PR is accepted: https://github.com/CodinGame/esbuild-import-meta-url-plugin/pull/5
66
+
67
+ ```ts
68
+ // vite.config.ts
69
+ import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin'
70
+
71
+ export default {
72
+ optimizeDeps: {
73
+ esbuildOptions: {
74
+ plugins: [importMetaUrlPlugin]
75
+ }
76
+ },
77
+ [...]
78
+ }
79
+ ```
@@ -0,0 +1,10 @@
1
+ import { ITextFileEditorModel } from 'vscode/monaco';
2
+ import * as monaco from 'monaco-editor';
3
+ import { IReference } from '@codingame/monaco-vscode-editor-service-override';
4
+ export declare class LeanMonacoEditor {
5
+ editor: monaco.editor.IStandaloneCodeEditor;
6
+ modelRef: IReference<ITextFileEditorModel>;
7
+ disposed: boolean;
8
+ start(editorEl: HTMLElement, fileName: string, code: string): Promise<void>;
9
+ dispose(): void;
10
+ }
package/dist/editor.js ADDED
@@ -0,0 +1,31 @@
1
+ import { Uri } from 'vscode';
2
+ import { fs } from 'memfs';
3
+ import { createModelReference } from 'vscode/monaco';
4
+ import * as monaco from 'monaco-editor';
5
+ import path from 'path';
6
+ export class LeanMonacoEditor {
7
+ editor;
8
+ modelRef;
9
+ disposed = false;
10
+ async start(editorEl, fileName, code) {
11
+ if (this.disposed)
12
+ return;
13
+ // Create file for clientProvider to find
14
+ fs.mkdirSync(path.dirname(fileName), { recursive: true });
15
+ fs.writeFileSync(fileName, '');
16
+ // Create editor and model
17
+ const theme = "Visual Studio Light"; //"Visual Studio Dark" //"Default Light Modern" //"Default Light+" //"Default Dark+" //"Default High Contrast"
18
+ this.editor = monaco.editor.create(editorEl, { automaticLayout: true, theme });
19
+ this.modelRef = await createModelReference(Uri.parse(fileName), code);
20
+ this.editor.setModel(this.modelRef.object.textEditorModel);
21
+ // Set focus on editor to trigger infoview to open
22
+ this.editor.focus();
23
+ }
24
+ dispose() {
25
+ if (this.modelRef)
26
+ this.modelRef.dispose();
27
+ if (this.editor)
28
+ this.editor.dispose();
29
+ this.disposed = true;
30
+ }
31
+ }
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'esbuild';
2
+ export declare const importMetaUrlPlugin: Plugin;
@@ -0,0 +1,26 @@
1
+ import * as fs from 'fs';
2
+ import url from 'url';
3
+ import { resolve } from 'import-meta-resolve';
4
+ // Fix for @codingame/esbuild-import-meta-url-plugin, see https://github.com/CodinGame/esbuild-import-meta-url-plugin/pull/5
5
+ // TODO: remove this when pull request gets accepted
6
+ export const importMetaUrlPlugin = {
7
+ name: 'import.meta.url',
8
+ setup({ onLoad }) {
9
+ // Help vite that bundles/move files in dev mode without touching `import.meta.url` which breaks asset urls
10
+ onLoad({ filter: /.*\.js$/, namespace: 'file' }, async (args) => {
11
+ const code = fs.readFileSync(args.path, 'utf8');
12
+ const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/g;
13
+ let i = 0;
14
+ let newCode = '';
15
+ for (let match = assetImportMetaUrlRE.exec(code); match != null; match = assetImportMetaUrlRE.exec(code)) {
16
+ newCode += code.slice(i, match.index);
17
+ const path = match[1].slice(1, -1);
18
+ const resolved = resolve(path, url.pathToFileURL(args.path).toString());
19
+ newCode += `new URL(${JSON.stringify(url.fileURLToPath(resolved))}, import.meta.url)`;
20
+ i = assetImportMetaUrlRE.lastIndex;
21
+ }
22
+ newCode += code.slice(i);
23
+ return { contents: newCode };
24
+ });
25
+ }
26
+ };
@@ -0,0 +1,2 @@
1
+ export * from './editor';
2
+ export * from './leanmonaco';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './editor';
2
+ export * from './leanmonaco';
@@ -0,0 +1,21 @@
1
+ import { EditorApi, InfoviewApi } from "@leanprover/infoview-api";
2
+ import { InfoWebviewFactory, InfoWebview } from "./monaco-lean4/vscode-lean4/src/infoview";
3
+ import { Rpc } from "./monaco-lean4/vscode-lean4/src/rpc";
4
+ import { ViewColumn } from "vscode";
5
+ export declare class IFrameInfoWebview implements InfoWebview {
6
+ private iframe;
7
+ rpc: Rpc;
8
+ visible: boolean;
9
+ private onDidDisposeEmitter;
10
+ onDidDispose: import("vscode").Event<void>;
11
+ api: InfoviewApi;
12
+ constructor(iframe: HTMLIFrameElement, rpc: Rpc);
13
+ dispose(): void;
14
+ reveal(viewColumn?: ViewColumn, preserveFocus?: boolean): void;
15
+ }
16
+ export declare class IFrameInfoWebviewFactory implements InfoWebviewFactory {
17
+ private infoviewElement;
18
+ setInfoviewElement(infoviewElement: HTMLElement): void;
19
+ make(editorApi: EditorApi, stylesheet: string, column: number): IFrameInfoWebview;
20
+ private initialHtml;
21
+ }
@@ -0,0 +1,80 @@
1
+ import { Rpc } from "./monaco-lean4/vscode-lean4/src/rpc";
2
+ import { EventEmitter } from "vscode";
3
+ export class IFrameInfoWebview {
4
+ iframe;
5
+ rpc;
6
+ visible = true;
7
+ onDidDisposeEmitter = new EventEmitter();
8
+ onDidDispose = this.onDidDisposeEmitter.event;
9
+ api;
10
+ constructor(iframe, rpc) {
11
+ this.iframe = iframe;
12
+ this.rpc = rpc;
13
+ this.api = rpc.getApi();
14
+ }
15
+ dispose() {
16
+ this.iframe.remove();
17
+ this.onDidDisposeEmitter.fire();
18
+ }
19
+ reveal(viewColumn, preserveFocus) {
20
+ }
21
+ }
22
+ export class IFrameInfoWebviewFactory {
23
+ infoviewElement;
24
+ setInfoviewElement(infoviewElement) {
25
+ this.infoviewElement = infoviewElement;
26
+ }
27
+ make(editorApi, stylesheet, column) {
28
+ const iframe = document.createElement("iframe");
29
+ this.infoviewElement.append(iframe);
30
+ iframe.contentWindow.document.open();
31
+ iframe.contentWindow.document.write(this.initialHtml(stylesheet));
32
+ iframe.contentWindow.document.close();
33
+ // Note that an extension can send data to its webviews using webview.postMessage().
34
+ // This method sends any JSON serializable data to the webview. The message is received
35
+ // inside the webview through the standard message event.
36
+ // The receiving of these messages is done inside webview\index.ts where it
37
+ // calls window.addEventListener('message',...
38
+ const rpc = new Rpc(m => {
39
+ try {
40
+ // JSON.stringify is needed here to serialize getters such as `Position.line` and `Position.character`
41
+ void iframe.contentWindow.postMessage(JSON.stringify(m));
42
+ }
43
+ catch (e) {
44
+ // ignore any disposed object exceptions
45
+ }
46
+ });
47
+ rpc.register(editorApi);
48
+ // Similarly, we can received data from the webview by listening to onDidReceiveMessage.
49
+ document.defaultView.addEventListener('message', m => {
50
+ if (m.source != iframe.contentWindow) {
51
+ return;
52
+ }
53
+ try {
54
+ rpc.messageReceived(JSON.parse(m.data));
55
+ }
56
+ catch {
57
+ // ignore any disposed object exceptions
58
+ }
59
+ });
60
+ return new IFrameInfoWebview(iframe, rpc);
61
+ }
62
+ initialHtml(stylesheet) {
63
+ return `
64
+ <!DOCTYPE html>
65
+ <html>
66
+ <head>
67
+ <meta charset="UTF-8" />
68
+ <meta http-equiv="Content-type" content="text/html;charset=utf-8">
69
+ <title>Infoview</title>
70
+ <style>${stylesheet}</style>
71
+ <link rel="stylesheet" href="${new URL('./vscode.css', import.meta.url)}">
72
+ <link rel="stylesheet" href="${new URL('./monaco-lean4/lean4-infoview/src/infoview/index.css', import.meta.url)}">
73
+ </head>
74
+ <body>
75
+ <div id="react_root"></div>
76
+ <script type="module" src="${new URL('./webview.js', import.meta.url)}"></script>
77
+ </body>
78
+ </html>`;
79
+ }
80
+ }
@@ -0,0 +1,26 @@
1
+ import 'vscode/localExtensionHost';
2
+ import { RegisterExtensionResult } from 'monaco-editor-wrapper';
3
+ import { LeanClientProvider } from './monaco-lean4/vscode-lean4/src/utils/clientProvider';
4
+ import { InfoProvider } from './monaco-lean4/vscode-lean4/src/infoview';
5
+ import { AbbreviationFeature } from './monaco-lean4/vscode-lean4/src/abbreviation/AbbreviationFeature';
6
+ import { LeanTaskGutter } from './monaco-lean4/vscode-lean4/src/taskgutter';
7
+ import { IFrameInfoWebviewFactory } from './infowebview';
8
+ import { Logger } from 'monaco-languageclient/tools';
9
+ import { DisposableStore } from 'vscode/monaco';
10
+ export declare class LeanMonaco {
11
+ ready: (value: void | PromiseLike<void>) => void;
12
+ whenReady: Promise<void>;
13
+ static activeInstance: LeanMonaco | null;
14
+ logger: Logger;
15
+ registerFileUrlResults: DisposableStore;
16
+ extensionRegisterResult: RegisterExtensionResult | undefined;
17
+ clientProvider: LeanClientProvider | undefined;
18
+ infoProvider: InfoProvider | undefined;
19
+ iframeWebviewFactory: IFrameInfoWebviewFactory | undefined;
20
+ abbreviationFeature: AbbreviationFeature | undefined;
21
+ taskGutter: LeanTaskGutter | undefined;
22
+ disposed: boolean;
23
+ start(websocketUrl: string): Promise<void>;
24
+ setInfoviewElement(infoviewEl: HTMLElement): void;
25
+ dispose(): void;
26
+ }
@@ -0,0 +1,205 @@
1
+ import 'vscode/localExtensionHost';
2
+ import { LeanClientProvider } from './monaco-lean4/vscode-lean4/src/utils/clientProvider';
3
+ import { Uri } from 'vscode';
4
+ import { InfoProvider } from './monaco-lean4/vscode-lean4/src/infoview';
5
+ import { AbbreviationFeature } from './monaco-lean4/vscode-lean4/src/abbreviation/AbbreviationFeature';
6
+ import { LeanTaskGutter } from './monaco-lean4/vscode-lean4/src/taskgutter';
7
+ import { IFrameInfoWebviewFactory } from './infowebview';
8
+ import { setupMonacoClient } from './monacoleanclient';
9
+ import { checkLean4ProjectPreconditions } from './preconditions';
10
+ import { checkServiceConsistency } from 'monaco-editor-wrapper/vscode/services';
11
+ import { Logger } from 'monaco-languageclient/tools';
12
+ import getConfigurationServiceOverride from '@codingame/monaco-vscode-configuration-service-override';
13
+ import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override';
14
+ import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-override';
15
+ import { initServices } from 'monaco-languageclient/vscode/services';
16
+ import { registerExtension } from 'vscode/extensions';
17
+ import { DisposableStore } from 'vscode/monaco';
18
+ const extensionFilesOrContents = new Map();
19
+ extensionFilesOrContents.set('/language-configuration.json', new URL('./monaco-lean4/vscode-lean4/language-configuration.json', import.meta.url));
20
+ extensionFilesOrContents.set('/syntaxes/lean4.json', new URL('./monaco-lean4/vscode-lean4/syntaxes/lean4.json', import.meta.url));
21
+ extensionFilesOrContents.set('/syntaxes/lean4-markdown.json', new URL('./monaco-lean4/vscode-lean4/syntaxes/lean4-markdown.json', import.meta.url));
22
+ extensionFilesOrContents.set('/syntaxes/codeblock.json', new URL('./monaco-lean4/vscode-lean4/syntaxes/codeblock.json', import.meta.url));
23
+ const extensionConfig = {
24
+ name: 'lean4web',
25
+ publisher: 'leanprover-community',
26
+ version: '1.0.0',
27
+ engines: {
28
+ vscode: '*'
29
+ },
30
+ "contributes": {
31
+ "languages": [
32
+ {
33
+ "id": "lean4",
34
+ "configuration": "./language-configuration.json",
35
+ "extensions": [
36
+ ".lean"
37
+ ],
38
+ },
39
+ {
40
+ "id": "lean4markdown",
41
+ "aliases": [],
42
+ "extensions": [
43
+ ".lean4markdown"
44
+ ],
45
+ "configuration": "./language-configuration.json"
46
+ }
47
+ ],
48
+ "grammars": [
49
+ {
50
+ "language": "lean4",
51
+ "scopeName": "source.lean4",
52
+ "path": "./syntaxes/lean4.json"
53
+ },
54
+ {
55
+ "language": "lean4markdown",
56
+ "scopeName": "source.lean4.markdown",
57
+ "path": "./syntaxes/lean4-markdown.json"
58
+ },
59
+ {
60
+ "language": "lean4",
61
+ "scopeName": "markdown.lean4.codeblock",
62
+ "path": "./syntaxes/codeblock.json",
63
+ "injectTo": [
64
+ "text.html.markdown"
65
+ ],
66
+ "embeddedLanguages": {
67
+ "meta.embedded.block.lean4": "lean4"
68
+ }
69
+ }
70
+ ],
71
+ }
72
+ };
73
+ const serviceConfig = {
74
+ userServices: {
75
+ ...getTextmateServiceOverride(),
76
+ ...getThemeServiceOverride(),
77
+ ...getConfigurationServiceOverride()
78
+ },
79
+ workspaceConfig: {
80
+ workspaceProvider: {
81
+ trusted: true,
82
+ workspace: {
83
+ workspaceUri: Uri.file('/workspace')
84
+ },
85
+ async open() {
86
+ return false;
87
+ }
88
+ }
89
+ }
90
+ };
91
+ const websocketOptions = {
92
+ $type: 'WebSocketUrl',
93
+ url: '',
94
+ startOptions: {
95
+ onCall: () => {
96
+ console.log('Connected to socket.');
97
+ },
98
+ reportStatus: true
99
+ },
100
+ stopOptions: {
101
+ onCall: () => {
102
+ console.log('Disconnected from socket.');
103
+ },
104
+ reportStatus: true
105
+ }
106
+ };
107
+ export class LeanMonaco {
108
+ ready;
109
+ whenReady = new Promise((resolve) => {
110
+ this.ready = resolve;
111
+ });
112
+ static activeInstance = null;
113
+ logger = new Logger();
114
+ registerFileUrlResults = new DisposableStore();
115
+ extensionRegisterResult;
116
+ clientProvider;
117
+ infoProvider;
118
+ iframeWebviewFactory;
119
+ abbreviationFeature;
120
+ taskGutter;
121
+ disposed = false;
122
+ async start(websocketUrl) {
123
+ if (LeanMonaco.activeInstance == this) {
124
+ console.warn('A LeanMonaco instance cannot be started twice.');
125
+ return;
126
+ }
127
+ if (LeanMonaco.activeInstance) {
128
+ console.warn('There can only be one active LeanMonaco instance at a time. Disposing previous instance.');
129
+ LeanMonaco.activeInstance?.dispose();
130
+ }
131
+ LeanMonaco.activeInstance = this;
132
+ if (!window.MonacoEnvironment?.getWorker) {
133
+ const workerLoaders = {
134
+ editorWorkerService: () => new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url), { type: 'module' }),
135
+ textMateWorker: () => new Worker(new URL('@codingame/monaco-vscode-textmate-service-override/worker', import.meta.url), { type: 'module' }),
136
+ };
137
+ window.MonacoEnvironment = {
138
+ getWorker: function (moduleId, label) {
139
+ const workerFactory = workerLoaders[label];
140
+ if (workerFactory != null) {
141
+ return workerFactory();
142
+ }
143
+ throw new Error(`Unimplemented worker ${label} (${moduleId})`);
144
+ }
145
+ };
146
+ }
147
+ await initServices({
148
+ serviceConfig,
149
+ caller: `Lean monaco-editor`,
150
+ performChecks: checkServiceConsistency,
151
+ logger: this.logger
152
+ });
153
+ await (await import('@codingame/monaco-vscode-theme-defaults-default-extension')).whenReady;
154
+ if (this.disposed)
155
+ return;
156
+ this.extensionRegisterResult = registerExtension(extensionConfig, 1 /* ExtensionHostKind.LocalProcess */);
157
+ if (extensionFilesOrContents) {
158
+ for (const entry of extensionFilesOrContents) {
159
+ const registerFileUrlResult = this.extensionRegisterResult.registerFileUrl(entry[0], entry[1].href);
160
+ this.registerFileUrlResults.add(registerFileUrlResult);
161
+ }
162
+ }
163
+ await this.extensionRegisterResult.whenReady();
164
+ if (this.disposed)
165
+ return;
166
+ this.abbreviationFeature = new AbbreviationFeature({});
167
+ this.clientProvider = new LeanClientProvider({
168
+ installChanged: () => { return { dispose: () => { } }; },
169
+ testLeanVersion: () => { return "lean4/stable"; },
170
+ getElanDefaultToolchain: () => { return "lean4/stable"; }
171
+ }, { appendLine: () => { }
172
+ }, setupMonacoClient({
173
+ ...websocketOptions,
174
+ url: websocketUrl,
175
+ }), checkLean4ProjectPreconditions, (docUri) => { return true; });
176
+ this.taskGutter = new LeanTaskGutter(this.clientProvider, { asAbsolutePath: (path) => Uri.parse(`${new URL('monaco-lean4/vscode-lean4/' + path, import.meta.url)}`), });
177
+ if (!this.iframeWebviewFactory)
178
+ this.iframeWebviewFactory = new IFrameInfoWebviewFactory();
179
+ this.infoProvider = new InfoProvider(this.clientProvider, { language: 'lean4' }, {}, this.iframeWebviewFactory);
180
+ this.ready();
181
+ }
182
+ setInfoviewElement(infoviewEl) {
183
+ if (!this.iframeWebviewFactory)
184
+ this.iframeWebviewFactory = new IFrameInfoWebviewFactory();
185
+ this.iframeWebviewFactory.setInfoviewElement(infoviewEl);
186
+ }
187
+ dispose() {
188
+ if (LeanMonaco.activeInstance == this) {
189
+ LeanMonaco.activeInstance = null;
190
+ }
191
+ this.registerFileUrlResults?.dispose();
192
+ this.registerFileUrlResults = new DisposableStore();
193
+ this.extensionRegisterResult?.dispose();
194
+ this.extensionRegisterResult = undefined;
195
+ this.disposed = true;
196
+ this.infoProvider?.dispose();
197
+ this.infoProvider = undefined;
198
+ this.taskGutter?.dispose();
199
+ this.taskGutter = undefined;
200
+ this.clientProvider?.dispose();
201
+ this.clientProvider = undefined;
202
+ this.abbreviationFeature?.dispose();
203
+ this.abbreviationFeature = undefined;
204
+ }
205
+ }
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@leanprover/infoview",
3
+ "version": "0.7.2",
4
+ "description": "An interactive display for the Lean 4 theorem prover.",
5
+ "scripts": {
6
+ "watch": "rollup --config --environment NODE_ENV:development --watch",
7
+ "build": "rollup --config --environment NODE_ENV:production",
8
+ "watchTest": "npm run watch",
9
+ "test": "tsc -p test/tsconfig.json"
10
+ },
11
+ "exports": {
12
+ ".": "./dist/index.development.js",
13
+ "./loader": "./dist/loader.production.min.js",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "typesVersions": {
17
+ "*": {
18
+ "*": [
19
+ "dist/index.d.ts"
20
+ ],
21
+ "loader": [
22
+ "dist/loader.d.ts"
23
+ ]
24
+ }
25
+ },
26
+ "files": [
27
+ "dist/*"
28
+ ],
29
+ "type": "module",
30
+ "license": "Apache-2.0",
31
+ "devDependencies": {
32
+ "@floating-ui/react": "^0.24.7",
33
+ "@rollup/plugin-commonjs": "^23.0.7",
34
+ "@rollup/plugin-node-resolve": "^15.1.0",
35
+ "@rollup/plugin-replace": "^5.0.2",
36
+ "@rollup/plugin-terser": "^0.1.0",
37
+ "@rollup/plugin-typescript": "^9.0.2",
38
+ "@rollup/plugin-url": "^8.0.1",
39
+ "@types/marked": "^4.3.1",
40
+ "@types/react": "^18.2.15",
41
+ "@types/react-dom": "^18.2.7",
42
+ "current-release": "npm:@leanprover/infoview@latest",
43
+ "react": "^18.2.0",
44
+ "react-dom": "^18.2.0",
45
+ "rollup": "^3.26.2",
46
+ "rollup-plugin-css-only": "^4.3.0",
47
+ "typescript": "^5.4.5"
48
+ },
49
+ "dependencies": {
50
+ "@leanprover/infoview-api": "~0.4.0",
51
+ "@vscode/codicons": "^0.0.32",
52
+ "@vscode/webview-ui-toolkit": "^1.4.0",
53
+ "es-module-shims": "^1.7.3",
54
+ "marked": "^4.3.0",
55
+ "react-fast-compare": "^3.2.2",
56
+ "tachyons": "^4.12.0",
57
+ "vscode-languageserver-protocol": "^3.17.3"
58
+ }
59
+ }