diff --git a/index.html b/index.html index 6b3c499..9fbe26e 100644 --- a/index.html +++ b/index.html @@ -44,10 +44,11 @@

Monaco Editor React


Verification

- Here the bundles are used instead of the direct sources.
- For the "Static HTTP Server Alternative" you need to run npm run start --workspace packages/examples as well. + Here the bundles are used instead of the direct sources.

Monaco Editor Wrapper Bundle Verification

+ For the "Static HTTP Server Alternative" please start npm run start:http beforehand.
+ JavaScript Diff (Static HTTP Server Alternative)
diff --git a/package.json b/package.json index 33866d4..aa0428a 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "test:run": "node --experimental-import-meta-resolve ./node_modules/vitest/vitest.mjs -c vite.config.ts --run", "release:prepare": "npm run reset:repo && npm ci && npm run lint && npm run build && npm run test:run", "reset:repo": "git clean -f -X -d", + "start:http": "npm run start:http --workspace packages/examples", "start:example:server:json": "npm run start:server:json --workspace packages/examples", "start:example:server:python": "npm run start:server:python --workspace packages/examples" }, diff --git a/packages/examples/package.json b/packages/examples/package.json index 637920b..030f088 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -52,7 +52,7 @@ "copy:all": "npm run copy:prepare && npm run copy:workers", "build:bundle:wrapper": "vite --config vite.bundle-mew.ts build", "build": "npm run clean && npm run compile && npm run build:bundle:wrapper && npm run copy:all", - "start": "http-server --port 20002 ./", + "start:http": "http-server --port 20002 ./", "start:server:json": "node --loader ts-node/esm ./src/servers/json-server.ts", "start:server:python": "node --loader ts-node/esm ./src/servers/python-server.ts" } diff --git a/packages/examples/src/reactPython.tsx b/packages/examples/src/reactPython.tsx index dda7d2d..b2dae0c 100644 --- a/packages/examples/src/reactPython.tsx +++ b/packages/examples/src/reactPython.tsx @@ -41,7 +41,9 @@ const userConfig: UserConfig = { }, reportStatus: true, } - }, configurationOptions: { + }, + clientOptions: { + documentSelector: ['python'], workspaceFolder: { index: 0, name: 'workspace', diff --git a/packages/monaco-editor-wrapper/CHANGELOG.md b/packages/monaco-editor-wrapper/CHANGELOG.md index d006d3f..eb11337 100644 --- a/packages/monaco-editor-wrapper/CHANGELOG.md +++ b/packages/monaco-editor-wrapper/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to npm module [monaco-editor-wrapper](https://www.npmjs.com/ ## [3.6.0] - 2024-01-04 - Updated to `monaco-languageclient@7.3.0` and `@codingame/monaco-vscode-api@1.85.0` / `@codingame/monaco-editor-treemended@1.85.0` (=`monaco-editor@0.45.0`). +- How to modify client's capabilities? [#61](https://github.com/TypeFox/monaco-components/issues/61) + - It is now possible to provide and fully override boh monaco-languageclient's clientOptions and connectionProvider ## [3.5.0] - 2023-11-07 diff --git a/packages/monaco-editor-wrapper/src/languageClientWrapper.ts b/packages/monaco-editor-wrapper/src/languageClientWrapper.ts index 23f2c1a..533b874 100644 --- a/packages/monaco-editor-wrapper/src/languageClientWrapper.ts +++ b/packages/monaco-editor-wrapper/src/languageClientWrapper.ts @@ -1,9 +1,8 @@ -import { initServices, InitializeServiceConfig, MonacoLanguageClient } from 'monaco-languageclient'; +import { initServices, InitializeServiceConfig, MonacoLanguageClient, IConnectionProvider } from 'monaco-languageclient'; import { toSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc'; import { BrowserMessageReader, BrowserMessageWriter } from 'vscode-languageserver-protocol/browser.js'; -import { CloseAction, ErrorAction, MessageTransports, State } from 'vscode-languageclient/lib/common/client.js'; +import { CloseAction, ErrorAction, LanguageClientOptions, MessageTransports, State } from 'vscode-languageclient/lib/common/client.js'; import { createUrl } from './utils.js'; -import { $ConfigurationOptions } from 'vscode-languageclient/lib/common/configuration.js'; import { Logger } from './logger.js'; export type WebSocketCallOptions = { @@ -59,9 +58,8 @@ export type WorkerConfigDirect = LanguageClientConfigBase & { export type LanguageClientConfig = { options: WebSocketConfigOptions | WebSocketConfigOptionsUrl | WorkerConfigOptions | WorkerConfigDirect; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - initializationOptions?: any; - configurationOptions?: $ConfigurationOptions + clientOptions?: LanguageClientOptions; + connectionProvider?: IConnectionProvider; } export type LanguageClientError = { @@ -251,28 +249,30 @@ export class LanguageClientWrapper { } private createLanguageClient(transports: MessageTransports): MonacoLanguageClient { - return new MonacoLanguageClient({ + const mlcConfig = { name: this.languageClientConfig?.options.name ?? 'Monaco Wrapper Language Client', - clientOptions: { - // use a language id as a document selector + + // allow to fully override the clientOptions + clientOptions: this.languageClientConfig?.clientOptions ?? { documentSelector: [this.languageId!], // disable the default error handler errorHandler: { error: () => ({ action: ErrorAction.Continue }), closed: () => ({ action: CloseAction.DoNotRestart }) - }, - // allow to initialize the language client with user specific options - initializationOptions: this.languageClientConfig?.initializationOptions, - - ...(this.languageClientConfig?.configurationOptions ?? {}) + } }, - // create a language client connection from the JSON RPC connection on demand - connectionProvider: { + // allow to fully override the clonnecetionProvider + connectionProvider: this.languageClientConfig?.connectionProvider ?? { get: () => { return Promise.resolve(transports); } } - }); + }; + if (!mlcConfig.clientOptions.documentSelector?.includes(this.languageId)) { + throw new Error(`languageClientWrapper (${this.name}): The language id '${this.languageId}' is not included in the document selector.`); + } + + return new MonacoLanguageClient(mlcConfig); } private disposeWorker(keepWorker?: boolean) {