Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Move awaitExtensionReadiness to top-level in EditorAppBaseConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Sep 29, 2023
1 parent 629f52a commit 8785370
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 46 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

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

18 changes: 9 additions & 9 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"version": "0.0.0",
"type": "module",
"dependencies": {
"@codingame/monaco-vscode-editor-service-override": "1.82.2",
"@codingame/monaco-vscode-javascript-default-extension": "1.82.2",
"@codingame/monaco-vscode-json-default-extension": "1.82.2",
"@codingame/monaco-vscode-keybindings-service-override": "1.82.2",
"@codingame/monaco-vscode-python-default-extension": "1.82.2",
"@codingame/monaco-vscode-textmate-service-override": "1.82.2",
"@codingame/monaco-vscode-theme-defaults-default-extension": "1.82.2",
"@codingame/monaco-vscode-theme-service-override": "1.82.2",
"@typefox/monaco-editor-react": "2.2.0-next.0",
"@codingame/monaco-vscode-editor-service-override": "~1.82.2",
"@codingame/monaco-vscode-javascript-default-extension": "~1.82.2",
"@codingame/monaco-vscode-json-default-extension": "~1.82.2",
"@codingame/monaco-vscode-keybindings-service-override": "~1.82.2",
"@codingame/monaco-vscode-python-default-extension": "~1.82.2",
"@codingame/monaco-vscode-textmate-service-override": "~1.82.2",
"@codingame/monaco-vscode-theme-defaults-default-extension": "~1.82.2",
"@codingame/monaco-vscode-theme-service-override": "~1.82.2",
"@typefox/monaco-editor-react": "2.2.0-next.1",
"http-server": "~14.1.1",
"langium": "~2.0.2",
"langium-statemachine-dsl": "~2.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/examples/src/langium/config/wrapperLangiumVscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import getEditorServiceOverride from '@codingame/monaco-vscode-editor-service-ov
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-override';
import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override';
import { whenReady } from '@codingame/monaco-vscode-theme-defaults-default-extension';
import { whenReady as whenReadyThemes } from '@codingame/monaco-vscode-theme-defaults-default-extension';
import { useOpenEditorStub } from 'monaco-languageclient';
import { UserConfig } from 'monaco-editor-wrapper';
import { getTextContent } from '../../common.js';
Expand Down Expand Up @@ -39,6 +39,8 @@ export const setupLangiumClientVscodeApi = async (): Promise<UserConfig> => {
languageId: 'langium',
code: code,
useDiffEditor: false,
// Ensure all required extensions are loaded before setting up the language extension
awaitExtensionReadiness: [whenReadyThemes],
extensions: [{
config: {
name: 'langium-example',
Expand Down Expand Up @@ -68,8 +70,7 @@ export const setupLangiumClientVscodeApi = async (): Promise<UserConfig> => {
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': true
}),
awaitReadiness: [whenReady]
})
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getEditorServiceOverride from '@codingame/monaco-vscode-editor-service-ov
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-override';
import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override';
import { whenReady } from '@codingame/monaco-vscode-theme-defaults-default-extension';
import { whenReady as whenReadyThemes } from '@codingame/monaco-vscode-theme-defaults-default-extension';
import { Uri } from 'vscode';
import { useOpenEditorStub } from 'monaco-languageclient';
import { UserConfig } from 'monaco-editor-wrapper';
Expand Down Expand Up @@ -39,6 +39,8 @@ export const createLangiumGlobalConfig = async (htmlElement: HTMLElement): Promi
languageId: 'statemachine',
code: code,
useDiffEditor: false,
// Ensure all required extensions are loaded before setting up the language extension
awaitExtensionReadiness: [whenReadyThemes],
extensions: [{
config: {
name: 'statemachine-example',
Expand Down Expand Up @@ -68,8 +70,7 @@ export const createLangiumGlobalConfig = async (htmlElement: HTMLElement): Promi
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': true
}),
awaitReadiness: [whenReady]
})
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions packages/examples/src/reactPython.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import getConfigurationServiceOverride from '@codingame/monaco-vscode-configurat
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-override';
import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override';
import { whenReady as whenReadyTheme } from '@codingame/monaco-vscode-theme-defaults-default-extension';
import { whenReady as whenReadyThemes } from '@codingame/monaco-vscode-theme-defaults-default-extension';
import { whenReady as whenReadyPython } from '@codingame/monaco-vscode-python-default-extension';
import React from 'react';
import ReactDOM from 'react-dom/client';
Expand Down Expand Up @@ -66,6 +66,9 @@ const userConfig: UserConfig = {
},
editorAppConfig: {
$type: 'vscodeApi',
languageId: 'python',
codeUri: '/workspace/python.py',
awaitExtensionReadiness: [whenReadyThemes, whenReadyPython],
extensions: [{
config: {
name: 'python-client',
Expand Down Expand Up @@ -99,11 +102,8 @@ const userConfig: UserConfig = {
}
}
}],
languageId: 'python',
codeUri: '/workspace/python.py',
userConfiguration: {
json: JSON.stringify({'workbench.colorTheme': 'Default Dark Modern'}),
awaitReadiness: [whenReadyTheme, whenReadyPython]
json: JSON.stringify({'workbench.colorTheme': 'Default Dark Modern'})
},
useDiffEditor: false,
code: code,
Expand Down
5 changes: 2 additions & 3 deletions packages/examples/src/wrapperWs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ const userConfig: UserConfig = {
editorOptions: monacoEditorConfig,
diffEditorOptions: monacoEditorConfig,
theme: 'vs-dark',
// Ensure all required extensions are loaded before setting up the language extension
awaitExtensionReadiness: [whenReadyTheme, whenReadyJson],
languageExtensionConfig: {
id: 'json',
extensions: ['.json', '.jsonc'],
aliases: ['JSON', 'json'],
mimetypes: ['application/json']
},
userConfiguration: {
awaitReadiness: [whenReadyTheme, whenReadyJson]
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/monaco-editor-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typefox/monaco-editor-react",
"version": "2.2.0-next.0",
"version": "2.2.0-next.1",
"license": "MIT",
"description": "React component for Monaco-Editor and Monaco Languageclient",
"keywords": [
Expand Down Expand Up @@ -50,7 +50,7 @@
"npm": "9.8.1"
},
"peerDependencies": {
"monaco-editor-wrapper": "3.2.0-next.0",
"monaco-editor-wrapper": "3.2.0-next.1",
"react": "~18.2.0",
"react-dom": "~18.2.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/monaco-editor-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monaco-editor-wrapper",
"version": "3.2.0-next.0",
"version": "3.2.0-next.1",
"license": "MIT",
"description": "Monaco-Editor and Monaco Languageclient Wrapper",
"keywords": [
Expand Down Expand Up @@ -58,7 +58,7 @@
"npm": "9.8.1"
},
"dependencies": {
"@codingame/monaco-vscode-configuration-service-override": "1.82.2",
"@codingame/monaco-vscode-configuration-service-override": "~1.82.2",
"monaco-languageclient": "6.5.0-next.2"
},
"peerDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/monaco-editor-wrapper/src/editorAppBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export type EditorAppBaseConfig = ModelUpdate & {
useDiffEditor: boolean;
domReadOnly?: boolean;
readOnly?: boolean;
awaitExtensionReadiness?: Array<() => Promise<void>>
userConfiguration?: UserConfiguration;
}

export type EditorAppType = 'vscodeApi' | 'classic';

export type UserConfiguration = {
json?: string;
awaitReadiness?: Array<() => Promise<void>>
}

/**
Expand Down Expand Up @@ -209,10 +209,10 @@ export abstract class EditorAppBase {
}
}

async awaitReadiness(config?: UserConfiguration) {
if (config?.awaitReadiness) {
async awaitReadiness(awaitExtensionReadiness?: Array<() => Promise<void>>) {
if (awaitExtensionReadiness) {
const allPromises: Array<Promise<void>> = [];
for (const awaitReadiness of config.awaitReadiness) {
for (const awaitReadiness of awaitExtensionReadiness) {
allPromises.push(awaitReadiness());
}
return Promise.all(allPromises);
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-editor-wrapper/src/editorAppClassic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class EditorAppClassic extends EditorAppBase {

async init() {
// await all extenson that should be ready beforehand
await this.awaitReadiness(this.config.userConfiguration);
await this.awaitReadiness(this.config.awaitExtensionReadiness);

// register own language first
const extLang = this.config.languageExtensionConfig;
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class EditorAppVscodeApi extends EditorAppBase {

async init() {
// await all extenson that should be ready beforehand
await this.awaitReadiness(this.config.userConfiguration);
await this.awaitReadiness(this.config.awaitExtensionReadiness);

if (this.config.extensions) {
const allPromises: Array<Promise<void>> = [];
Expand Down
2 changes: 2 additions & 0 deletions packages/monaco-editor-wrapper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from './editorAppClassic.js';

import type {
ExtensionConfig,
EditorAppConfigVscodeApi,
RegisterExtensionResult,
RegisterLocalProcessExtensionResult,
Expand Down Expand Up @@ -69,6 +70,7 @@ export type {
EditorAppBaseConfig,
EditorAppType,
EditorAppConfigClassic,
ExtensionConfig,
EditorAppConfigVscodeApi,
RegisterExtensionResult,
RegisterLocalProcessExtensionResult,
Expand Down

0 comments on commit 8785370

Please sign in to comment.