Skip to content

Commit d09b448

Browse files
committed
style
1 parent 0cb4edc commit d09b448

17 files changed

+277
-256
lines changed

Diff for: cypress/e2e/spec.cy.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ describe('Editor Test', () => {
22
it('displays the editor', () => {
33
cy.visit('http://localhost:5173/')
44
cy.contains('#check 0')
5-
.should(($p) => {
5+
.should(($p: any) => {
66
// ...
77
expect(getComputedStyle($p.get(0)).fontFamily).to.match(/^JuliaMono/)
88
})
@@ -18,12 +18,12 @@ describe('Editor Test', () => {
1818
cy.visit('http://localhost:5173/')
1919
cy.get('[data-cy="theme-light"]').click()
2020
cy.contains('#check 0')
21-
.should(($p) => {
21+
.should(($p: any) => {
2222
expect(getComputedStyle($p.get(0)).getPropertyValue('--vscode-editor-background')).to.equal("#ffffff")
2323
})
2424
cy.get('[data-cy="theme-dark"]').click()
2525
cy.contains('#check 0')
26-
.should(($p) => {
26+
.should(($p: any) => {
2727
expect(getComputedStyle($p.get(0)).getPropertyValue('--vscode-editor-background')).to.equal("#1e1e1e")
2828
})
2929

Diff for: demo/src/App.css

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
height: 300px;
44
}
55

6-
76
.controls {
87
flex: 0 0 100%;
98
}
10-

Diff for: demo/src/App.tsx

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import { useState } from 'react'
2-
import './App.css'
32
import LeanMonacoComponent from './LeanMonaco'
43
import { LeanMonacoOptions } from 'lean4monaco'
4+
import './App.css'
55

66
function App() {
7-
const [options, setOptions] = useState<LeanMonacoOptions>({websocket: {url: 'ws://localhost:8080/'}, vscode: {
8-
"workbench.colorTheme": "Visual Studio Light",
9-
/* To add settings here, you can open your settings in VSCode (Ctrl+,), search
10-
* for the desired setting, select "Copy Setting as JSON" from the "More Actions"
11-
* menu next to the selected setting, and paste the copied string here.
12-
*/
13-
}})
7+
8+
/* lean-Monaco options. The websocket URL is where the server should listen.
9+
* To add settings in `vscode` (i.e. for the editor),
10+
* you can open your settings in VSCode (Ctrl+,), search
11+
* for the desired setting, select "Copy Setting as JSON" from the "More Actions"
12+
* menu next to the selected setting, and paste the copied string here.
13+
*/
14+
const [options, setOptions] = useState<LeanMonacoOptions>({
15+
websocket: {
16+
url: 'ws://localhost:8080/'
17+
},
18+
vscode: {
19+
"workbench.colorTheme": "Visual Studio Light",
20+
}
21+
})
22+
23+
// state to keep track of the number of open editors
1424
const [numberEditors, setNumberEditors] = useState(1)
1525

1626
return (

Diff for: demo/src/LeanMonaco.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import { useEffect, useRef, createContext, useState } from 'react'
22
import { LeanMonaco, LeanMonacoOptions } from 'lean4monaco'
3-
import LeanMonacoEditorComponent from './LeanMonacoEditor';
3+
import LeanMonacoEditorComponent from './LeanMonacoEditor'
44

55
export const LeanMonacoContext = createContext<LeanMonaco|null>(null);
66

77
function LeanMonacoComponent({options, numberEditors} : {options: LeanMonacoOptions, numberEditors: number}) {
88
const [leanMonaco, setLeanMonaco] = useState<LeanMonaco|null>(null)
99
const infoviewRef = useRef<HTMLDivElement>(null)
1010

11+
// You need to start one `LeanMonaco` instance once in your application using a `useEffect`
1112
useEffect(() => {
1213
const leanMonaco = new LeanMonaco()
1314
setLeanMonaco(leanMonaco)
1415
leanMonaco.setInfoviewElement(infoviewRef.current!)
15-
16+
1617
;(async () => {
17-
await leanMonaco.start(options)
18+
await leanMonaco.start(options)
1819
})()
19-
20+
2021
return () => {
21-
leanMonaco.dispose()
22+
leanMonaco.dispose()
2223
}
2324
}, [options])
2425

2526
return (
2627
<>
2728
<LeanMonacoContext.Provider value={leanMonaco}>
28-
{[...Array(numberEditors)].map((x, i) =>
29+
{[...Array(numberEditors)].map((_x, i) =>
2930
<LeanMonacoEditorComponent key={i} fileName={`/project/test${i}.lean`} value={`#check ${i}`}/>
3031
)}
3132
<div className='infoview' ref={infoviewRef}></div>

Diff for: demo/src/LeanMonacoEditor.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ function LeanMonacoEditorComponent({fileName, value}: {fileName: string, value:
66
const codeviewRef = useRef<HTMLDivElement>(null)
77
const leanMonaco = useContext(LeanMonacoContext)
88

9+
// You can start multiple `LeanMonacoEditor` instances
910
useEffect(() => {
1011
if (leanMonaco) {
1112
const leanMonacoEditor = new LeanMonacoEditor()
12-
13+
1314
;(async () => {
14-
await leanMonaco!.whenReady
15-
await leanMonacoEditor.start(codeviewRef.current!, fileName, value)
15+
await leanMonaco!.whenReady
16+
await leanMonacoEditor.start(codeviewRef.current!, fileName, value)
1617
})()
17-
18+
1819
return () => {
19-
leanMonacoEditor.dispose()
20+
leanMonacoEditor.dispose()
2021
}
2122
}
2223
}, [leanMonaco])
2324

2425
return (
25-
<div className='codeview' ref={codeviewRef}></div>
26+
<div className='codeview' ref={codeviewRef}></div>
2627
)
2728
}
2829

Diff for: demo/src/index.css

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ a {
2525
color: #646cff;
2626
text-decoration: inherit;
2727
}
28+
2829
a:hover {
2930
color: #535bf2;
3031
}
@@ -52,11 +53,12 @@ button {
5253
cursor: pointer;
5354
transition: border-color 0.25s;
5455
}
56+
5557
button:hover {
5658
border-color: #646cff;
5759
}
58-
button:focus,
59-
button:focus-visible {
60+
61+
button:focus, button:focus-visible {
6062
outline: 4px auto -webkit-focus-ring-color;
6163
}
6264

@@ -65,9 +67,11 @@ button:focus-visible {
6567
color: #213547;
6668
background-color: #ffffff;
6769
}
70+
6871
a:hover {
6972
color: #747bff;
7073
}
74+
7175
button {
7276
background-color: #f9f9f9;
7377
}

Diff for: demo/src/main.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import './index.css'
66
ReactDOM.createRoot(document.getElementById('root')!).render(
77
<React.StrictMode>
88
<App />
9-
</React.StrictMode>,
9+
</React.StrictMode>
1010
)

Diff for: demo/src/vite-env.d.ts

-1
This file was deleted.

Diff for: demo/vite.config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ export default defineConfig({
2525
{
2626
src: [
2727
normalizePath(path.resolve(__dirname, '../node_modules/@leanprover/infoview/dist/*')),
28+
// note: if you install `lean4monaco` via npm, this line need to change, see README.
2829
normalizePath(path.resolve(__dirname, '../dist/webview/webview.js')),
2930
],
3031
dest: 'infoview'
3132
}
3233
]
33-
}) as PluginOption
34+
})
3435
],
3536
server: {
3637
fs: {
38+
// only needed because `demo` lies inside the `lean4monaco` folder
3739
allow: [".."]
3840
}
3941
},

Diff for: src/editor.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Uri } from 'vscode';
2-
import { fs } from 'memfs';
3-
import { ITextFileEditorModel, createModelReference } from 'vscode/monaco';
4-
import * as monaco from 'monaco-editor';
5-
import { IReference } from '@codingame/monaco-vscode-editor-service-override';
1+
import { Uri } from 'vscode'
2+
import { fs } from 'memfs'
3+
import { ITextFileEditorModel, createModelReference } from 'vscode/monaco'
4+
import * as monaco from 'monaco-editor'
5+
import { IReference } from '@codingame/monaco-vscode-editor-service-override'
66
import path from 'path'
77

88
export class LeanMonacoEditor {
@@ -15,12 +15,12 @@ export class LeanMonacoEditor {
1515
if (this.disposed) return
1616

1717
// Create file for clientProvider to find
18-
fs.mkdirSync(path.dirname(fileName), {recursive: true});
19-
fs.writeFileSync(fileName, '');
20-
18+
fs.mkdirSync(path.dirname(fileName), {recursive: true})
19+
fs.writeFileSync(fileName, '')
20+
2121
// Create editor and model
22-
this.modelRef = await createModelReference(Uri.parse(fileName), code);
23-
this.editor = monaco.editor.create(editorEl, { automaticLayout: true });
22+
this.modelRef = await createModelReference(Uri.parse(fileName), code)
23+
this.editor = monaco.editor.create(editorEl, { automaticLayout: true })
2424
this.editor.setModel(this.modelRef.object.textEditorModel)
2525

2626
// Set focus on editor to trigger infoview to open

0 commit comments

Comments
 (0)