Skip to content

Commit

Permalink
fixes for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Aug 23, 2024
1 parent 426f382 commit aff9a94
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 100 deletions.
2 changes: 1 addition & 1 deletion demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions demo/src/LeanMonaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ function LeanMonacoComponent({options, numberEditors} : {options: LeanMonacoOpti

// You need to start one `LeanMonaco` instance once in your application using a `useEffect`
useEffect(() => {
const leanMonaco = new LeanMonaco()
setLeanMonaco(leanMonaco)
leanMonaco.setInfoviewElement(infoviewRef.current!)
var _leanMonaco = new LeanMonaco()
setLeanMonaco(_leanMonaco)
_leanMonaco.setInfoviewElement(infoviewRef.current!)


;(async () => {
await leanMonaco.start(options)
await _leanMonaco.start(options)
console.debug('[demo]: leanMonaco started')
})()

return () => {
leanMonaco.dispose()
_leanMonaco.dispose()
}
}, [options])

Expand All @@ -34,7 +36,7 @@ function LeanMonacoComponent({options, numberEditors} : {options: LeanMonacoOpti

<div>
<button onClick={(ev)=> {
console.log('restarting Lean')
console.log('[LeanMonaco] restarting Lean')
leanMonaco?.clientProvider?.getClients().map(client => {client.restart()})
}}>Restart Lean</button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions demo/src/LeanMonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function LeanMonacoEditorComponent({fileName, value}: {fileName: string, value:

;(async () => {
await leanMonaco!.whenReady
console.debug('[demo]: starting editor')
await leanMonacoEditor.start(codeviewRef.current!, fileName, value)
console.debug('[demo]: editor started')
})()

return () => {
Expand Down
139 changes: 59 additions & 80 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 31 additions & 11 deletions src/leanmonaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,27 @@ export type LeanMonacoOptions = {
console.debug('[LeanMonaco]: starting')

if (LeanMonaco.activeInstance == this) {
console.warn('A LeanMonaco instance cannot be started twice.')
console.warn('[LeanMonaco]: A LeanMonaco instance cannot be started twice.')
return
}
if (LeanMonaco.activeInstance) {
console.warn('There can only be one active LeanMonaco instance at a time. Disposing previous instance.')
console.warn('[LeanMonaco]: There can only be one active LeanMonaco instance at a time. Disposing previous instance.')
LeanMonaco.activeInstance?.dispose()
}
LeanMonaco.activeInstance = this

if (! window.MonacoEnvironment) {
console.debug('[LeanMonaco]: setting monaco environment')
type WorkerLoader = () => Worker
const workerLoaders: Partial<Record<string, WorkerLoader>> = {
editorWorkerService: () => new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url), { type: 'module' }),
textMateWorker: () => new Worker(new URL('@codingame/monaco-vscode-textmate-service-override/worker', import.meta.url), { type: 'module' }),
editorWorkerService: () => new Worker(
new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url),
{ type: 'module' }
),
textMateWorker: () => new Worker(
new URL('@codingame/monaco-vscode-textmate-service-override/worker', import.meta.url),
{ type: 'module' }
),
}
window.MonacoEnvironment = {
getWorker: function (moduleId, label) {
Expand All @@ -102,19 +109,22 @@ export type LeanMonacoOptions = {
workspaceProvider: {
trusted: true,
workspace: {
workspaceUri: Uri.file('/workspace.code-workspace')
workspaceUri: Uri.file('/workspace.code-workspace')
},
async open() {
return false
return false
}
}
}
)

console.debug('[LeanMonaco]: done initializing')
}
await (await import('@codingame/monaco-vscode-theme-defaults-default-extension')).whenReady

if (this.disposed) return
if (this.disposed) {
console.debug('[LeanMonaco]: is disposed (A)')
return
}

this.extensionRegisterResult = registerExtension(this.getExtensionManifest(), ExtensionHostKind.LocalProcess)

Expand All @@ -125,12 +135,18 @@ export type LeanMonacoOptions = {

await this.extensionRegisterResult.whenReady()

if (this.disposed) return
if (this.disposed) {
console.debug('[LeanMonaco]: is disposed (B)')
return
}

const themeService = await getService(IThemeService)
const configurationService = await getService(IConfigurationService)

if (this.disposed) return
if (this.disposed) {
console.debug('[LeanMonaco]: is disposed (C)')
return
}

this.updateVSCodeOptions(options.vscode ?? {})

Expand Down Expand Up @@ -206,8 +222,12 @@ export type LeanMonacoOptions = {
...options.vscode
})

if (this.disposed) return
if (this.disposed) {
console.debug('[LeanMonaco]: is disposed (D)')
return
}

console.info('[LeanMonaco]: is ready!')
this.ready()
}

Expand Down
2 changes: 1 addition & 1 deletion src/vscode-lean4
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2021", "ES2021.String", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down

0 comments on commit aff9a94

Please sign in to comment.