Skip to content

Commit

Permalink
Clean-up and allow registering a registerModelUpdate callback
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Oct 11, 2024
1 parent 0a7026f commit 834db30
Show file tree
Hide file tree
Showing 29 changed files with 535 additions and 807 deletions.
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@~10.0.1"
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.2"
```

## 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.2 | 6.0.0-next.2 | 6.0.0-next.2 | 10.0.1 | 1.94.1 | 0.52.0 | 2024-10-10 | |
| 9.0.0-next.3 | 6.0.0-next.3 | 6.0.0-next.3 | 10.0.1 | 1.94.1 | 0.52.0 | 2024-10-10 | |
| 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
650 changes: 325 additions & 325 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"devDependencies": {
"@codingame/esbuild-import-meta-url-plugin": "~1.0.2",
"@codingame/monaco-vscode-rollup-vsix-plugin": "~10.0.1",
"@codingame/monaco-vscode-rollup-vsix-plugin": "~10.0.2",
"@testing-library/react": "~16.0.1",
"@types/node": "~20.16.11",
"@types/react": "~18.3.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

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

## [9.0.0-next.2] - 2024-10-10
## [9.0.0-next.3] - 2024-10-11

- 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 `10.0.1`.
- Updated all `@codingame/monaco-vscode` packages to `10.0.2`.
- Enhancements to logging
- monaco-languageclient config improvement, wrapper+languageclientwrapper improvements [#741](https://github.com/TypeFox/monaco-languageclient/pull/741)
- Pass MessageTransports directly
Expand Down
20 changes: 10 additions & 10 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.2",
"version": "9.0.0-next.3",
"description": "Monaco Language client implementation",
"author": {
"name": "TypeFox GmbH",
Expand Down Expand Up @@ -62,18 +62,18 @@
"LICENSE"
],
"dependencies": {
"@codingame/monaco-vscode-extensions-service-override": "~10.0.1",
"@codingame/monaco-vscode-languages-service-override": "~10.0.1",
"@codingame/monaco-vscode-localization-service-override": "~10.0.1",
"@codingame/monaco-vscode-log-service-override": "~10.0.1",
"@codingame/monaco-vscode-model-service-override": "~10.0.1",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.1",
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.1",
"@codingame/monaco-vscode-extensions-service-override": "~10.0.2",
"@codingame/monaco-vscode-languages-service-override": "~10.0.2",
"@codingame/monaco-vscode-localization-service-override": "~10.0.2",
"@codingame/monaco-vscode-log-service-override": "~10.0.2",
"@codingame/monaco-vscode-model-service-override": "~10.0.2",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.2",
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.2",
"vscode-languageclient": "~9.0.1"
},
"peerDependencies": {
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.1",
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.1"
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.2",
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.2"
},
"peerDependenciesMeta": {
"monaco-editor": {
Expand Down
6 changes: 5 additions & 1 deletion packages/examples/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

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

## [2024.10.2] - 20241-10-11

- Updated to `[email protected]`, `[email protected]` and `@typefox/[email protected]`. Updated all `@codingame/monaco-vscode` packages to `10.0.2`.

## [2024.10.1] - 20241-10-10

- Updated to `[email protected]`, `[email protected]` and `@typefox/[email protected]`. Updated all `@codingame/monaco-vscode` packages to `10.0.2`.
- Aligend example config. `htmlContainer` is now a required property of `editorAppConfig`
- Fixed problems with Statemachine example (two editor and react version)
- Json example exports a function for the configuration

## [2024.9.1] - 2024-09-27

- Updated to `[email protected]`, `[email protected]` and `@typefox/[email protected]`. Updated all `@codingame/monaco-vscode` packages to `10.0.1`.
- 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
48 changes: 24 additions & 24 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monaco-languageclient-examples",
"version": "2024.10.1",
"version": "2024.10.2",
"description": "Monaco Language client examples",
"author": {
"name": "TypeFox GmbH",
Expand Down Expand Up @@ -54,35 +54,35 @@
}
},
"dependencies": {
"@codingame/monaco-vscode-configuration-service-override": "~10.0.1",
"@codingame/monaco-vscode-files-service-override": "~10.0.1",
"@codingame/monaco-vscode-groovy-default-extension": "~10.0.1",
"@codingame/monaco-vscode-keybindings-service-override": "~10.0.1",
"@codingame/monaco-vscode-lifecycle-service-override": "~10.0.1",
"@codingame/monaco-vscode-localization-service-override": "~10.0.1",
"@codingame/monaco-vscode-java-default-extension": "~10.0.1",
"@codingame/monaco-vscode-javascript-default-extension": "~10.0.1",
"@codingame/monaco-vscode-json-default-extension": "~10.0.1",
"@codingame/monaco-vscode-python-default-extension": "~10.0.1",
"@codingame/monaco-vscode-standalone-languages": "~10.0.1",
"@codingame/monaco-vscode-standalone-typescript-language-features": "~10.0.1",
"@codingame/monaco-vscode-standalone-json-language-features": "~10.0.1",
"@codingame/monaco-vscode-textmate-service-override": "~10.0.1",
"@codingame/monaco-vscode-theme-defaults-default-extension": "~10.0.1",
"@codingame/monaco-vscode-theme-service-override": "~10.0.1",
"@codingame/monaco-vscode-typescript-basics-default-extension": "~10.0.1",
"@codingame/monaco-vscode-typescript-language-features-default-extension": "~10.0.1",
"@typefox/monaco-editor-react": "~6.0.0-next.2",
"@codingame/monaco-vscode-configuration-service-override": "~10.0.2",
"@codingame/monaco-vscode-files-service-override": "~10.0.2",
"@codingame/monaco-vscode-groovy-default-extension": "~10.0.2",
"@codingame/monaco-vscode-keybindings-service-override": "~10.0.2",
"@codingame/monaco-vscode-lifecycle-service-override": "~10.0.2",
"@codingame/monaco-vscode-localization-service-override": "~10.0.2",
"@codingame/monaco-vscode-java-default-extension": "~10.0.2",
"@codingame/monaco-vscode-javascript-default-extension": "~10.0.2",
"@codingame/monaco-vscode-json-default-extension": "~10.0.2",
"@codingame/monaco-vscode-python-default-extension": "~10.0.2",
"@codingame/monaco-vscode-standalone-languages": "~10.0.2",
"@codingame/monaco-vscode-standalone-typescript-language-features": "~10.0.2",
"@codingame/monaco-vscode-standalone-json-language-features": "~10.0.2",
"@codingame/monaco-vscode-textmate-service-override": "~10.0.2",
"@codingame/monaco-vscode-theme-defaults-default-extension": "~10.0.2",
"@codingame/monaco-vscode-theme-service-override": "~10.0.2",
"@codingame/monaco-vscode-typescript-basics-default-extension": "~10.0.2",
"@codingame/monaco-vscode-typescript-language-features-default-extension": "~10.0.2",
"@typefox/monaco-editor-react": "~6.0.09.0.0-next.3",
"express": "~4.21.1",
"langium": "~3.2.0",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.1",
"monaco-editor-wrapper": "~6.0.0-next.2",
"monaco-languageclient": "~9.0.0-next.2",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.2",
"monaco-editor-wrapper": "~6.0.09.0.0-next.3",
"monaco-languageclient": "~9.0.09.0.0-next.3",
"pyright": "~1.1.384",
"react": "~18.3.1",
"react-dom": "~18.3.1",
"request-light": "~0.8.0",
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.1",
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.2",
"vscode-json-languageservice": "~5.4.1",
"vscode-languageclient": "~9.0.1",
"vscode-languageserver": "~9.0.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/src/python/client/reactPython.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import * as vscode from 'vscode';
import { RegisteredFileSystemProvider, registerFileSystemOverlay, RegisteredMemoryFile } from '@codingame/monaco-vscode-files-service-override';
import React, { StrictMode } from 'react';
import ReactDOM from 'react-dom/client';
import type { TextChanges } from '@typefox/monaco-editor-react';
import { MonacoEditorReactComp } from '@typefox/monaco-editor-react';
import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper';
import { MonacoEditorLanguageClientWrapper, TextChanges } from 'monaco-editor-wrapper';
import { createUserConfig } from './config.js';
import badPyCode from './bad.py?raw';

Expand Down
5 changes: 3 additions & 2 deletions packages/wrapper-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

All notable changes to npm module [@typefox/monaco-editor-react](https://www.npmjs.com/package/@typefox/monaco-editor-react) are documented in this file.

## [6.0.0-next.2] - 2024-10-10
## [6.0.0-next.3] - 2024-10-10

- Clean-up and allow registering a registerModelUpdate callback. This is used to properly handle `onTextChanged`
- Support all arguments for monaco-vscode-api `initialize` [#756](https://github.com/TypeFox/monaco-languageclient/pull/756)
- On startup the current containerRef is passed to the interal editor app/monaco-editor
- Update to monaco-vscode-api 9.0.x [#749](https://github.com/TypeFox/monaco-languageclient/pull/749)
- Updated to `[email protected].2` and `[email protected].2`. Updated all `@codingame/monaco-vscode` packages to `10.0.1`.
- Updated to `[email protected].3` and `[email protected].3`. Updated all `@codingame/monaco-vscode` packages to `10.0.2`.
- Enhancements to logging
- monaco-languageclient config improvement, wrapper+languageclientwrapper improvements [#741](https://github.com/TypeFox/monaco-languageclient/pull/741)
- Turned react component from class to function [#739](https://github.com/TypeFox/monaco-languageclient/pull/739)
Expand Down
18 changes: 9 additions & 9 deletions packages/wrapper-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typefox/monaco-editor-react",
"version": "6.0.0-next.2",
"version": "6.0.0-next.3",
"license": "MIT",
"description": "React component for Monaco-Editor and Monaco Languageclient",
"keywords": [
Expand Down Expand Up @@ -42,18 +42,18 @@
"npm": "10.8.3"
},
"dependencies": {
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.1",
"monaco-editor-wrapper": "~6.0.0-next.2",
"monaco-languageclient": "~9.0.0-next.2",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.2",
"monaco-editor-wrapper": "~6.0.0-next.3",
"monaco-languageclient": "~9.0.0-next.3",
"react": "~18.3.1",
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.1"
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.2"
},
"peerDependencies": {
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.1",
"monaco-editor-wrapper": "~6.0.0-next.2",
"monaco-languageclient": "~9.0.0-next.2",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.2",
"monaco-editor-wrapper": "~6.0.0-next.3",
"monaco-languageclient": "~9.0.0-next.3",
"react": "~18.3.1",
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.1"
"vscode": "npm:@codingame/monaco-vscode-api@~10.0.2"
},
"peerDependenciesMeta": {
"monaco-editor": {
Expand Down
75 changes: 37 additions & 38 deletions packages/wrapper-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

import * as monaco from 'monaco-editor';
import React, { CSSProperties, useCallback, useEffect, useRef, useState } from 'react';
import { MonacoEditorLanguageClientWrapper, TextContents, WrapperConfig } from 'monaco-editor-wrapper';

export type TextChanges = TextContents & {
isDirty: boolean;
}
import { MonacoEditorLanguageClientWrapper, TextChanges, TextModels, WrapperConfig } from 'monaco-editor-wrapper';

export type MonacoEditorProps = {
style?: CSSProperties;
Expand Down Expand Up @@ -80,6 +76,41 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
containerRef.current.className = className ?? '';
try {
wrapperRef.current.getMonacoEditorApp()?.updateHtmlContainer(containerRef.current);

wrapperRef.current.registerModelUpdate((textModels: TextModels) => {
if (textModels.text || textModels.textOriginal) {
const verifyModelContent = () => {
const text = textModels.text?.getValue() ?? '';
const textOriginal = textModels.textOriginal?.getValue() ?? '';
const codeResources = wrapperConfig.editorAppConfig.codeResources;
const dirty = text !== codeResources?.main?.text;
const dirtyOriginal = textOriginal !== codeResources?.original?.text;
onTextChanged?.({
text,
textOriginal,
isDirty: dirty || dirtyOriginal
});
};

const newSubscriptions: monaco.IDisposable[] = [];

if (textModels.text) {
newSubscriptions.push(textModels.text.onDidChangeContent(() => {
verifyModelContent();
}));
}

if (textModels.textOriginal) {
newSubscriptions.push(textModels.textOriginal.onDidChangeContent(() => {
verifyModelContent();
}));
}
setOnTextChangedSubscriptions(newSubscriptions);
// do it initially
verifyModelContent();
}
});

await wrapperRef.current.start();
onLoad?.(wrapperRef.current);
handleOnTextChanged();
Expand All @@ -93,45 +124,13 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
} else {
throw new Error('No htmlContainer found');
}
}, [className, onError, onLoad]);
}, [className, onError, onLoad, onTextChanged]);

const handleOnTextChanged = useCallback(() => {
disposeOnTextChanged();

if (!onTextChanged) return;

const textModels = wrapperRef.current.getTextModels();
if (textModels?.text || textModels?.textOriginal) {
const verifyModelContent = () => {
const text = textModels.text?.getValue() ?? '';
const textOriginal = textModels.textOriginal?.getValue() ?? '';
const codeResources = wrapperConfig.editorAppConfig.codeResources;
const dirty = text !== codeResources?.main?.text;
const dirtyOriginal = textOriginal !== codeResources?.original?.text;
onTextChanged({
text,
textOriginal,
isDirty: dirty || dirtyOriginal
});
};

const newSubscriptions: monaco.IDisposable[] = [];

if (textModels.text) {
newSubscriptions.push(textModels.text.onDidChangeContent(() => {
verifyModelContent();
}));
}

if (textModels.textOriginal) {
newSubscriptions.push(textModels.textOriginal.onDidChangeContent(() => {
verifyModelContent();
}));
}
setOnTextChangedSubscriptions(newSubscriptions);
// do it initially
verifyModelContent();
}
}, [onTextChanged, wrapperConfig]);

const destroyMonaco = useCallback(async () => {
Expand Down
Loading

0 comments on commit 834db30

Please sign in to comment.