lean4monaco 1.1.10 → 1.1.13
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/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export * from './leanmonaco';
|
|
|
3
3
|
export { RpcSessionAtPos } from './vscode-lean4/vscode-lean4/src/infoview';
|
|
4
4
|
export { DocumentPosition } from './vscode-lean4/lean4-infoview/src/infoview/util';
|
|
5
5
|
export { LeanClient } from './vscode-lean4/vscode-lean4/src/leanclient';
|
|
6
|
+
export { WithRpcSessions } from './vscode-lean4/lean4-infoview/src/infoview/rpcSessions';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './editor';
|
|
2
2
|
export * from './leanmonaco';
|
|
3
|
+
// TODO: I think this should be present in the infoview-api and can be removed here
|
|
3
4
|
export { RpcSessionAtPos } from './vscode-lean4/vscode-lean4/src/infoview';
|
|
4
5
|
export { DocumentPosition } from './vscode-lean4/lean4-infoview/src/infoview/util';
|
|
5
6
|
export { LeanClient } from './vscode-lean4/vscode-lean4/src/leanclient';
|
|
7
|
+
export { WithRpcSessions } from './vscode-lean4/lean4-infoview/src/infoview/rpcSessions';
|
package/dist/leanmonaco.js
CHANGED
|
@@ -152,7 +152,7 @@ export class LeanMonaco {
|
|
|
152
152
|
"editor.fontFamily": "'Noto Color Emoji', 'JuliaMono'",
|
|
153
153
|
"editor.wordWrap": "on",
|
|
154
154
|
"editor.wrappingStrategy": "advanced",
|
|
155
|
-
"workbench.colorTheme": "Visual Studio Light",
|
|
155
|
+
"workbench.colorTheme": isBrowserDefaultDark() ? "Visual Studio Dark" : "Visual Studio Light",
|
|
156
156
|
...options.vscode
|
|
157
157
|
});
|
|
158
158
|
if (this.disposed) {
|
|
@@ -253,3 +253,7 @@ export class LeanMonaco {
|
|
|
253
253
|
this.abbreviationFeature = undefined;
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
+
/** Returns true if the browser wants dark mode */
|
|
257
|
+
function isBrowserDefaultDark() {
|
|
258
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
259
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RpcSessionAtPos } from '@leanprover/infoview-api';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import type { TextDocumentPositionParams } from 'vscode-languageserver-protocol';
|
|
4
|
+
import { DocumentPosition } from './util';
|
|
5
|
+
/**
|
|
6
|
+
* Provides a {@link RpcSessionsContext} to the children.
|
|
7
|
+
* The {@link RpcSessions} object stored there manages RPC sessions in the Lean server.
|
|
8
|
+
*/
|
|
9
|
+
export declare function WithRpcSessions({ children }: {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare function useRpcSessionAtTdpp(pos: TextDocumentPositionParams): RpcSessionAtPos;
|
|
13
|
+
export declare function useRpcSessionAtPos(pos: DocumentPosition): RpcSessionAtPos;
|
|
14
|
+
/** @deprecated use {@link useRpcSession} instead */
|
|
15
|
+
export declare const RpcContext: React.Context<RpcSessionAtPos>;
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve an RPC session at {@link EnvPosContext},
|
|
18
|
+
* if the context is set.
|
|
19
|
+
* Otherwise return a dummy session that throws on any RPC call.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useRpcSession(): RpcSessionAtPos;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RpcSessions } from '@leanprover/infoview-api';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { EditorContext, EnvPosContext } from './contexts';
|
|
5
|
+
import { DocumentPosition, useClientNotificationEffect, useEvent } from './util';
|
|
6
|
+
const RpcSessionsContext = React.createContext(undefined);
|
|
7
|
+
/**
|
|
8
|
+
* Provides a {@link RpcSessionsContext} to the children.
|
|
9
|
+
* The {@link RpcSessions} object stored there manages RPC sessions in the Lean server.
|
|
10
|
+
*/
|
|
11
|
+
export function WithRpcSessions({ children }) {
|
|
12
|
+
const ec = React.useContext(EditorContext);
|
|
13
|
+
const [sessions] = React.useState(() => new RpcSessions({
|
|
14
|
+
createRpcSession: (uri) => ec.api.createRpcSession(uri),
|
|
15
|
+
closeRpcSession: (uri) => ec.api.closeRpcSession(uri),
|
|
16
|
+
call: (params) => ec.api.sendClientRequest(params.textDocument.uri, '$/lean/rpc/call', params),
|
|
17
|
+
release: (params) => void ec.api.sendClientNotification(params.uri, '$/lean/rpc/release', params),
|
|
18
|
+
}));
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
// Clean up the sessions on unmount
|
|
21
|
+
return () => sessions.dispose();
|
|
22
|
+
}, [sessions]);
|
|
23
|
+
useClientNotificationEffect('textDocument/didClose', (params) => {
|
|
24
|
+
sessions.closeSessionForFile(params.textDocument.uri);
|
|
25
|
+
}, [sessions]);
|
|
26
|
+
// TODO: only restart files for the server that stopped
|
|
27
|
+
useEvent(ec.events.serverRestarted, () => sessions.closeAllSessions());
|
|
28
|
+
return _jsx(RpcSessionsContext.Provider, { value: sessions, children: children });
|
|
29
|
+
}
|
|
30
|
+
const noCtxRpcSession = {
|
|
31
|
+
call: async () => {
|
|
32
|
+
throw new Error('no RPC context set');
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const noPosRpcSession = {
|
|
36
|
+
call: async () => {
|
|
37
|
+
throw new Error('no position context set');
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export function useRpcSessionAtTdpp(pos) {
|
|
41
|
+
return React.useContext(RpcSessionsContext)?.connect(pos) || noCtxRpcSession;
|
|
42
|
+
}
|
|
43
|
+
export function useRpcSessionAtPos(pos) {
|
|
44
|
+
return useRpcSessionAtTdpp(DocumentPosition.toTdpp(pos));
|
|
45
|
+
}
|
|
46
|
+
/** @deprecated use {@link useRpcSession} instead */
|
|
47
|
+
/*
|
|
48
|
+
* NOTE(WN): This context cannot be removed as of 2024-05-27 since existing widgets use it.
|
|
49
|
+
* For backwards compatibility, it must be set to the correct value by infoview code.
|
|
50
|
+
* A future major release of @leanprover/infoview could remove this context
|
|
51
|
+
* after it has been deprecated for a sufficiently long time.
|
|
52
|
+
*/
|
|
53
|
+
export const RpcContext = React.createContext(noCtxRpcSession);
|
|
54
|
+
/**
|
|
55
|
+
* Retrieve an RPC session at {@link EnvPosContext},
|
|
56
|
+
* if the context is set.
|
|
57
|
+
* Otherwise return a dummy session that throws on any RPC call.
|
|
58
|
+
*/
|
|
59
|
+
export function useRpcSession() {
|
|
60
|
+
const pos = React.useContext(EnvPosContext);
|
|
61
|
+
const rsc = React.useContext(RpcSessionsContext);
|
|
62
|
+
if (!pos)
|
|
63
|
+
return noPosRpcSession;
|
|
64
|
+
if (!rsc)
|
|
65
|
+
return noCtxRpcSession;
|
|
66
|
+
return rsc.connect(DocumentPosition.toTdpp(pos));
|
|
67
|
+
}
|