Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to monaco-vscode-api 9.0.x #749

Merged
merged 9 commits into from
Sep 26, 2024
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ loader.config({ monaco });
If you use pnpm, you have to add `vscode` / `@codingame/monaco-vscode-api` as direct dependency (you find the [compatibility table here](https://github.com/TypeFox/monaco-languageclient/blob/main/docs/versions-and-history.md#monaco-editor--codingamemonaco-vscode-api-compatibility-table), otherwise the installation will fail.

```json
"vscode": "npm:@codingame/monaco-vscode-api@~8.0.4"
"vscode": "npm:@codingame/monaco-vscode-api@~9.0.3"
```

## Licenses
Expand Down
2 changes: 1 addition & 1 deletion docs/versions-and-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The following table describes which version of **monaco-languageclient** and **@

| monaco-languageclient | monaco-editor-wrapper | monaco-editor-react | monaco-vscode-api / editor-api | vscode | monaco-editor | release date | comment |
| :---- | :---- | :--- | :--- | :--- | :--- | :--- | :--- |
| 9.0.0-next.0 | 6.0.0-next.0 | 6.0.0-next.0 | 8.0.4 | 1.92.2 | 0.51.0 | 2024-09-xy | |
| 9.0.0-next.1 | 6.0.0-next.1 | 6.0.0-next.1 | 9.0.3 | 1.93.1 | 0.52.0 | 2024-09-xy | |
| 8.8.3 | 5.5.3 | 4.5.3 | 8.0.4 | 1.92.2 | 0.51.0 | 2024-08-26 | |
| 8.8.2 | 5.5.2 | 4.5.2 | 8.0.2 | 1.92.2 | 0.50.0 | 2024-08-21 | |
| 8.8.1 | 5.5.1 | 4.5.1 | 8.0.1 | 1.92.1 | 0.50.0 | 2024-08-12 | |
Expand Down
10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ <h2>Monaco Editor Wrapper</h2>
<h3>JSON</h3>

Please execute <b><code>npm run start:example:server:json</code></b> beforehand:<br>
<a href="./packages/examples/wrapper_ws.html">JSON Language Client & Language Server (Web Socket)</a>
<a href="./packages/examples/json.html">JSON Language Client & Language Server (Web Socket)</a>
<br>
<a href="./packages/examples/browser.html">Language Client Pure Browser Example</a>
<br>

<h3>Langium</h3>

<a href="./packages/examples/wrapper_langium.html">Langium Grammar DSL Language Client & Language Server (Worker)</a>
<a href="./packages/examples/langium.html">Langium Grammar DSL Language Client & Language Server (Worker)</a>
<br>
<a href="./packages/examples/wrapper_statemachine.html">Langium Statemachine Client & Language Server (Worker)</a>
<a href="./packages/examples/statemachine.html">Langium Statemachine Client & Language Server (Worker)</a>
<br>
Localizations: <a href="./packages/examples/wrapper_statemachine.html?locale=de">German</a> <a href="./packages/examples/wrapper_statemachine.html?locale=fr">French</a> and <a href="./packages/examples/wrapper_statemachine.html?locale=es">Spanish</a><br>
Localizations: <a href="./packages/examples/statemachine.html?locale=de">German</a> <a href="./packages/examples/statemachine.html?locale=fr">French</a> and <a href="./packages/examples/statemachine.html?locale=es">Spanish</a><br>

<h3>Python</h3>
Please execute <b><code>npm run start:example:server:python</code></b> beforehand:<br>
Expand Down Expand Up @@ -68,7 +68,7 @@ <h2>Monaco Editor React</h2>
<br>

<h3>monaco-editor related examples</h3>
<a href="./packages/examples/wrapper_ts.html">Monaco Editor Wrapper TypeScript Example</a>
<a href="./packages/examples/ts.html">Monaco Editor Wrapper TypeScript Example</a>
<br>

<h2>Verification</h2>
Expand Down
1,513 changes: 728 additions & 785 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@
"type": "module",
"devDependencies": {
"@codingame/esbuild-import-meta-url-plugin": "~1.0.2",
"@codingame/monaco-vscode-rollup-vsix-plugin": "~8.0.4",
"@rollup/pluginutils": "~5.1.0",
"@codingame/monaco-vscode-rollup-vsix-plugin": "~9.0.3",
"@testing-library/react": "~16.0.1",
"@types/node": "~20.16.5",
"@types/react": "~18.3.5",
"@types/react": "~18.3.8",
"@types/react-dom": "~18.3.0",
"@types/vscode": "~1.92.0",
"@types/vscode": "~1.93.0",
"@typescript-eslint/eslint-plugin": "~7.18.0",
"@typescript-eslint/parser": "~7.18.0",
"@vitejs/plugin-react": "~4.3.1",
"@vitest/browser": "~2.0.5",
"@vitest/browser": "~2.1.1",
"editorconfig": "~2.0.0",
"esbuild": "~0.23.1",
"esbuild": "~0.24.0",
"eslint": "~8.57.0",
"eslint-plugin-header": "~3.1.1",
"eslint-plugin-import": "~2.29.1",
"eslint-plugin-unused-imports": "~3.2.0",
"http-server": "~14.1.1",
"minimatch": "~10.0.1",
"typescript": "~5.5.4",
"vite": "~5.4.3",
"vite-node": "~2.0.5",
"vitest": "~2.0.5",
"webdriverio": "~9.0.7"
"vite": "~5.4.7",
"vite-node": "~2.1.1",
"vitest": "~2.1.1",
"webdriverio": "~9.1.0"
},
"volta": {
"node": "20.17.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

All notable changes to this npm module are documented in this file.

## [9.0.0-next.0] - 2024-08-26
## [9.0.0-next.1] - 2024-09-xy

- Update to monaco-vscode-api 9.0.3 (monaco-editor 0.52.0)
- Pass MessageTransports directly

## [8.8.3] - 2024-08-26
Expand Down
25 changes: 13 additions & 12 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monaco-languageclient",
"version": "9.0.0-next.0",
"version": "9.0.0-next.1",
"description": "Monaco Language client implementation",
"author": {
"name": "TypeFox GmbH",
Expand Down Expand Up @@ -29,8 +29,8 @@
"default": "./lib/tools/index.js"
},
"./vscode/services": {
"types": "./lib/vscode/services.d.ts",
"default": "./lib/vscode/services.js"
"types": "./lib/vscode/index.d.ts",
"default": "./lib/vscode/index.js"
}
},
"typesVersions": {
Expand All @@ -42,7 +42,7 @@
"lib/tools/index"
],
"vscode/services": [
"lib/vscode/services"
"lib/vscode/index"
]
}
},
Expand All @@ -62,17 +62,18 @@
"LICENSE"
],
"dependencies": {
"@codingame/monaco-vscode-extensions-service-override": "~8.0.4",
"@codingame/monaco-vscode-languages-service-override": "~8.0.4",
"@codingame/monaco-vscode-localization-service-override": "~8.0.4",
"@codingame/monaco-vscode-model-service-override": "~8.0.4",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~8.0.4",
"vscode": "npm:@codingame/monaco-vscode-api@~8.0.4",
"@codingame/monaco-vscode-extensions-service-override": "~9.0.3",
"@codingame/monaco-vscode-languages-service-override": "~9.0.3",
"@codingame/monaco-vscode-localization-service-override": "~9.0.3",
"@codingame/monaco-vscode-log-service-override": "~9.0.3",
"@codingame/monaco-vscode-model-service-override": "~9.0.3",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~9.0.3",
"vscode": "npm:@codingame/monaco-vscode-api@~9.0.3",
"vscode-languageclient": "~9.0.1"
},
"peerDependencies": {
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~8.0.4",
"vscode": "npm:@codingame/monaco-vscode-api@~8.0.4"
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~9.0.3",
"vscode": "npm:@codingame/monaco-vscode-api@~9.0.3"
},
"peerDependenciesMeta": {
"monaco-editor": {
Expand Down
2 changes: 0 additions & 2 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

export type * from './client.js';
export * from './client.js';
export type * from './commonTypes.js';
export * from './commonTypes.js';
40 changes: 1 addition & 39 deletions packages/client/src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,4 @@
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

export type LoggerConfig = {
enabled: boolean,
debugEnabled?: boolean
};

export class Logger {

private enabled: boolean;
private debugEnabled: boolean;

constructor(config?: LoggerConfig) {
this.updateConfig(config);
}

updateConfig(config?: LoggerConfig) {
this.enabled = !config ? true : config!.enabled === true;
this.debugEnabled = this.enabled && config?.debugEnabled === true;
}

isEnabled() {
return this.enabled;
}

isDebugEnabled() {
return this.debugEnabled;
}

info(message: string) {
if (this.enabled) {
console.log(message);
}
}

debug(message: string, force?: boolean) {
if (this.enabled && (this.debugEnabled || force === true)) {
console.debug(message);
}
}
}
export * from './logging.js';
26 changes: 26 additions & 0 deletions packages/client/src/tools/logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

import { ConsoleLogger as VSCodeConsoleLogger, ILogger } from '@codingame/monaco-vscode-log-service-override';
import { LogLevel } from 'vscode/services';

export interface Logger extends ILogger {
createErrorAndLog(message: string, ...params: unknown[]): Error;
}

export class ConsoleLogger extends VSCodeConsoleLogger {

constructor(logLevel?: LogLevel, useColors?: boolean) {
super(logLevel ?? LogLevel.Off, useColors);
}

createErrorAndLog(message: string, ...params: unknown[]) {
if (this.getLevel() >= LogLevel.Error) {
this.error(message, ...params);
}
return new Error(message);
}

}
7 changes: 7 additions & 0 deletions packages/client/src/vscode/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

export * from './fakeWorker.js';
export * from './services.js';
54 changes: 22 additions & 32 deletions packages/client/src/vscode/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

import * as monaco from 'monaco-editor';
import 'vscode/localExtensionHost';
import { ILogService, initialize, IWorkbenchConstructionOptions, LogLevel, StandaloneServices } from 'vscode/services';
import { ILogService, initialize, IWorkbenchConstructionOptions, StandaloneServices, LogLevel } from 'vscode/services';
import type { WorkerConfig } from '@codingame/monaco-vscode-extensions-service-override';
import getExtensionServiceOverride from '@codingame/monaco-vscode-extensions-service-override';
import getLanguagesServiceOverride from '@codingame/monaco-vscode-languages-service-override';
import getModelServiceOverride from '@codingame/monaco-vscode-model-service-override';
import getLogServiceOverride from '@codingame/monaco-vscode-log-service-override';
import type { LocalizationOptions } from '@codingame/monaco-vscode-localization-service-override';
import { Logger } from 'monaco-languageclient/tools';
import { FakeWorker as Worker } from './fakeWorker.js';
import { Logger } from '../tools/index.js';

export interface MonacoEnvironmentEnhanced extends monaco.Environment {
vscodeInitialising?: boolean;
Expand All @@ -22,10 +23,15 @@ export interface MonacoEnvironmentEnhanced extends monaco.Environment {
export interface InitializeServiceConfig {
userServices?: monaco.editor.IEditorOverrideServices;
enableExtHostWorker?: boolean;
debugLogging?: boolean;
workspaceConfig?: IWorkbenchConstructionOptions;
}

export interface InitServicesInstructions extends InitializeServiceConfig {
caller?: string;
performChecks?: () => boolean;
logger?: Logger;
}

export const initEnhancedMonacoEnvironment = () => {
const monWin = (self as Window);
if (!monWin.MonacoEnvironment) {
Expand All @@ -45,6 +51,7 @@ export const initEnhancedMonacoEnvironment = () => {
export const supplyRequiredServices = async () => {
return {
...getLanguagesServiceOverride(),
...getLogServiceOverride(),
...getModelServiceOverride()
};
};
Expand All @@ -61,33 +68,18 @@ export const mergeServices = (services: monaco.editor.IEditorOverrideServices, o
}
};

export interface InitServicesInstruction {
serviceConfig?: InitializeServiceConfig;
caller?: string;
performChecks?: () => boolean;
logger?: Logger;
}

export const initServices = async (instruction: InitServicesInstruction) => {
export const initServices = async (instructions: InitServicesInstructions) => {
const envEnhanced = initEnhancedMonacoEnvironment();

// in case debugLogging is set and for whatever reason no logger is passed a proper one is created
if (instruction.serviceConfig?.debugLogging === true && !instruction.logger) {
instruction.logger = new Logger({
enabled: true,
debugEnabled: true
});
}

if (!(envEnhanced.vscodeInitialising ?? false)) {
if (envEnhanced.vscodeApiInitialised ?? false) {
instruction.logger?.debug('Initialization of vscode services can only performed once!');
instructions.logger?.debug('Initialization of vscode services can only performed once!');
} else {
envEnhanced.vscodeInitialising = true;
instruction.logger?.debug(`Initializing vscode services. Caller: ${instruction.caller ?? 'unknown'}`);
instructions.logger?.debug(`Initializing vscode services. Caller: ${instructions.caller ?? 'unknown'}`);

await importAllServices(instruction);
instruction.logger?.debug('Initialization of vscode services completed successfully.');
await importAllServices(instructions);
instructions.logger?.debug('Initialization of vscode services completed successfully.');

envEnhanced.vscodeApiInitialised = true;
}
Expand All @@ -105,21 +97,19 @@ export const initServices = async (instruction: InitServicesInstruction) => {
* - languages
* - model
*/
export const importAllServices = async (instruction: InitServicesInstruction) => {
const lc: InitializeServiceConfig = instruction.serviceConfig ?? {};
const userServices: monaco.editor.IEditorOverrideServices = lc.userServices ?? {};
export const importAllServices = async (instructions: InitServicesInstructions) => {
const userServices: monaco.editor.IEditorOverrideServices = instructions.userServices ?? {};

const lcRequiredServices = await supplyRequiredServices();

mergeServices(lcRequiredServices, userServices);
await configureExtHostWorker(instruction.serviceConfig?.enableExtHostWorker === true, userServices);
await configureExtHostWorker(instructions.enableExtHostWorker === true, userServices);

reportServiceLoading(userServices, instruction.logger);
reportServiceLoading(userServices, instructions.logger);

if (instruction.performChecks === undefined || instruction.performChecks()) {
await initialize(userServices, undefined, lc.workspaceConfig);
const logLevel = lc.workspaceConfig?.developmentOptions?.logLevel ?? LogLevel.Info;
StandaloneServices.get(ILogService).setLevel(logLevel);
if (instructions.performChecks === undefined || (typeof instructions.performChecks === 'function' && instructions.performChecks())) {
await initialize(userServices, undefined, instructions.workspaceConfig);
StandaloneServices.get(ILogService).setLevel(instructions.logger?.getLevel() ?? LogLevel.Off);
kaisalmen marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down
Loading