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

Wrapper: Make codeResources and useDiffEditor optional in EditorAppConfig #670

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
],
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module'
sourceType: 'module',
project: ['./tsconfig.json']
},
plugins: [
'@typescript-eslint',
Expand Down Expand Up @@ -80,6 +81,8 @@ module.exports = {
'@typescript-eslint/prefer-for-of': 'error', // prefer for-of loop over arrays
'@typescript-eslint/prefer-namespace-keyword': 'error', // prefer namespace over module in TypeScript
'@typescript-eslint/triple-slash-reference': 'error', // ban /// <reference />, prefer imports
'@typescript-eslint/type-annotation-spacing': 'error' // consistent space around colon ':'
'@typescript-eslint/type-annotation-spacing': 'error', // consistent space around colon ':'
'@typescript-eslint/strict-boolean-expressions': 'error', // Disallow certain types in boolean expressions
'@typescript-eslint/no-unnecessary-condition': 'error' // Disallow conditionals where the type is always truthy or always falsy
}
};
620 changes: 308 additions & 312 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
"@codingame/esbuild-import-meta-url-plugin": "~1.0.2",
"@codingame/monaco-vscode-rollup-vsix-plugin": "~5.2.0",
"@rollup/pluginutils": "~5.1.0",
"@types/node": "~20.12.12",
"@types/node": "~20.14.1",
"@types/react": "~18.3.3",
"@types/react-dom": "~18.3.0",
"@types/vscode": "~1.89.0",
"@typescript-eslint/eslint-plugin": "~7.10.0",
"@typescript-eslint/parser": "~7.10.0",
"@typescript-eslint/eslint-plugin": "~7.12.0",
"@typescript-eslint/parser": "~7.12.0",
"@vitest/browser": "~1.6.0",
"editorconfig": "~2.0.0",
"esbuild": "~0.21.3",
"esbuild": "~0.21.4",
"eslint": "~8.57.0",
"eslint-plugin-header": "~3.1.1",
"eslint-plugin-import": "~2.29.1",
"eslint-plugin-unused-imports": "~3.2.0",
"minimatch": "~9.0.4",
"http-server": "~14.1.1",
"typescript": "~5.4.5",
"vite": "~5.2.11",
"vite": "~5.2.12",
"vitest": "~1.6.0",
"vite-node": "~1.6.0",
"webdriverio": "~8.37.0"
"webdriverio": "~8.38.2"
},
"volta": {
"node": "20.13.1",
"npm": "10.5.2"
"node": "20.14.0",
"npm": "10.7.0"
},
"scripts": {
"clean": "npm run clean --workspaces",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"npm": ">=9.0.0"
},
"volta": {
"node": "20.13.1",
"npm": "10.5.2"
"node": "20.14.0",
"npm": "10.7.0"
},
"files": [
"lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class MonacoLanguageClient extends BaseLanguageClient {
protected readonly connectionProvider: IConnectionProvider;

constructor({ id, name, clientOptions, connectionProvider }: MonacoLanguageClientOptions) {
super(id || name.toLowerCase(), name, clientOptions);
super((id ?? 'unknown-id') || name.toLowerCase(), name, clientOptions);
kaisalmen marked this conversation as resolved.
Show resolved Hide resolved
this.connectionProvider = connectionProvider;
}

Expand Down
12 changes: 5 additions & 7 deletions packages/client/src/vscode/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as monaco from 'monaco-editor';
import 'vscode/localExtensionHost';
import { ILogService, initialize, IWorkbenchConstructionOptions, StandaloneServices } from 'vscode/services';
import { ILogService, initialize, IWorkbenchConstructionOptions, LogLevel, StandaloneServices } 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';
Expand Down Expand Up @@ -79,8 +79,8 @@ export const initServices = async (instruction: InitServicesInstruction) => {
});
}

