Skip to content

Commit

Permalink
Merge pull request #756 from TypeFox/env-views-options
Browse files Browse the repository at this point in the history
Support all arguments for monaco-vscode-api initialize
  • Loading branch information
kaisalmen authored Oct 7, 2024
2 parents 09fa65b + 7b61d52 commit 986697e
Show file tree
Hide file tree
Showing 62 changed files with 850 additions and 666 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ indent_size = 2

[*.md]
indent_size = 2

[*.yml]
indent_size = 2
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.1 | 6.0.0-next.1 | 6.0.0-next.1 | 9.0.3 | 1.93.1 | 0.52.0 | 2024-09-xy | |
| 9.0.0-next.2 | 6.0.0-next.2 | 6.0.0-next.2 | 9.0.3 | 1.93.1 | 0.52.0 | 2024-10-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
788 changes: 424 additions & 364 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
"@codingame/esbuild-import-meta-url-plugin": "~1.0.2",
"@codingame/monaco-vscode-rollup-vsix-plugin": "~9.0.3",
"@testing-library/react": "~16.0.1",
"@types/node": "~20.16.9",
"@types/react": "~18.3.9",
"@types/node": "~20.16.10",
"@types/react": "~18.3.10",
"@types/react-dom": "~18.3.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.1.1",
"@vitejs/plugin-react": "~4.3.2",
"@vitest/browser": "~2.1.2",
"editorconfig": "~2.0.0",
"esbuild": "~0.24.0",
"eslint": "~8.57.0",
"eslint": "~8.57.1",
"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",
"playwright": "~1.47.2",
"typescript": "~5.5.4",
"typescript": "~5.6.2",
"vite": "~5.4.8",
"vite-node": "~2.1.1",
"vitest": "~2.1.1",
"webdriverio": "~9.1.1"
"vite-node": "~2.1.2",
"vitest": "~2.1.2",
"webdriverio": "~9.1.2"
},
"volta": {
"node": "20.17.0",
"node": "20.18.0",
"npm": "10.8.3"
},
"scripts": {
Expand Down Expand Up @@ -57,7 +57,7 @@
"release:prepare": "npm run reset:repo && npm ci && npm run build && npm run lint && npm run test:run",
"reset:repo": "git clean -f -X -d",
"test": "npm run test:webdriverio",
"test:run": "npm run test:webdriverio",
"test:run": "npm run test:webdriverio:run",
"test:webdriverio": "vitest",
"test:webdriverio:run": "vitest --run",
"test:playwright": "vitest --config vitest.debug.config.ts",
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.1] - 2024-09-xy
## [9.0.0-next.2] - 2024-10-xy

