From a4d67dbe4954ae66dd195265fab17ad0aa658eb7 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Thu, 14 Nov 2024 22:56:28 +0100 Subject: [PATCH] Support language client usage independent of wrapper and allow to configure and init vscode api independently --- package-lock.json | 1 + packages/client/package.json | 1 + packages/client/src/commonTypes.ts | 2 +- packages/client/src/vscode/services.ts | 57 +++++---- packages/examples/src/appPlayground/main.ts | 7 +- packages/examples/src/bare/client.ts | 12 +- packages/examples/src/browser/main.ts | 7 +- packages/examples/src/clangd/client/config.ts | 7 +- .../src/eclipse.jdt.ls/client/main.ts | 7 +- packages/examples/src/groovy/client/main.ts | 7 +- .../examples/src/json/client/wrapperWs.ts | 7 +- .../langium-dsl/config/classicConfig.ts | 7 +- .../langium-dsl/config/extendedConfig.ts | 7 +- .../config/wrapperStatemachineConfig.ts | 7 +- .../src/langium/statemachine/main-react.tsx | 2 +- packages/examples/src/multi/config.ts | 63 ++++++++++ .../examples/src/multi/twoLanguageClients.ts | 106 +++++++--------- packages/examples/src/python/client/config.ts | 7 +- .../src/python/client/reactPython.tsx | 2 +- packages/examples/src/ts/wrapperTs.ts | 9 +- packages/examples/two_langauge_clients.html | 1 + packages/wrapper-react/src/index.tsx | 4 +- packages/wrapper-react/test/helper.ts | 12 -- packages/wrapper-react/test/index.test.tsx | 20 +-- packages/wrapper/src/editorAppBase.ts | 10 +- packages/wrapper/src/editorAppClassic.ts | 11 -- packages/wrapper/src/editorAppExtended.ts | 13 -- packages/wrapper/src/languageClientWrapper.ts | 4 +- packages/wrapper/src/vscode/services.ts | 116 +++++++++++------- packages/wrapper/src/wrapper.ts | 74 +++++------ packages/wrapper/test/helper.ts | 12 +- packages/wrapper/test/vscode/services.test.ts | 20 +-- packages/wrapper/test/wrapper.test.ts | 4 +- 33 files changed, 352 insertions(+), 274 deletions(-) create mode 100644 packages/examples/src/multi/config.ts diff --git a/package-lock.json b/package-lock.json index 030c05e56..5d49e90d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12012,6 +12012,7 @@ "version": "9.0.0-next.7", "license": "MIT", "dependencies": { + "@codingame/monaco-vscode-configuration-service-override": "~11.0.1", "@codingame/monaco-vscode-extensions-service-override": "~11.0.1", "@codingame/monaco-vscode-languages-service-override": "~11.0.1", "@codingame/monaco-vscode-localization-service-override": "~11.0.1", diff --git a/packages/client/package.json b/packages/client/package.json index a21490e26..19ddff001 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -69,6 +69,7 @@ "LICENSE" ], "dependencies": { + "@codingame/monaco-vscode-configuration-service-override": "~11.0.1", "@codingame/monaco-vscode-extensions-service-override": "~11.0.1", "@codingame/monaco-vscode-languages-service-override": "~11.0.1", "@codingame/monaco-vscode-localization-service-override": "~11.0.1", diff --git a/packages/client/src/commonTypes.ts b/packages/client/src/commonTypes.ts index bdc31dbad..ef592f10b 100644 --- a/packages/client/src/commonTypes.ts +++ b/packages/client/src/commonTypes.ts @@ -5,7 +5,7 @@ import { MonacoLanguageClient } from './client.js'; -export type ConnetionConfigOptions = WebSocketConfigOptionsDirect | WebSocketConfigOptionsParams | WebSocketConfigOptionsUrl | WorkerConfigOptionsParams | WorkerConfigOptionsDirect; +export type ConnectionConfigOptions = WebSocketConfigOptionsDirect | WebSocketConfigOptionsParams | WebSocketConfigOptionsUrl | WorkerConfigOptionsParams | WorkerConfigOptionsDirect; export interface WebSocketCallOptions { /** Adds handle on languageClient */ diff --git a/packages/client/src/vscode/services.ts b/packages/client/src/vscode/services.ts index 4b932f654..c433c690e 100644 --- a/packages/client/src/vscode/services.ts +++ b/packages/client/src/vscode/services.ts @@ -17,6 +17,7 @@ import { EnvironmentOverride } from 'vscode/workbench'; import { Logger } from 'monaco-languageclient/tools'; import { FakeWorker as Worker } from './fakeWorker.js'; import { setUnexpectedErrorHandler } from 'vscode/monaco'; +import { updateUserConfiguration } from '@codingame/monaco-vscode-configuration-service-override'; export interface MonacoEnvironmentEnhanced extends monaco.Environment { vscodeInitialising?: boolean; @@ -26,21 +27,24 @@ export interface MonacoEnvironmentEnhanced extends monaco.Environment { export interface UserConfiguration { json?: string; } +export interface ViewsConfig { + viewServiceType: 'EditorService' | 'ViewsService' | 'WorkspaceService'; + openEditorFunc?: OpenEditor; + viewsInitFunc?: () => void; +} export interface VscodeApiConfig { - userServices?: monaco.editor.IEditorOverrideServices; + enableTextmate: boolean; + vscodeApiInitPerformExternally?: boolean; + serviceOverrides?: monaco.editor.IEditorOverrideServices; enableExtHostWorker?: boolean; workspaceConfig?: IWorkbenchConstructionOptions; userConfiguration?: UserConfiguration; - viewsConfig?: { - viewServiceType: 'EditorService' | 'ViewsService' | 'WorkspaceService'; - openEditorFunc?: OpenEditor; - viewsInitFunc?: () => void; - }, + viewsConfig?: ViewsConfig, envOptions?: EnvironmentOverride; } -export interface InitVscodeApiInstructions extends VscodeApiConfig { +export interface InitServicesInstructions { htmlContainer: HTMLElement; caller?: string; performServiceConsistencyChecks?: () => boolean; @@ -82,13 +86,15 @@ export const reportServiceLoading = (services: monaco.editor.IEditorOverrideServ } }; -export const mergeServices = (services: monaco.editor.IEditorOverrideServices, overrideServices: monaco.editor.IEditorOverrideServices) => { - for (const [name, service] of Object.entries(services)) { - overrideServices[name] = service; +export const mergeServices = (overrideServices: monaco.editor.IEditorOverrideServices, services?: monaco.editor.IEditorOverrideServices) => { + if (services !== undefined) { + for (const [name, service] of Object.entries(services)) { + overrideServices[name] = service; + } } }; -export const initServices = async (instructions: InitVscodeApiInstructions) => { +export const initServices = async (vscodeApiConfig: VscodeApiConfig, instructions: InitServicesInstructions) => { const envEnhanced = initEnhancedMonacoEnvironment(); if (!(envEnhanced.vscodeInitialising ?? false)) { @@ -98,12 +104,14 @@ export const initServices = async (instructions: InitVscodeApiInstructions) => { envEnhanced.vscodeInitialising = true; instructions.logger?.debug(`Initializing vscode services. Caller: ${instructions.caller ?? 'unknown'}`); - await importAllServices(instructions); - instructions.viewsConfig?.viewsInitFunc?.(); + await importAllServices(vscodeApiConfig, instructions); + vscodeApiConfig.viewsConfig?.viewsInitFunc?.(); instructions.logger?.debug('Initialization of vscode services completed successfully.'); envEnhanced.vscodeApiInitialised = true; } + + await updateUserConfiguration(vscodeApiConfig.userConfiguration?.json ?? JSON.stringify({})); } }; @@ -118,22 +126,20 @@ export const initServices = async (instructions: InitVscodeApiInstructions) => { * - languages * - model */ -export const importAllServices = async (instructions: InitVscodeApiInstructions) => { - const userServices: monaco.editor.IEditorOverrideServices = instructions.userServices ?? {}; +export const importAllServices = async (vscodeApiConfig: VscodeApiConfig, instructions: InitServicesInstructions) => { + const services = await supplyRequiredServices(); - const lcRequiredServices = await supplyRequiredServices(); + mergeServices(services, vscodeApiConfig.serviceOverrides); + await configureExtHostWorker(vscodeApiConfig.enableExtHostWorker === true, services); - mergeServices(lcRequiredServices, userServices); - await configureExtHostWorker(instructions.enableExtHostWorker === true, userServices); - - reportServiceLoading(userServices, instructions.logger); + reportServiceLoading(services, instructions.logger); if (instructions.performServiceConsistencyChecks === undefined || (typeof instructions.performServiceConsistencyChecks === 'function' && instructions.performServiceConsistencyChecks())) { - if (instructions.viewsConfig?.viewServiceType === 'ViewsService' || instructions.viewsConfig?.viewServiceType === 'WorkspaceService') { - await initialize(userServices, instructions.htmlContainer, instructions.workspaceConfig, instructions.envOptions); + if (vscodeApiConfig.viewsConfig?.viewServiceType === 'ViewsService' || vscodeApiConfig.viewsConfig?.viewServiceType === 'WorkspaceService') { + await initialize(services, instructions.htmlContainer, vscodeApiConfig.workspaceConfig, vscodeApiConfig.envOptions); } else { - await initialize(userServices, undefined, instructions.workspaceConfig, instructions.envOptions); + await initialize(services, undefined, vscodeApiConfig.workspaceConfig, vscodeApiConfig.envOptions); } } @@ -153,10 +159,9 @@ export const configureExtHostWorker = async (enableExtHostWorker: boolean, userS options: fakeWorker.options }; - const extHostServices = { + mergeServices(userServices, { ...getExtensionServiceOverride(workerConfig), - }; - mergeServices(extHostServices, userServices); + }); } }; diff --git a/packages/examples/src/appPlayground/main.ts b/packages/examples/src/appPlayground/main.ts index 7deb1a73c..dc77b422c 100644 --- a/packages/examples/src/appPlayground/main.ts +++ b/packages/examples/src/appPlayground/main.ts @@ -38,8 +38,10 @@ export const runApplicationPlayground = async () => { const wrapperConfig: WrapperConfig = { id: 'AAP', logLevel: LogLevel.Debug, + htmlContainer: document.body, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getConfigurationServiceOverride(), ...getKeybindingsServiceOverride(), ...getLifecycleServiceOverride(), @@ -106,8 +108,7 @@ export const runApplicationPlayground = async () => { } } }], - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: document.body + monacoWorkerFactory: configureMonacoWorkers } }; diff --git a/packages/examples/src/bare/client.ts b/packages/examples/src/bare/client.ts index 14b02f00f..228da933d 100644 --- a/packages/examples/src/bare/client.ts +++ b/packages/examples/src/bare/client.ts @@ -8,8 +8,6 @@ import { initServices } from 'monaco-languageclient/vscode/services'; import { LogLevel } from 'vscode/services'; // monaco-editor does not supply json highlighting with the json worker, // that's why we use the textmate extension from VSCode -import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-override'; -import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override'; import getConfigurationServiceOverride from '@codingame/monaco-vscode-configuration-service-override'; import '@codingame/monaco-vscode-theme-defaults-default-extension'; import '@codingame/monaco-vscode-json-default-extension'; @@ -24,11 +22,11 @@ export const runClient = async () => { const logger = new ConsoleLogger(LogLevel.Debug); const htmlContainer = document.getElementById('monaco-editor-root')!; await initServices({ - userServices: { - ...getConfigurationServiceOverride(), - ...getThemeServiceOverride(), - ...getTextmateServiceOverride(), - }, + enableTextmate: true, + serviceOverrides: { + ...getConfigurationServiceOverride() + } + }, { htmlContainer, logger }); diff --git a/packages/examples/src/browser/main.ts b/packages/examples/src/browser/main.ts index 66235f365..93f114030 100644 --- a/packages/examples/src/browser/main.ts +++ b/packages/examples/src/browser/main.ts @@ -30,8 +30,10 @@ export const runBrowserEditor = async () => { const wrapper = new MonacoEditorLanguageClientWrapper(); const jsonClientUserConfig: WrapperConfig = { logLevel: LogLevel.Debug, + htmlContainer, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride(), }, userConfiguration: { @@ -52,8 +54,7 @@ export const runBrowserEditor = async () => { } }, useDiffEditor: false, - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer + monacoWorkerFactory: configureMonacoWorkers } }; await wrapper.init(jsonClientUserConfig); diff --git a/packages/examples/src/clangd/client/config.ts b/packages/examples/src/clangd/client/config.ts index 5249b4e00..f7a631471 100644 --- a/packages/examples/src/clangd/client/config.ts +++ b/packages/examples/src/clangd/client/config.ts @@ -29,6 +29,7 @@ export const createWrapperConfig = async (config: { }): Promise => { return { logLevel: LogLevel.Debug, + htmlContainer: config.htmlContainer, languageClientConfigs: { LANGUAGE_ID: { name: 'Clangd WASM Language Server', @@ -55,7 +56,8 @@ export const createWrapperConfig = async (config: { } }, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getConfigurationServiceOverride(), ...getKeybindingsServiceOverride(), ...getLifecycleServiceOverride(), @@ -119,8 +121,7 @@ export const createWrapperConfig = async (config: { } } }], - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: config.htmlContainer + monacoWorkerFactory: configureMonacoWorkers } }; }; diff --git a/packages/examples/src/eclipse.jdt.ls/client/main.ts b/packages/examples/src/eclipse.jdt.ls/client/main.ts index 6ea4a11ee..2969f5f67 100644 --- a/packages/examples/src/eclipse.jdt.ls/client/main.ts +++ b/packages/examples/src/eclipse.jdt.ls/client/main.ts @@ -22,8 +22,10 @@ export const runEclipseJdtLsClient = () => { const userConfig: WrapperConfig = { logLevel: LogLevel.Debug, + htmlContainer: document.getElementById('monaco-editor-root')!, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride(), }, userConfiguration: { @@ -44,8 +46,7 @@ export const runEclipseJdtLsClient = () => { } }, useDiffEditor: false, - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: document.getElementById('monaco-editor-root')! + monacoWorkerFactory: configureMonacoWorkers }, languageClientConfigs: { java: { diff --git a/packages/examples/src/groovy/client/main.ts b/packages/examples/src/groovy/client/main.ts index 67e5370c8..51d034c4c 100644 --- a/packages/examples/src/groovy/client/main.ts +++ b/packages/examples/src/groovy/client/main.ts @@ -18,8 +18,10 @@ File file = new File("E:/Example.txt"); const userConfig: WrapperConfig = { logLevel: LogLevel.Debug, + htmlContainer: document.getElementById('monaco-editor-root')!, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride(), }, userConfiguration: { @@ -40,8 +42,7 @@ const userConfig: WrapperConfig = { } }, useDiffEditor: false, - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: document.getElementById('monaco-editor-root')! + monacoWorkerFactory: configureMonacoWorkers }, languageClientConfigs: { groovy: { diff --git a/packages/examples/src/json/client/wrapperWs.ts b/packages/examples/src/json/client/wrapperWs.ts index d57bdaf11..6943a8af4 100644 --- a/packages/examples/src/json/client/wrapperWs.ts +++ b/packages/examples/src/json/client/wrapperWs.ts @@ -20,8 +20,10 @@ export const buildJsonClientUserConfig = (params: { }): WrapperConfig => { return { logLevel: LogLevel.Debug, + htmlContainer: params.htmlContainer, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride(), }, userConfiguration: { @@ -43,8 +45,7 @@ export const buildJsonClientUserConfig = (params: { } }, useDiffEditor: false, - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: params.htmlContainer + monacoWorkerFactory: configureMonacoWorkers }, languageClientConfigs: { json: { diff --git a/packages/examples/src/langium/langium-dsl/config/classicConfig.ts b/packages/examples/src/langium/langium-dsl/config/classicConfig.ts index e7927fac2..0581b3671 100644 --- a/packages/examples/src/langium/langium-dsl/config/classicConfig.ts +++ b/packages/examples/src/langium/langium-dsl/config/classicConfig.ts @@ -17,8 +17,10 @@ export const setupLangiumClientClassic = async (): Promise => { const langiumWorker = loadLangiumWorker(); return { logLevel: LogLevel.Debug, + htmlContainer: document.getElementById('monaco-editor-root')!, vscodeApiConfig: { - userServices: { + enableTextmate: false, + serviceOverrides: { ...getConfigurationServiceOverride(), ...getKeybindingsServiceOverride() } @@ -46,8 +48,7 @@ export const setupLangiumClientClassic = async (): Promise => { useWorkerFactory({ logger }); - }, - htmlContainer: document.getElementById('monaco-editor-root')! + } }, languageClientConfigs: { langium: { diff --git a/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts b/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts index b3c5335ef..5ae02da14 100644 --- a/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts +++ b/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts @@ -28,8 +28,10 @@ export const setupLangiumClientExtended = async (): Promise => { return { logLevel: LogLevel.Debug, + htmlContainer: document.getElementById('monaco-editor-root')!, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride() }, userConfiguration: { @@ -74,8 +76,7 @@ export const setupLangiumClientExtended = async (): Promise => { }, filesOrContents: extensionFilesOrContents }], - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: document.getElementById('monaco-editor-root')! + monacoWorkerFactory: configureMonacoWorkers }, languageClientConfigs: { langium: { diff --git a/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts b/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts index 974080684..ec3a1d421 100644 --- a/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts +++ b/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts @@ -54,8 +54,10 @@ export const createLangiumGlobalConfig = async (params: { return { logLevel: LogLevel.Debug, + htmlContainer: params.htmlContainer, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride(), ...getLifecycleServiceOverride(), ...getLocalizationServiceOverride(createDefaultLocaleConfiguration()), @@ -99,8 +101,7 @@ export const createLangiumGlobalConfig = async (params: { }, filesOrContents: extensionFilesOrContents }], - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: params.htmlContainer + monacoWorkerFactory: configureMonacoWorkers }, languageClientConfigs }; diff --git a/packages/examples/src/langium/statemachine/main-react.tsx b/packages/examples/src/langium/statemachine/main-react.tsx index 93547c786..e785b108c 100644 --- a/packages/examples/src/langium/statemachine/main-react.tsx +++ b/packages/examples/src/langium/statemachine/main-react.tsx @@ -18,7 +18,7 @@ export const runStatemachineReact = async () => { worker: loadStatemachineWorkerRegular(), htmlContainer: document.getElementById('monaco-editor-root')! }); - const root = ReactDOM.createRoot(wrapperConfig.editorAppConfig.htmlContainer); + const root = ReactDOM.createRoot(wrapperConfig.htmlContainer); try { document.querySelector('#button-start')?.addEventListener('click', async () => { diff --git a/packages/examples/src/multi/config.ts b/packages/examples/src/multi/config.ts new file mode 100644 index 000000000..3d690e27e --- /dev/null +++ b/packages/examples/src/multi/config.ts @@ -0,0 +1,63 @@ +/* -------------------------------------------------------------------------------------------- + * Copyright (c) 2024 TypeFox and others. + * Licensed under the MIT License. See LICENSE in the package root for license information. + * ------------------------------------------------------------------------------------------ */ + +import * as vscode from 'vscode'; +import { MonacoLanguageClient } from 'monaco-languageclient'; +import { LanguageClientConfig } from 'monaco-editor-wrapper'; + +export const createJsonLanguageClientConfig: () => LanguageClientConfig = () => { + return { + name: 'JSON Client', + clientOptions: { + documentSelector: ['json'] + }, + connection: { + options: { + $type: 'WebSocketParams', + host: 'localhost', + port: 30000, + path: 'sampleServer', + secured: false + } + } + }; +}; + +export const createPythonLanguageClientConfig: () => LanguageClientConfig = () => { + return { + connection: { + options: { + $type: 'WebSocketParams', + host: 'localhost', + port: 30001, + path: 'pyright', + secured: false, + extraParams: { + authorization: 'UserAuth' + }, + startOptions: { + onCall: (languageClient?: MonacoLanguageClient) => { + setTimeout(() => { + ['pyright.restartserver', 'pyright.organizeimports'].forEach((cmdName) => { + vscode.commands.registerCommand(cmdName, (...args: unknown[]) => { + languageClient?.sendRequest('workspace/executeCommand', { command: cmdName, arguments: args }); + }); + }); + }, 250); + }, + reportStatus: true, + } + } + }, + clientOptions: { + documentSelector: ['python', 'py'], + workspaceFolder: { + index: 0, + name: 'workspace', + uri: vscode.Uri.parse('/workspace') + } + } + }; +}; diff --git a/packages/examples/src/multi/twoLanguageClients.ts b/packages/examples/src/multi/twoLanguageClients.ts index 670d29dee..ee1385fef 100644 --- a/packages/examples/src/multi/twoLanguageClients.ts +++ b/packages/examples/src/multi/twoLanguageClients.ts @@ -3,15 +3,15 @@ * Licensed under the MIT License. See LICENSE in the package root for license information. * ------------------------------------------------------------------------------------------ */ -import * as vscode from 'vscode'; +import 'vscode/localExtensionHost'; import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override'; // this is required syntax highlighting import '@codingame/monaco-vscode-json-default-extension'; import '@codingame/monaco-vscode-python-default-extension'; import { LogLevel } from 'vscode/services'; -import { CodePlusFileExt, MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper'; -import { MonacoLanguageClient } from 'monaco-languageclient'; +import { CodePlusFileExt, configureAndInitVscodeApi, LanguageClientWrapper, MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper'; import { configureMonacoWorkers, disableButton } from '../common/client/utils.js'; +import { createJsonLanguageClientConfig, createPythonLanguageClientConfig } from './config.js'; export const runMultipleLanguageClientsExample = async () => { disableButton('button-flip', true); @@ -30,11 +30,19 @@ print("Hello Moon!") let currentText = textJson; let currenFileExt = 'json'; + const lccJson = createJsonLanguageClientConfig(); + const lccPython = createPythonLanguageClientConfig(); + + let lcwJson: LanguageClientWrapper | undefined; + let lcwPython: LanguageClientWrapper | undefined; + const wrapperConfig: WrapperConfig = { id: '42', logLevel: LogLevel.Debug, + htmlContainer: document.getElementById('monaco-editor-root')!, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride() }, userConfiguration: { @@ -54,60 +62,7 @@ print("Hello Moon!") } }, useDiffEditor: false, - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: document.getElementById('monaco-editor-root')! - }, - languageClientConfigs: { - json: { - clientOptions: { - documentSelector: ['json'] - }, - name: 'JSON Client', - connection: { - options: { - $type: 'WebSocketParams', - host: 'localhost', - port: 30000, - path: 'sampleServer', - secured: false - } - } - }, - python: { - name: 'Python Client', - connection: { - options: { - $type: 'WebSocketParams', - host: 'localhost', - port: 30001, - path: 'pyright', - secured: false, - extraParams: { - authorization: 'UserAuth' - }, - startOptions: { - onCall: (languageClient?: MonacoLanguageClient) => { - setTimeout(() => { - ['pyright.restartserver', 'pyright.organizeimports'].forEach((cmdName) => { - vscode.commands.registerCommand(cmdName, (...args: unknown[]) => { - languageClient?.sendRequest('workspace/executeCommand', { command: cmdName, arguments: args }); - }); - }); - }, 250); - }, - reportStatus: true, - } - } - }, - clientOptions: { - documentSelector: ['python', 'py'], - workspaceFolder: { - index: 0, - name: 'workspace', - uri: vscode.Uri.parse('/workspace') - } - } - } + monacoWorkerFactory: configureMonacoWorkers } }; @@ -115,12 +70,45 @@ print("Hello Moon!") try { document.querySelector('#button-start')?.addEventListener('click', async () => { + wrapperConfig.vscodeApiConfig.vscodeApiInitPerformExternally = (document.getElementById('checkbox-extlc')! as HTMLInputElement).checked; + if (wrapperConfig.vscodeApiConfig.vscodeApiInitPerformExternally === true) { + + const logger = wrapper.getLogger(); + logger.setLevel(wrapperConfig.logLevel!); + await configureAndInitVscodeApi({ + vscodeApiConfig: wrapperConfig.vscodeApiConfig!, + logLevel: wrapperConfig.logLevel!, + }, { + htmlContainer: wrapperConfig.htmlContainer, + caller: 'runMultipleLanguageClientsExample', + logger + }); + + if (lcwJson === undefined) { + lcwJson = new LanguageClientWrapper({ + languageClientConfig: lccJson + }); + await lcwJson.start(); + } + if (lcwPython === undefined) { + lcwPython = new LanguageClientWrapper({ + languageClientConfig: lccPython + }); + await lcwPython.start(); + } + } else { + wrapperConfig.languageClientConfigs = { + json: lccJson, + python: lccPython + }; + } + + await wrapper.initAndStart(wrapperConfig); if (wrapperConfig.editorAppConfig.codeResources?.main !== undefined) { (wrapperConfig.editorAppConfig.codeResources.main as CodePlusFileExt).text = currentText; (wrapperConfig.editorAppConfig.codeResources.main as CodePlusFileExt).fileExt = currenFileExt; } - await wrapper.initAndStart(wrapperConfig); disableButton('button-flip', false); }); document.querySelector('#button-dispose')?.addEventListener('click', async () => { diff --git a/packages/examples/src/python/client/config.ts b/packages/examples/src/python/client/config.ts index 224f0a64c..deeae4ad2 100644 --- a/packages/examples/src/python/client/config.ts +++ b/packages/examples/src/python/client/config.ts @@ -62,8 +62,10 @@ export const createUserConfig = (workspaceRoot: string, code: string, codeUri: s } }, logLevel: LogLevel.Debug, + htmlContainer: document.getElementById('monaco-editor-root')!, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride() }, userConfiguration: { @@ -84,8 +86,7 @@ export const createUserConfig = (workspaceRoot: string, code: string, codeUri: s } }, useDiffEditor: false, - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: document.getElementById('monaco-editor-root')! + monacoWorkerFactory: configureMonacoWorkers } }; }; diff --git a/packages/examples/src/python/client/reactPython.tsx b/packages/examples/src/python/client/reactPython.tsx index 77c961653..1e3b5edc7 100644 --- a/packages/examples/src/python/client/reactPython.tsx +++ b/packages/examples/src/python/client/reactPython.tsx @@ -22,7 +22,7 @@ export const runPythonReact = async () => { console.log(`Dirty? ${textChanges.isDirty}\ntext: ${textChanges.text}\ntextOriginal: ${textChanges.textOriginal}`); }; const wrapperConfig = createUserConfig('/workspace', badPyCode, '/workspace/bad.py'); - const root = ReactDOM.createRoot(wrapperConfig.editorAppConfig.htmlContainer); + const root = ReactDOM.createRoot(wrapperConfig.htmlContainer); try { document.querySelector('#button-start')?.addEventListener('click', async () => { diff --git a/packages/examples/src/ts/wrapperTs.ts b/packages/examples/src/ts/wrapperTs.ts index 1e8cdca56..1b2867bcd 100644 --- a/packages/examples/src/ts/wrapperTs.ts +++ b/packages/examples/src/ts/wrapperTs.ts @@ -5,7 +5,7 @@ import * as vscode from 'vscode'; import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override'; -import '@codingame/monaco-vscode-typescript-basics-default-extension'; +import '@codingame/monaco-vscode-stypescript-basics-default-extension'; import '@codingame/monaco-vscode-typescript-language-features-default-extension'; import { LogLevel } from 'vscode/services'; import { CodePlusUri, MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper'; @@ -24,8 +24,10 @@ export const runTsWrapper = async () => { const wrapperConfig: WrapperConfig = { logLevel: LogLevel.Debug, + htmlContainer: document.getElementById('monaco-editor-root')!, vscodeApiConfig: { - userServices: { + enableTextmate: true, + serviceOverrides: { ...getKeybindingsServiceOverride() }, enableExtHostWorker: true, @@ -55,8 +57,7 @@ export const runTsWrapper = async () => { } }, useDiffEditor: false, - monacoWorkerFactory: configureMonacoWorkers, - htmlContainer: document.getElementById('monaco-editor-root')! + monacoWorkerFactory: configureMonacoWorkers } }; diff --git a/packages/examples/two_langauge_clients.html b/packages/examples/two_langauge_clients.html index f4090c775..494653aef 100644 --- a/packages/examples/two_langauge_clients.html +++ b/packages/examples/two_langauge_clients.html @@ -15,6 +15,7 @@ +