if (!envEnhanced.vscodeInitialising) {
if (envEnhanced.vscodeApiInitialised) {
if (!(envEnhanced.vscodeInitialising ?? false)) {
if (envEnhanced.vscodeApiInitialised ?? false) {
instruction.logger?.debug('Initialization of vscode services can only performed once!');
} else {
envEnhanced.vscodeInitialising = true;
Expand Down Expand Up @@ -118,10 +118,8 @@ export const importAllServices = async (instruction: InitServicesInstruction) =>

if (instruction.performChecks === undefined || instruction.performChecks()) {
await initialize(userServices);
const logLevel = lc.workspaceConfig?.developmentOptions?.logLevel;
if (logLevel) {
StandaloneServices.get(ILogService).setLevel(logLevel);
}
const logLevel = lc.workspaceConfig?.developmentOptions?.logLevel ?? LogLevel.Info;
StandaloneServices.get(ILogService).setLevel(logLevel);
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/examples/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## [2024.5.2x] - 2024-05-2x
## [2024.6.x] - 2024-06-0x

- Updated to `monaco-languageclient@8.5.0`, `monaco-editor-wrapper@5.2.0` and `@typefox/monaco-editor-react@4.2.0`. Updated all `@codingame/monaco-vscode` packages to `5.2.0`.

Expand Down
8 changes: 4 additions & 4 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.5.2x",
"version": "2024.6.x",
"description": "Monaco Language client examples",
"author": {
"name": "TypeFox GmbH",
Expand Down Expand Up @@ -77,7 +77,7 @@
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~5.2.0",
"monaco-editor-wrapper": "~5.2.0",
"monaco-languageclient": "~8.5.0",
"pyright": "~1.1.364",
"pyright": "~1.1.365",
"react": "~18.3.1",
"react-dom": "~18.3.1",
"request-light": "~0.7.0",
Expand All @@ -97,8 +97,8 @@
"vscode-languageserver-types": "~3.17.5"
},
"volta": {
"node": "20.13.1",
"npm": "10.5.2"
"node": "20.14.0",
"npm": "10.7.0"
},
"files": [
"dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const runLanguageServer = (
) => {
process.on('uncaughtException', err => {
console.error('Uncaught Exception: ', err.toString());
if (err.stack) {
if (err.stack !== undefined) {
console.error(err.stack);
}
});
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 @@ -40,7 +40,7 @@
const writer = new WebSocketMessageWriter(socket);
const socketConnection = createConnection(reader, writer, () => socket.dispose());
const serverConnection = createServerProcess(serverName, runCommand, runCommandArgs, spawnOptions);
if (serverConnection) {

Check failure on line 43 in packages/examples/src/common/node/server-commons.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required

Check failure on line 43 in packages/examples/src/common/node/server-commons.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required
forward(socketConnection, serverConnection, message => {
if (Message.isRequest(message)) {
console.log(`${serverName} Server received:`);
Expand All @@ -66,7 +66,7 @@
}) => {
config.server.on('upgrade', (request: IncomingMessage, socket: Socket, head: Buffer) => {
const baseURL = `http://${request.headers.host}/`;
const pathName = request.url ? new URL(request.url, baseURL).pathname : undefined;
const pathName = request.url !== undefined ? new URL(request.url, baseURL).pathname : undefined;
if (pathName === runconfig.pathName) {
config.wss.handleUpgrade(request, socket, head, webSocket => {
const socket: IWebSocket = {
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/src/groovy/server/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getLocalDirectory } from '../../common/node/server-commons.js';

const baseDir = resolve(getLocalDirectory(import.meta.url));
const groovyJar = resolve(baseDir, '../../../resources/groovy/external/groovy-language-server-all.jar');
const relativeDir = process.env.LANG_SERVER_JAR_PATH || groovyJar;
const relativeDir = process.env.LANG_SERVER_JAR_PATH ?? groovyJar;
console.log(`basedir: ${baseDir}`);
console.log(`groovyJar: ${groovyJar}`);
console.log(`LANG_SERVER_JAR_PATH: ${process.env.LANG_SERVER_JAR_PATH}`);
Expand Down
6 changes: 3 additions & 3 deletions packages/examples/src/json/server/json-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export class JsonServer {
});

this.connection.onInitialize(params => {
if (params.rootPath) {
if (params.rootPath !== null && params.rootPath !== undefined) {
this.workspaceRoot = URI.URI.file(params.rootPath);
} else if (params.rootUri) {
} else if (params.rootUri !== null) {
this.workspaceRoot = URI.URI.parse(params.rootUri);
}
this.connection.console.log('The server is initialized.');
Expand Down Expand Up @@ -200,7 +200,7 @@ export class JsonServer {
return response.responseText;
} catch (error: unknown) {
const err = error as Record<string, unknown>;
return Promise.reject(err.responseText || requestLight.getErrorStatusDescription(err.status as number) || err.toString());
return Promise.reject(err.responseText !== undefined || requestLight.getErrorStatusDescription(err.status as number) || err.toString());
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/langium/langium-dsl/wrapperLangium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@
};

const checkStarted = () => {
if (wrapper?.isStarted()) {
if (wrapper?.isStarted() ?? false) {

Check failure on line 63 in packages/examples/src/langium/langium-dsl/wrapperLangium.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required

Check failure on line 63 in packages/examples/src/langium/langium-dsl/wrapperLangium.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required
alert('Editor was already started!\nPlease reload the page to test the alternative editor.');
return true;
}
return false;
};

const disableButton = (id: string, disabled: boolean) => {
const button = document.getElementById(id) as HTMLButtonElement;
const button = document.getElementById(id) as HTMLButtonElement | null;
if (button !== null) {
button.disabled = disabled;
}
};

export const disposeEditor = async () => {
if (!wrapper) return;

Check failure on line 78 in packages/examples/src/langium/langium-dsl/wrapperLangium.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required

Check failure on line 78 in packages/examples/src/langium/langium-dsl/wrapperLangium.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required
wrapper.reportStatus();
await wrapper.dispose();
wrapper = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const createLangiumGlobalConfig = async (params: {
extensionFilesOrContents.set(`/${params.languageServerId}-statemachine-grammar.json`, responseStatemachineTm);

let main;
if (params.text) {
if (params.text !== undefined) {
main = {
text: params.text,
fileExt: 'statemachine'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ declare const self: DedicatedWorkerGlobalScope;
self.onmessage = async (event: MessageEvent) => {
const data = event.data;
console.log(event.data);
if (data.port) {
if (data.port !== undefined) {
start(data.port, 'statemachine-server-port');

messageReader?.listen((message) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/src/python/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const runPythonServer = (baseDir: string, relativeDir: string) => {
clientInfo: { origin: string; secure: boolean; req: IncomingMessage },
callback
) => {
const parsedURL = new URL(`${clientInfo.origin}${clientInfo.req?.url ?? ''}`);
const parsedURL = new URL(`${clientInfo.origin}${clientInfo.req.url ?? ''}`);
const authToken = parsedURL.searchParams.get('authorization');
if (authToken === 'UserAuth') {
callback(true);
Expand Down
4 changes: 3 additions & 1 deletion packages/examples/src/ts/wrapperTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
}
});
document.querySelector('#button-diff')?.addEventListener('click', async () => {
userConfig.wrapperConfig.editorAppConfig.useDiffEditor = !userConfig.wrapperConfig.editorAppConfig.useDiffEditor;
// ensure it is boolean value and not undefined
const useDiffEditor = userConfig.wrapperConfig.editorAppConfig.useDiffEditor ?? false;
userConfig.wrapperConfig.editorAppConfig.useDiffEditor = !useDiffEditor;

Check failure on line 125 in packages/examples/src/ts/wrapperTs.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required

Check failure on line 125 in packages/examples/src/ts/wrapperTs.ts

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required
await wrapper.dispose();
await wrapper.initAndStart(userConfig, htmlElement);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-ws-jsonrpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"npm": ">=8.0.0"
},
"volta": {
"node": "20.13.1",
"npm": "10.5.2"
"node": "20.14.0",
"npm": "10.7.0"
},
"files": [
"lib",
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-ws-jsonrpc/src/socket/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class WebSocketMessageReader extends AbstractMessageReader implements Mes
this.callback = callback;
while (this.events.length !== 0) {
const event = this.events.pop()!;
if (event.message) {
if (event.message !== undefined) {
this.readMessage(event.message);
} else if (event.error) {
} else if (event.error !== undefined) {
this.fireError(event.error);
} else {
this.fireClose();
Expand Down
4 changes: 2 additions & 2 deletions packages/wrapper-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"build": "npm run clean && npm run compile"
},
"volta": {
"node": "20.13.1",
"npm": "10.5.2"
"node": "20.14.0",
"npm": "10.7.0"
},
"dependencies": {
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~5.2.0",
Expand Down
13 changes: 7 additions & 6 deletions packages/wrapper-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

const mustReInit = this.isReInitRequired(prevProps);

if (mustReInit) {

Check failure on line 57 in packages/wrapper-react/src/index.tsx

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required

Check failure on line 57 in packages/wrapper-react/src/index.tsx

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required
await this.handleReinit();
} else {
// the function now ensure a model update is only required if something else than the code changed
Expand Down Expand Up @@ -113,7 +113,7 @@
}

protected async destroyMonaco(): Promise<void> {
if (this.wrapper.isInitDone()) {

Check failure on line 116 in packages/wrapper-react/src/index.tsx

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required

Check failure on line 116 in packages/wrapper-react/src/index.tsx

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required
if (this.isRestarting) {
await this.isRestarting;
}
Expand Down Expand Up @@ -177,26 +177,27 @@
if (!onTextChanged) return;

const textModels = this.wrapper.getTextModels();
if (textModels?.text || textModels?.textOriginal) {

Check failure on line 180 in packages/wrapper-react/src/index.tsx

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required

Check failure on line 180 in packages/wrapper-react/src/index.tsx

View workflow job for this annotation

GitHub Actions / monaco-languageclient

Unexpected any value in conditional. An explicit comparison or type cast is required
const verifyModelContent = () => {
const main = textModels?.text?.getValue() ?? '';
const original = textModels?.textOriginal?.getValue() ?? '';
const dirty = main !== userConfig.wrapperConfig.editorAppConfig.codeResources.main?.text ?? '';
const dirtyOriginal = original !== userConfig.wrapperConfig.editorAppConfig.codeResources.original?.text ?? '';
const main = textModels.text?.getValue() ?? '';
const original = textModels.textOriginal?.getValue() ?? '';
const codeResources = userConfig.wrapperConfig.editorAppConfig.codeResources;
const dirty = main !== codeResources?.main?.text;
const dirtyOriginal = original !== codeResources?.original?.text;
onTextChanged({
main,
original,
isDirty: dirty || dirtyOriginal
});
};

if (textModels?.text) {
if (textModels.text) {
this._subscriptions.push(textModels.text.onDidChangeContent(() => {
verifyModelContent();
}));
}

if (textModels?.textOriginal) {
if (textModels.textOriginal) {
this._subscriptions.push(textModels.textOriginal.onDidChangeContent(() => {
verifyModelContent();
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
"build": "npm run clean && npm run compile && npm run build:workers:esbuild && npm run build:workers:vite"
},
"volta": {
"node": "20.13.1",
"npm": "10.5.2"
"node": "20.14.0",
"npm": "10.7.0"
},
"dependencies": {
"@codingame/monaco-vscode-configuration-service-override": "~5.2.0",
Expand Down
Loading
Loading