- Support all arguments for monaco-vscode-api `initialize` [#756](https://github.com/TypeFox/monaco-languageclient/pull/756)
- Update to monaco-vscode-api 9.0.x [#749](https://github.com/TypeFox/monaco-languageclient/pull/749)
- Updated all `@codingame/monaco-vscode` packages to `9.0.3`.
- Enhancements to logging
Expand Down
4 changes: 2 additions & 2 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.1",
"version": "9.0.0-next.2",
"description": "Monaco Language client implementation",
"author": {
"name": "TypeFox GmbH",
Expand Down Expand Up @@ -51,7 +51,7 @@
"npm": ">=9.0.0"
},
"volta": {
"node": "20.17.0",
"node": "20.18.0",
"npm": "10.8.3"
},
"files": [
Expand Down
33 changes: 26 additions & 7 deletions packages/client/src/vscode/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

import * as monaco from 'monaco-editor';
import 'vscode/localExtensionHost';
import { ILogService, initialize, IWorkbenchConstructionOptions, StandaloneServices, LogLevel } from 'vscode/services';
import { initialize, IWorkbenchConstructionOptions } from 'vscode/services';
import { OpenEditor } from '@codingame/monaco-vscode-editor-service-override';
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 { EnvironmentOverride } from 'vscode/workbench';
import { Logger } from 'monaco-languageclient/tools';
import { FakeWorker as Worker } from './fakeWorker.js';

Expand All @@ -20,13 +22,25 @@ export interface MonacoEnvironmentEnhanced extends monaco.Environment {
vscodeApiInitialised?: boolean;
}

export interface InitializeServiceConfig {
export interface UserConfiguration {
json?: string;
}

export interface VscodeApiConfig {
userServices?: monaco.editor.IEditorOverrideServices;
enableExtHostWorker?: boolean;
workspaceConfig?: IWorkbenchConstructionOptions;
userConfiguration?: UserConfiguration;
viewsConfig?: {
viewServiceType: 'EditorService' | 'ViewsService' | 'WorkspaceService';
openEditorFunc?: OpenEditor;
viewsInitFunc?: () => void;
},
envOptions?: EnvironmentOverride;
}

export interface InitServicesInstructions extends InitializeServiceConfig {
export interface InitVscodeApiInstructions extends VscodeApiConfig {
htmlContainer: HTMLElement;
caller?: string;
performChecks?: () => boolean;
logger?: Logger;
Expand All @@ -48,6 +62,11 @@ export const initEnhancedMonacoEnvironment = () => {
return envEnhanced;
};

export const getMonacoEnvironmentEnhanced = () => {
const monWin = (self as Window);
return monWin.MonacoEnvironment as MonacoEnvironmentEnhanced;
};

export const supplyRequiredServices = async () => {
return {
...getLanguagesServiceOverride(),
Expand All @@ -68,7 +87,7 @@ export const mergeServices = (services: monaco.editor.IEditorOverrideServices, o
}
};

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

if (!(envEnhanced.vscodeInitialising ?? false)) {
Expand All @@ -79,6 +98,7 @@ export const initServices = async (instructions: InitServicesInstructions) => {
instructions.logger?.debug(`Initializing vscode services. Caller: ${instructions.caller ?? 'unknown'}`);

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

envEnhanced.vscodeApiInitialised = true;
Expand All @@ -97,7 +117,7 @@ export const initServices = async (instructions: InitServicesInstructions) => {
* - languages
* - model
*/
export const importAllServices = async (instructions: InitServicesInstructions) => {
export const importAllServices = async (instructions: InitVscodeApiInstructions) => {
const userServices: monaco.editor.IEditorOverrideServices = instructions.userServices ?? {};

const lcRequiredServices = await supplyRequiredServices();
Expand All @@ -108,8 +128,7 @@ export const importAllServices = async (instructions: InitServicesInstructions)
reportServiceLoading(userServices, instructions.logger);

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);
await initialize(userServices, instructions.htmlContainer, instructions.workspaceConfig, instructions.envOptions);
}
};

Expand Down
8 changes: 6 additions & 2 deletions packages/examples/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

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

## [2024.9.1] - 2024-09-xy
## [2024.10.1] - 20241-10-xy

- Updated to `monaco-languageclient@9.0.0-next.1`, `monaco-editor-wrapper@6.0.0-next.1` and `@typefox/monaco-editor-react@6.0.0-next.1`. Updated all `@codingame/monaco-vscode` packages to `9.0.3`.
- Aligend example config. `htmlContainer` is now a required property of `editorAppConfig`

## [2024.9.1] - 2024-09-27

- Updated to `monaco-languageclient@9.0.0-next.2`, `monaco-editor-wrapper@6.0.0-next.2` and `@typefox/monaco-editor-react@6.0.0-next.2`. Updated all `@codingame/monaco-vscode` packages to `9.0.3`.
- Align configuration of all examples to the latest configuration adjustments.
- Only use a single function to configure `monaco-editor` that all examples.
- `server-commons`: Allow to set `requestMessageHandler` and `responseMessageHandler`.
Expand Down
6 changes: 3 additions & 3 deletions packages/examples/build/downloadResources.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

export const getLocalDirectory = () => {
const __filename = fileURLToPath(import.meta.url);
Expand Down
10 changes: 5 additions & 5 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
"@codingame/monaco-vscode-theme-service-override": "~9.0.3",
"@codingame/monaco-vscode-typescript-basics-default-extension": "~9.0.3",
"@codingame/monaco-vscode-typescript-language-features-default-extension": "~9.0.3",
"@typefox/monaco-editor-react": "~6.0.0-next.1",
"@typefox/monaco-editor-react": "~6.0.0-next.2",
"express": "~4.21.0",
"langium": "~3.2.0",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~9.0.3",
"monaco-editor-wrapper": "~6.0.0-next.1",
"monaco-languageclient": "~9.0.0-next.1",
"pyright": "~1.1.382",
"monaco-editor-wrapper": "~6.0.0-next.2",
"monaco-languageclient": "~9.0.0-next.2",
"pyright": "~1.1.383",
"react": "~18.3.1",
"react-dom": "~18.3.1",
"request-light": "~0.8.0",
Expand All @@ -98,7 +98,7 @@
"vscode-languageserver-types": "~3.17.5"
},
"volta": {
"node": "20.17.0",
"node": "20.18.0",
"npm": "10.8.3"
},
"files": [
Expand Down
4 changes: 3 additions & 1 deletion packages/examples/src/bare/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import { updateUserConfiguration } from '@codingame/monaco-vscode-configuration-

export const runClient = async () => {
const logger = new ConsoleLogger(LogLevel.Debug);
const htmlContainer = document.getElementById('monaco-editor-root')!;
await initServices({
userServices: {
...getConfigurationServiceOverride(),
...getThemeServiceOverride(),
...getTextmateServiceOverride(),
},
htmlContainer,
logger
});

Expand All @@ -46,7 +48,7 @@ export const runClient = async () => {
configureMonacoWorkers(logger);

// create monaco editor
monaco.editor.create(document.getElementById('monaco-editor-root')!, {
monaco.editor.create(htmlContainer, {
value: `{
"$schema": "http://json.schemastore.org/coffeelint",
"line_endings": "unix"
Expand Down
25 changes: 13 additions & 12 deletions packages/examples/src/browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const runBrowserEditor = async () => {
const protocolConverter = createProtocolConverter(undefined, true, true);

let mainVscodeDocument: vscode.TextDocument | undefined;
const htmlElement = document.getElementById('monaco-editor-root');
const htmlContainer = document.getElementById('monaco-editor-root')!;
const languageId = 'json';
const code = `{
"$schema": "http://json.schemastore.org/coffeelint",
Expand All @@ -30,9 +30,17 @@ export const runBrowserEditor = async () => {
const wrapper = new MonacoEditorLanguageClientWrapper();
const jsonClientUserConfig: WrapperConfig = {
logLevel: LogLevel.Debug,
serviceConfig: {
vscodeApiConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': 'On',
'editor.experimental.asyncTokenization': true
})
}
},
editorAppConfig: {
Expand All @@ -44,15 +52,8 @@ export const runBrowserEditor = async () => {
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': 'On',
'editor.experimental.asyncTokenization': true
})
},
monacoWorkerFactory: configureMonacoWorkers
monacoWorkerFactory: configureMonacoWorkers,
htmlContainer
}
};
await wrapper.init(jsonClientUserConfig);
Expand Down Expand Up @@ -155,7 +156,7 @@ export const runBrowserEditor = async () => {
diagnosticCollection.clear();
};

await wrapper.start(htmlElement);
await wrapper.start();

wrapper.getTextModels()?.text?.onDidChangeContent(() => {
validate();
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/src/common/node/server-commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { URL } from 'node:url';
import { Socket } from 'node:net';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import * as cp from 'node:child_process';
import { IWebSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc';
import { createConnection, createServerProcess, forward } from 'vscode-ws-jsonrpc/server';
import { Message, InitializeRequest, InitializeParams, RequestMessage, ResponseMessage } from 'vscode-languageserver-protocol';
import * as cp from 'child_process';

export enum LanguageName {
/** https://nodejs.org/api/cli.html */
Expand Down
24 changes: 12 additions & 12 deletions packages/examples/src/eclipse.jdt.ls/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ export const runEclipseJdtLsClient = () => {

const userConfig: WrapperConfig = {
logLevel: LogLevel.Debug,
serviceConfig: {
vscodeApiConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.wordBasedSuggestions': 'off',
'editor.experimental.asyncTokenization': true
})
}
},
editorAppConfig: {
Expand All @@ -36,15 +44,8 @@ export const runEclipseJdtLsClient = () => {
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.wordBasedSuggestions': 'off',
'editor.experimental.asyncTokenization': true
})
},
monacoWorkerFactory: configureMonacoWorkers
monacoWorkerFactory: configureMonacoWorkers,
htmlContainer: document.getElementById('monaco-editor-root')!
},
languageClientConfigs: {
java: {
Expand All @@ -68,7 +69,6 @@ export const runEclipseJdtLsClient = () => {
};

const wrapper = new MonacoEditorLanguageClientWrapper();
const htmlElement = document.getElementById('monaco-editor-root');

try {
document.querySelector('#button-start')?.addEventListener('click', async () => {
Expand All @@ -77,7 +77,7 @@ export const runEclipseJdtLsClient = () => {
// open files, so the LS can pick it up
await vscode.workspace.openTextDocument(helloJavaUri);

await wrapper.start(htmlElement);
await wrapper.start();
});
document.querySelector('#button-dispose')?.addEventListener('click', async () => {
await wrapper.dispose();
Expand Down
Loading

0 comments on commit 986697e

Please sign in to comment.