From a9d5f351c7828f2f187587abbb84f6c31c39ae28 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Thu, 12 Dec 2024 09:52:24 +0100 Subject: [PATCH 01/15] Packages --- packages/cors-proxy/package.json | 2 +- packages/extended-services-vscode-extension/package.json | 9 +++++---- packages/kie-sandbox-distribution/package.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/cors-proxy/package.json b/packages/cors-proxy/package.json index 2ac6327c043..dd2be835947 100644 --- a/packages/cors-proxy/package.json +++ b/packages/cors-proxy/package.json @@ -28,7 +28,7 @@ "dependencies": { "cors": "^2.8.5", "express": "^4.21.1", - "node-fetch": "^3.3.1" + "node-fetch": "^3.3.2" }, "devDependencies": { "@babel/core": "^7.16.0", diff --git a/packages/extended-services-vscode-extension/package.json b/packages/extended-services-vscode-extension/package.json index 824e46cb458..be6c3b96bb1 100644 --- a/packages/extended-services-vscode-extension/package.json +++ b/packages/extended-services-vscode-extension/package.json @@ -43,7 +43,7 @@ "@vscode/test-web": "^0.0.30", "@vscode/vsce": "^2.22.0", "copy-webpack-plugin": "^11.0.0", - "node-fetch": "^3.3.1", + "node-fetch": "^3.3.2", "rimraf": "^3.0.2", "webpack": "^5.94.0", "webpack-cli": "^4.10.0", @@ -74,21 +74,22 @@ "configuration": { "properties": { "extendedServices.connectionHeartbeatIntervalinSecs": { - "default": 1, + "default": 10, "description": "Specifies the interval (in seconds) between each connection check.", "format": "time", + "minimum": 10, "order": 2, "type": "integer" }, "extendedServices.enableAutorun": { "default": true, - "description": "Automatically run a local instance of the service.", + "description": "Automatically runs a local instance of the Extended Service.", "order": 0, "type": "boolean" }, "extendedServices.extendedServicesURL": { "default": "http://localhost:21345", - "description": "Specifies the Exnteded Services URL.", + "description": "Specifies the Extended Services URL.", "format": "uri", "order": 1, "type": "string" diff --git a/packages/kie-sandbox-distribution/package.json b/packages/kie-sandbox-distribution/package.json index 7337835482a..f5fc7882bec 100644 --- a/packages/kie-sandbox-distribution/package.json +++ b/packages/kie-sandbox-distribution/package.json @@ -37,7 +37,7 @@ "@types/jest": "^29.5.12", "jest": "^29.7.0", "jest-junit": "^16.0.0", - "node-fetch": "^3.3.1", + "node-fetch": "^3.3.2", "rimraf": "^3.0.2", "run-script-os": "^1.1.6", "ts-jest": "^29.1.5", From bfd6f960daa63e4aae34544c7c2a3cc82fbadd54 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Thu, 12 Dec 2024 13:56:09 +0100 Subject: [PATCH 02/15] WIP --- .../src/Connection.ts | 1 + .../src/LocalExtendedServices.ts | 1 + .../src/Validator.ts | 18 ++-- .../src/configurations/Configuration.ts | 74 +++++----------- .../src/extension/extension-browser.ts | 76 ++++++++++------ .../src/extension/extension-main.ts | 88 +++++++++++++------ .../src/requests/PingRequest.ts | 1 + .../src/requests/ValidationRequests.ts | 41 ++++++--- 8 files changed, 170 insertions(+), 130 deletions(-) diff --git a/packages/extended-services-vscode-extension/src/Connection.ts b/packages/extended-services-vscode-extension/src/Connection.ts index 0984a04f05c..dc39250f43a 100644 --- a/packages/extended-services-vscode-extension/src/Connection.ts +++ b/packages/extended-services-vscode-extension/src/Connection.ts @@ -35,6 +35,7 @@ export class Connection { } public stop(): void { + console.debug("[Extended Services Extension] Disconnecting from Extended Service"); if (this.timeout) { this.fireDisconnectedEvent(); clearInterval(this.timeout); diff --git a/packages/extended-services-vscode-extension/src/LocalExtendedServices.ts b/packages/extended-services-vscode-extension/src/LocalExtendedServices.ts index 090e3404ef4..e804db505c2 100644 --- a/packages/extended-services-vscode-extension/src/LocalExtendedServices.ts +++ b/packages/extended-services-vscode-extension/src/LocalExtendedServices.ts @@ -80,6 +80,7 @@ export class LocalExtendedServices { } public stop(): void { + console.debug("[Extended Services Extension] Stopping local instance of Extended Service"); if (!this.serviceProcess) { return; } diff --git a/packages/extended-services-vscode-extension/src/Validator.ts b/packages/extended-services-vscode-extension/src/Validator.ts index 501a8440d07..e92f3eda924 100644 --- a/packages/extended-services-vscode-extension/src/Validator.ts +++ b/packages/extended-services-vscode-extension/src/Validator.ts @@ -49,26 +49,32 @@ function createDMNDiagnostics(validationResponses: validationResponse.DMNValidat }); } -export async function validateBPMN(serviceURL: URL, kieFile: kieFile.KieFile): Promise { +export async function validateBPMN(serviceURL: URL, bpmnFile: kieFile.KieFile): Promise { try { const validationResponses: validationResponse.BPMNValidationResponse[] = await validationRequests.validateBPMN( serviceURL, - kieFile + bpmnFile ); return createBPMNDiagnostics(validationResponses); } catch (error) { - throw new Error("VALIDATE BPMN ERROR - " + error.message); + console.error("An error happened while trying to validate BPMN file: " + kieFile + " with error: " + error.message); + throw new Error( + "An error happened while trying to validate BPMN file: " + kieFile + " with error: " + error.message + ); } } -export async function validateDMN(serviceURL: URL, kieFile: kieFile.KieFile): Promise { +export async function validateDMN(serviceURL: URL, dmnFile: kieFile.KieFile): Promise { try { const validationResponses: validationResponse.DMNValidationResponse[] = await validationRequests.validateDMN( serviceURL, - kieFile + dmnFile ); return createDMNDiagnostics(validationResponses); } catch (error) { - throw new Error("VALIDATE DMN ERROR - " + error.message); + console.error("An error happened while trying to validate DMN file: " + kieFile + " with error: " + error.message); + throw new Error( + "An error happened while trying to validate DMN file: " + kieFile + " with error: " + error.message + ); } } diff --git a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts index 5beb698fa88..507aa8c045b 100644 --- a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts +++ b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts @@ -19,9 +19,10 @@ import * as vscode from "vscode"; -export const enableAutoRunID: string = "extendedServices.enableAutorun"; -export const connectionHeartbeatIntervalinSecsID: string = "extendedServices.connectionHeartbeatIntervalinSecs"; -export const extendedServicesURLID: string = "extendedServices.extendedServicesURL"; +export const enableAutoRunID = "extendedServices.enableAutorun"; +export const connectionHeartbeatIntervalinSecsID = "extendedServices.connectionHeartbeatIntervalinSecs"; +export const extendedServicesURLID = "extendedServices.extendedServicesURL"; +const defaultExtendedServicesURL = "http://localhost:21345"; export class Configuration { readonly enableAutoRun: boolean; @@ -35,65 +36,30 @@ export class Configuration { } } -function fetchEnableAutoRun(): boolean { - const enableAutoRun = vscode.workspace.getConfiguration().get(enableAutoRunID); - if (!enableAutoRun) { - throw new Error("Enable Auto Run configuration not found"); - } - return enableAutoRun; -} - -function fetchConnectionHeartbeatIntervalinSecs(): number { - const connectionHeartbeatIntervalinSecs = vscode.workspace - .getConfiguration() - .get(connectionHeartbeatIntervalinSecsID); - if (!connectionHeartbeatIntervalinSecs) { - throw new Error("Connection Heartbeat Interval configuration not found"); - } - - return connectionHeartbeatIntervalinSecs; -} - function fetchExtendedServicesURL(): URL { - const extendedServicesURL = vscode.workspace.getConfiguration().get(extendedServicesURLID); - if (!extendedServicesURL) { - throw new Error("Extended Services URL configuration not found"); - } - + const extendedServicesURL = getConfigurationPropertyValue(extendedServicesURLID, defaultExtendedServicesURL); try { return new URL(extendedServicesURL); } catch (error) { - throw new Error("Invalid service URL:" + error.message); + throw new Error("The provided Extended Services URL " + extendedServicesURL + " is invalid: " + error.message); } } -export function fetchConfiguration(): Configuration { - let errorMessages: string[] = []; - let enableAutoRun: any; - let connectionHeartbeatIntervalinSecs: any; - let extendedServicesURL: any; - - try { - enableAutoRun = fetchEnableAutoRun(); - } catch (error) { - errorMessages.push(error.message); - } - - try { - connectionHeartbeatIntervalinSecs = fetchConnectionHeartbeatIntervalinSecs(); - } catch (error) { - errorMessages.push(error.message); +const getConfigurationPropertyValue = (property: string, defaultValue: T): T => { + const value = vscode.workspace.getConfiguration().get(property) as T; + if (!value) { + console.warn("Property: " + property + " is missing, using the default: " + defaultValue); } + return value || defaultValue; +}; - try { - extendedServicesURL = fetchExtendedServicesURL(); - } catch (error) { - errorMessages.push(error.message); - } +export function fetchConfiguration(): Configuration { + const enableAutoRun = getConfigurationPropertyValue(enableAutoRunID, true); + const connectionHeartbeatIntervalinSecs = getConfigurationPropertyValue( + connectionHeartbeatIntervalinSecsID, + 10 + ); + const extendedServicesURL = fetchExtendedServicesURL(); - if (errorMessages.length < 0) { - throw new Error("CONFIGURATION ERROR - " + errorMessages.join(", ")); - } else { - return new Configuration(enableAutoRun, connectionHeartbeatIntervalinSecs, extendedServicesURL); - } + return new Configuration(enableAutoRun, connectionHeartbeatIntervalinSecs, extendedServicesURL); } diff --git a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts index eee98f3ea0a..9247ed12d85 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts @@ -67,29 +67,38 @@ function initializeVSCodeElements() { } function startExtendedServices(): void { + console.debug("[Extended Services Extension] Starting Extended Service"); try { - statusBarItem.show(); configuration = fetchConfiguration(); } catch (error) { - stopExtendedServices(); - vscode.window.showErrorMessage("An error happened while trying to start the Extended Services: " + error.message); + console.error("[Extended Services Extension] Extension configuration is wrong: " + error.message); + vscode.window.showErrorMessage( + "Extension configuration is wrong: " + error.message + " Please fix your local extension's setting" + ); return; } try { + console.debug( + "[Extended Services Extension] Connecting with the Extended Service located: " + configuration.extendedServicesURL + ); connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalinSecs); } catch (error) { stopExtendedServices(); - vscode.window.showErrorMessage("An error happened while trying to connect to the service:" + error.message); + console.error( + "[Extended Services Extension] An error happened while trying to start the local service:" + error.message + ); + vscode.window.showErrorMessage("An error happened while trying to start the local service:" + error.message); } } function stopExtendedServices() { + console.debug("[Extended Services Extension] Stopping Extended Service"); configuration = null; connection.stop(); } -async function validate(configuration: Configuration) { +async function validate(extendedServicesURL: URL) { diagnosticCollection.clear(); const bpmnFiles: KieFile[] = await kiefilesfetcher.findActiveKieFiles([kiefilesfetcher.bpmnDocumentFilter]); @@ -97,13 +106,16 @@ async function validate(configuration: Configuration) { for (const bpmnFile of bpmnFiles) { try { - const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateBPMN( - configuration.extendedServicesURL, - bpmnFile - ); + console.debug("[Extended Services Extension] Validating BPMN file: " + bpmnFile); + const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateBPMN(extendedServicesURL, bpmnFile); diagnosticCollection.set(bpmnFile.uri, bpmnDiagnostics); } catch (error) { - stopExtendedServices(); + console.error( + "[Extended Services Extension] An error happened while trying to validate " + + bpmnFile.uri.path + + ": " + + error.message + ); vscode.window.showErrorMessage( "An error happened while trying to validate " + bpmnFile.uri.path + ": " + error.message ); @@ -112,13 +124,16 @@ async function validate(configuration: Configuration) { for (const dmnFile of dmnFiles) { try { - const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateDMN( - configuration.extendedServicesURL, - dmnFile - ); - diagnosticCollection.set(dmnFile.uri, bpmnDiagnostics); + console.debug("[Extended Services Extension] Validating DMN file: " + dmnFile); + const dmnDiagnostics: vscode.Diagnostic[] = await validator.validateDMN(extendedServicesURL, dmnFile); + diagnosticCollection.set(dmnFile.uri, dmnDiagnostics); } catch (error) { - stopExtendedServices(); + console.error( + "[Extended Services Extension] An error happened while trying to validate " + + dmnFile.uri.path + + ": " + + error.message + ); vscode.window.showErrorMessage( "An error happened while trying to validate " + dmnFile.uri.path + ": " + error.message ); @@ -139,37 +154,41 @@ export function activate(context: vscode.ExtensionContext) { }); kieFilesWatcher.subscribeKieFilesOpened(() => { - statusBarItem.show(); - if (userDisconnected) { - return; - } - - if (configuration) { - validate(configuration); - } else { + console.debug( + "[Extended Services Extension] A KIE file has been opened. Current opened KIE files: " + + kieFilesWatcher.watchedKieFiles.length + ); + if (!userDisconnected && kieFilesWatcher.watchedKieFiles.length <= 1) { startExtendedServices(); + } else if (configuration) { + validate(configuration.extendedServicesURL); } }); kieFilesWatcher.subscribeKieFileChanged(() => { + console.debug("[Extended Services Extension] A KIE file has been changed"); if (configuration) { - validate(configuration); + validate(configuration.extendedServicesURL); } }); kieFilesWatcher.subscribeKieFilesClosed(() => { + console.debug( + "[Extended Services Extension] A KIE file has been closed. Current opened KIE files: " + + kieFilesWatcher.watchedKieFiles.length + ); if (kieFilesWatcher.watchedKieFiles.length === 0) { stopExtendedServices(); - statusBarItem.hide(); } else if (configuration) { - validate(configuration); + validate(configuration.extendedServicesURL); } }); connection.subscribeConnected(() => { + statusBarItem.show(); vscode.commands.executeCommand("setContext", connectedEnablementUID, true); if (configuration) { - validate(configuration); + validate(configuration.extendedServicesURL); statusBarItem.text = "$(extended-services-connected)"; statusBarItem.tooltip = "Apache KIE Extended Services are connected. Click to disconnect."; statusBarItem.command = stopExtendedServicesCommandUID; @@ -178,6 +197,7 @@ export function activate(context: vscode.ExtensionContext) { connection.subscribeConnectionLost((errorMessage: string) => { vscode.window.showErrorMessage("Connection error: " + errorMessage); + statusBarItem.hide(); stopExtendedServices(); }); diff --git a/packages/extended-services-vscode-extension/src/extension/extension-main.ts b/packages/extended-services-vscode-extension/src/extension/extension-main.ts index ea25c14f787..6221a1bef60 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-main.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-main.ts @@ -71,14 +71,16 @@ function initializeVSCodeElements() { } function startExtendedServices(context: vscode.ExtensionContext): void { - let config: Configuration; + console.debug("[Extended Services Extension] Starting Extended Service"); + statusBarItem.command = undefined; try { - statusBarItem.command = undefined; - statusBarItem.show(); configuration = fetchConfiguration(); } catch (error) { - stopExtendedServices(null); - vscode.window.showErrorMessage("An error happened while trying to start the Extended Services: " + error.message); + console.error("[Extended Services Extension] Extension configuration is wrong: " + error.message); + vscode.window.showErrorMessage( + "Extension configuration is wrong: " + error.message + " Please fix your local extension's setting" + ); + statusBarItem.hide(); return; } @@ -90,6 +92,7 @@ function startExtendedServices(context: vscode.ExtensionContext): void { } function stopExtendedServices(configuration: Configuration | null) { + console.debug("[Extended Services Extension] Stopping Extended Service"); statusBarItem.command = undefined; if (configuration?.enableAutoRun) { localService.stop(); @@ -99,24 +102,39 @@ function stopExtendedServices(configuration: Configuration | null) { } function startLocalExtendedServices(configuration: Configuration, context: vscode.ExtensionContext): void { + console.debug("[Extended Services Extension] Starting a Local Extended Service process"); try { localService.start(configuration.extendedServicesURL, context.extensionPath); } catch (error) { stopExtendedServices(configuration); - vscode.window.showErrorMessage("An error happened while trying to start the local service:" + error.message); + console.error( + "[Extended Services Extension] An error happened while trying to start the Local Extended Service process:" + + error.message + ); + vscode.window.showErrorMessage( + "An error happened while trying to start the Local Extended Service process:" + error.message + ); } } function startConnection(configuration: Configuration) { + console.debug( + "[Extended Services Extension] Connecting with the Extended Service located: " + configuration.extendedServicesURL + ); try { connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalinSecs); } catch (error) { stopExtendedServices(configuration); + console.error( + "[Extended Services Extension] An error happened while trying to connect to the service:" + error.message + ); vscode.window.showErrorMessage("An error happened while trying to connect to the service:" + error.message); } } -async function validate(configuration: Configuration) { +async function validate(extendedServicesURL: URL) { + console.debug("[Extended Services Extension] Validating the opened KIE files"); + diagnosticCollection.clear(); const bpmnFiles: KieFile[] = await kiefilesfetcher.findActiveKieFiles([kiefilesfetcher.bpmnDocumentFilter]); @@ -124,12 +142,16 @@ async function validate(configuration: Configuration) { for (const bpmnFile of bpmnFiles) { try { - const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateBPMN( - configuration.extendedServicesURL, - bpmnFile - ); + console.debug("[Extended Services Extension] Validating BPMN file: " + bpmnFile); + const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateBPMN(extendedServicesURL, bpmnFile); diagnosticCollection.set(bpmnFile.uri, bpmnDiagnostics); } catch (error) { + console.error( + "[Extended Services Extension] An error happened while trying to validate " + + bpmnFile.uri.path + + ": " + + error.message + ); vscode.window.showErrorMessage( "An error happened while trying to validate " + bpmnFile.uri.path + ": " + error.message ); @@ -138,13 +160,16 @@ async function validate(configuration: Configuration) { for (const dmnFile of dmnFiles) { try { - const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateDMN( - configuration.extendedServicesURL, - dmnFile - ); - diagnosticCollection.set(dmnFile.uri, bpmnDiagnostics); + console.debug("[Extended Services Extension] Validating DMN file: " + dmnFile); + const dmnDiagnostics: vscode.Diagnostic[] = await validator.validateDMN(extendedServicesURL, dmnFile); + diagnosticCollection.set(dmnFile.uri, dmnDiagnostics); } catch (error) { - stopExtendedServices(configuration); + console.error( + "[Extended Services Extension] An error happened while trying to validate " + + dmnFile.uri.path + + ": " + + error.message + ); vscode.window.showErrorMessage( "An error happened while trying to validate " + dmnFile.uri.path + ": " + error.message ); @@ -166,30 +191,33 @@ export function activate(context: vscode.ExtensionContext) { }); kieFilesWatcher.subscribeKieFilesOpened(() => { - statusBarItem.show(); - if (userDisconnected) { - return; - } - - if (configuration) { - validate(configuration); - } else { + console.debug( + "[Extended Services Extension] A KIE file has been opened. Current opened KIE files: " + + kieFilesWatcher.watchedKieFiles.length + ); + if (!userDisconnected && kieFilesWatcher.watchedKieFiles.length <= 1) { startExtendedServices(context); + } else if (configuration) { + validate(configuration.extendedServicesURL); } }); kieFilesWatcher.subscribeKieFileChanged(() => { + console.debug("[Extended Services Extension] A KIE file has been changed"); if (configuration) { - validate(configuration); + validate(configuration.extendedServicesURL); } }); kieFilesWatcher.subscribeKieFilesClosed(() => { + console.debug( + "[Extended Services Extension] A KIE file has been closed. Current opened KIE files: " + + kieFilesWatcher.watchedKieFiles.length + ); if (kieFilesWatcher.watchedKieFiles.length === 0) { stopExtendedServices(configuration); - statusBarItem.hide(); } else if (configuration) { - validate(configuration); + validate(configuration.extendedServicesURL); } }); @@ -214,8 +242,9 @@ export function activate(context: vscode.ExtensionContext) { connection.subscribeConnected(() => { vscode.commands.executeCommand("setContext", connectedEnablementUID, true); + statusBarItem.show(); if (configuration) { - validate(configuration); + validate(configuration.extendedServicesURL); statusBarItem.text = "$(extended-services-connected)"; statusBarItem.tooltip = "Apache KIE Extended Services are connected. Click to disconnect."; statusBarItem.command = stopExtendedServicesCommandUID; @@ -223,6 +252,7 @@ export function activate(context: vscode.ExtensionContext) { }); connection.subscribeConnectionLost((errorMessage: string) => { + statusBarItem.hide(); stopExtendedServices(configuration); vscode.window.showErrorMessage("Connection error: " + errorMessage); }); diff --git a/packages/extended-services-vscode-extension/src/requests/PingRequest.ts b/packages/extended-services-vscode-extension/src/requests/PingRequest.ts index 0e26fd641ca..4dfc74d85ad 100644 --- a/packages/extended-services-vscode-extension/src/requests/PingRequest.ts +++ b/packages/extended-services-vscode-extension/src/requests/PingRequest.ts @@ -23,6 +23,7 @@ export async function ping(extendedServicesURL: URL): Promise ({ + URI: document.fileName, + content: document.getText(), + })), }; return JSON.stringify(body); @@ -56,12 +54,13 @@ async function validate( textDocument = await vscode.workspace.openTextDocument(kieFile.uri); } const url = new URL(endpoint, serviceURL); + console.debug("[Extended Services Extension] Fetching " + url.toString()); const response = await fetch(url.toString(), { method: "POST", headers: { "Content-Type": "application/json", }, - body: buildRequestBody(textDocument), + body: buildMultipleResourcesPayload(textDocument.fileName, [textDocument]), }); const responseData: any = await response.json(); @@ -75,6 +74,14 @@ export async function validateBPMN( try { return validate(serviceURL, kieFile, "/jitbpmn/validate", validationresponse.parseBPMNValidationResponse); } catch (error) { + console.error( + "[Extended Services Extension] An error happened while trying to validate " + + kieFile + + " from serviceUrl " + + serviceURL + + ": " + + error + ); throw new Error("VALIDATE BPMN REQUEST ERROR: \n", error.message); } } @@ -86,6 +93,14 @@ export async function validateDMN( try { return validate(serviceURL, kieFile, "/jitdmn/validate", validationresponse.parseDMNValidationResponse); } catch (error) { + console.error( + "[Extended Services Extension] An error happened while trying to validate " + + kieFile + + " from serviceUrl " + + serviceURL + + ": " + + error + ); throw new Error("VALIDATE DMN REQUEST ERROR: \n", error.message); } } From 1e4cbdb950c719fe5e777f9725bc1aff65e1b3e0 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Thu, 12 Dec 2024 15:45:29 +0100 Subject: [PATCH 03/15] WIP --- .../src/extension/extension-browser.ts | 36 ++++++++++++------- .../src/extension/extension-main.ts | 34 ++++++++++++------ 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts index 9247ed12d85..1c7b52037a3 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts @@ -40,16 +40,19 @@ let kieFilesWatcher: KieFilesWatcher; let configurationWatcher: ConfigurationWatcher; let connection: Connection; -let userDisconnected: boolean = false; +/* Determines if the extension is corrected with the Extended Services Backend */ +let isConnected = false; +/* Determines the user explicitely disconnected the Extension from the Extended Services Backend */ +let disconnectedByUser: boolean = false; let configuration: Configuration | null = null; function initializeCommands(context: vscode.ExtensionContext) { connectExtendedServicesCommand = vscode.commands.registerCommand(startExtendedServicesCommandUID, () => { - userDisconnected = false; + disconnectedByUser = false; startExtendedServices(); }); disconnectExtendedServicesCommand = vscode.commands.registerCommand(stopExtendedServicesCommandUID, () => { - userDisconnected = true; + disconnectedByUser = true; stopExtendedServices(); }); } @@ -94,6 +97,8 @@ function startExtendedServices(): void { function stopExtendedServices() { console.debug("[Extended Services Extension] Stopping Extended Service"); + /* Invalidating immediatly the current connection, so any request coming when shutting down is not served */ + isConnected = false; configuration = null; connection.stop(); } @@ -106,7 +111,7 @@ async function validate(extendedServicesURL: URL) { for (const bpmnFile of bpmnFiles) { try { - console.debug("[Extended Services Extension] Validating BPMN file: " + bpmnFile); + console.debug("[Extended Services Extension] Validating BPMN file: " + bpmnFile.uri.path); const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateBPMN(extendedServicesURL, bpmnFile); diagnosticCollection.set(bpmnFile.uri, bpmnDiagnostics); } catch (error) { @@ -124,7 +129,7 @@ async function validate(extendedServicesURL: URL) { for (const dmnFile of dmnFiles) { try { - console.debug("[Extended Services Extension] Validating DMN file: " + dmnFile); + console.debug("[Extended Services Extension] Validating DMN file: " + dmnFile.uri.path); const dmnDiagnostics: vscode.Diagnostic[] = await validator.validateDMN(extendedServicesURL, dmnFile); diagnosticCollection.set(dmnFile.uri, dmnDiagnostics); } catch (error) { @@ -148,7 +153,7 @@ export function activate(context: vscode.ExtensionContext) { configurationWatcher.subscribeSettingsChanged(() => { stopExtendedServices(); - if (!userDisconnected && kieFilesWatcher.watchedKieFiles.length > 0) { + if (!disconnectedByUser && kieFilesWatcher.watchedKieFiles.length > 0) { startExtendedServices(); } }); @@ -158,16 +163,17 @@ export function activate(context: vscode.ExtensionContext) { "[Extended Services Extension] A KIE file has been opened. Current opened KIE files: " + kieFilesWatcher.watchedKieFiles.length ); - if (!userDisconnected && kieFilesWatcher.watchedKieFiles.length <= 1) { - startExtendedServices(); - } else if (configuration) { + if (!disconnectedByUser && isConnected && configuration) { validate(configuration.extendedServicesURL); } + if (!disconnectedByUser && !isConnected) { + startExtendedServices(); + } }); kieFilesWatcher.subscribeKieFileChanged(() => { console.debug("[Extended Services Extension] A KIE file has been changed"); - if (configuration) { + if (!disconnectedByUser && isConnected && configuration) { validate(configuration.extendedServicesURL); } }); @@ -185,8 +191,10 @@ export function activate(context: vscode.ExtensionContext) { }); connection.subscribeConnected(() => { - statusBarItem.show(); + console.debug("[Extended Services Extension] Connected with Extended Services"); + isConnected = true; vscode.commands.executeCommand("setContext", connectedEnablementUID, true); + statusBarItem.show(); if (configuration) { validate(configuration.extendedServicesURL); statusBarItem.text = "$(extended-services-connected)"; @@ -196,12 +204,16 @@ export function activate(context: vscode.ExtensionContext) { }); connection.subscribeConnectionLost((errorMessage: string) => { - vscode.window.showErrorMessage("Connection error: " + errorMessage); statusBarItem.hide(); stopExtendedServices(); + isConnected = false; + console.error("[Extended Services Extension] Connection lost with Extended Services"); + vscode.window.showErrorMessage("Connection error: " + errorMessage); }); connection.subscribeDisconnected(() => { + console.debug("[Extended Services Extension] Disconnected with Extended Services"); + isConnected = false; vscode.commands.executeCommand("setContext", connectedEnablementUID, false); statusBarItem.text = "$(extended-services-disconnected)"; statusBarItem.tooltip = "Apache KIE Extended Services are not connected. Click to connect."; diff --git a/packages/extended-services-vscode-extension/src/extension/extension-main.ts b/packages/extended-services-vscode-extension/src/extension/extension-main.ts index 6221a1bef60..740d9aa1422 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-main.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-main.ts @@ -43,16 +43,19 @@ let configurationWatcher: ConfigurationWatcher; let connection: Connection; let localService: LocalExtendedServices; -let userDisconnected: boolean = false; +/* Determines if the extension is corrected with the Extended Services Backend */ +let isConnected = false; +/* Determines the user explicitely disconnected the Extension from the Extended Services Backend */ +let disconnectedByUser: boolean = false; let configuration: Configuration | null; function initializeCommands(context: vscode.ExtensionContext) { connectExtendedServicesCommand = vscode.commands.registerCommand(startExtendedServicesCommandUID, () => { - userDisconnected = false; + disconnectedByUser = false; startExtendedServices(context); }); disconnectExtendedServicesCommand = vscode.commands.registerCommand(stopExtendedServicesCommandUID, () => { - userDisconnected = true; + disconnectedByUser = true; if (configuration) { stopExtendedServices(configuration); } @@ -93,6 +96,8 @@ function startExtendedServices(context: vscode.ExtensionContext): void { function stopExtendedServices(configuration: Configuration | null) { console.debug("[Extended Services Extension] Stopping Extended Service"); + /* Invalidating immediatly the current connection, so any request coming when shutting down is not served */ + isConnected = false; statusBarItem.command = undefined; if (configuration?.enableAutoRun) { localService.stop(); @@ -142,7 +147,7 @@ async function validate(extendedServicesURL: URL) { for (const bpmnFile of bpmnFiles) { try { - console.debug("[Extended Services Extension] Validating BPMN file: " + bpmnFile); + console.debug("[Extended Services Extension] Validating BPMN file: " + bpmnFile.uri.path); const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateBPMN(extendedServicesURL, bpmnFile); diagnosticCollection.set(bpmnFile.uri, bpmnDiagnostics); } catch (error) { @@ -160,7 +165,7 @@ async function validate(extendedServicesURL: URL) { for (const dmnFile of dmnFiles) { try { - console.debug("[Extended Services Extension] Validating DMN file: " + dmnFile); + console.debug("[Extended Services Extension] Validating DMN file: " + dmnFile.uri.path); const dmnDiagnostics: vscode.Diagnostic[] = await validator.validateDMN(extendedServicesURL, dmnFile); diagnosticCollection.set(dmnFile.uri, dmnDiagnostics); } catch (error) { @@ -185,7 +190,7 @@ export function activate(context: vscode.ExtensionContext) { configurationWatcher.subscribeSettingsChanged(() => { stopExtendedServices(configuration); - if (!userDisconnected && kieFilesWatcher.watchedKieFiles.length > 0) { + if (!disconnectedByUser && kieFilesWatcher.watchedKieFiles.length > 0) { startExtendedServices(context); } }); @@ -195,16 +200,17 @@ export function activate(context: vscode.ExtensionContext) { "[Extended Services Extension] A KIE file has been opened. Current opened KIE files: " + kieFilesWatcher.watchedKieFiles.length ); - if (!userDisconnected && kieFilesWatcher.watchedKieFiles.length <= 1) { - startExtendedServices(context); - } else if (configuration) { + if (!disconnectedByUser && isConnected && configuration) { validate(configuration.extendedServicesURL); } + if (!disconnectedByUser && !isConnected) { + startExtendedServices(context); + } }); kieFilesWatcher.subscribeKieFileChanged(() => { console.debug("[Extended Services Extension] A KIE file has been changed"); - if (configuration) { + if (!disconnectedByUser && isConnected && configuration) { validate(configuration.extendedServicesURL); } }); @@ -222,6 +228,7 @@ export function activate(context: vscode.ExtensionContext) { }); localService.subscribeLocalExtendedServicesStarted(() => { + console.debug("[Extended Services Extension] Local instance of Extended Services started"); if (configuration) { startConnection(configuration); } @@ -237,10 +244,13 @@ export function activate(context: vscode.ExtensionContext) { }); localService.subscribeLocalExtendedServicesStopped(() => { + console.debug("[Extended Services Extension] Local instance of Extended Services stopped"); connection.stop(); }); connection.subscribeConnected(() => { + console.debug("[Extended Services Extension] Connected with Extended Services"); + isConnected = true; vscode.commands.executeCommand("setContext", connectedEnablementUID, true); statusBarItem.show(); if (configuration) { @@ -254,10 +264,14 @@ export function activate(context: vscode.ExtensionContext) { connection.subscribeConnectionLost((errorMessage: string) => { statusBarItem.hide(); stopExtendedServices(configuration); + isConnected = false; + console.error("[Extended Services Extension] Connection lost with Extended Services"); vscode.window.showErrorMessage("Connection error: " + errorMessage); }); connection.subscribeDisconnected(() => { + console.debug("[Extended Services Extension] Disconnected with Extended Services"); + isConnected = false; vscode.commands.executeCommand("setContext", connectedEnablementUID, false); statusBarItem.text = "$(extended-services-disconnected)"; statusBarItem.tooltip = "Apache KIE Extended Services are not connected. Click to connect."; From a9970d389fc2252f2dab082dde8a63127c7baa76 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Thu, 12 Dec 2024 15:54:09 +0100 Subject: [PATCH 04/15] Fix --- .../src/extension/extension-browser.ts | 5 ----- .../src/extension/extension-main.ts | 5 ----- 2 files changed, 10 deletions(-) diff --git a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts index 1c7b52037a3..141fd515ef6 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts @@ -183,11 +183,6 @@ export function activate(context: vscode.ExtensionContext) { "[Extended Services Extension] A KIE file has been closed. Current opened KIE files: " + kieFilesWatcher.watchedKieFiles.length ); - if (kieFilesWatcher.watchedKieFiles.length === 0) { - stopExtendedServices(); - } else if (configuration) { - validate(configuration.extendedServicesURL); - } }); connection.subscribeConnected(() => { diff --git a/packages/extended-services-vscode-extension/src/extension/extension-main.ts b/packages/extended-services-vscode-extension/src/extension/extension-main.ts index 740d9aa1422..2bd7cdb7605 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-main.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-main.ts @@ -220,11 +220,6 @@ export function activate(context: vscode.ExtensionContext) { "[Extended Services Extension] A KIE file has been closed. Current opened KIE files: " + kieFilesWatcher.watchedKieFiles.length ); - if (kieFilesWatcher.watchedKieFiles.length === 0) { - stopExtendedServices(configuration); - } else if (configuration) { - validate(configuration.extendedServicesURL); - } }); localService.subscribeLocalExtendedServicesStarted(() => { From 497217fa061e5a1ae993d92b51c9d8a11b34c47a Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Thu, 12 Dec 2024 16:21:47 +0100 Subject: [PATCH 05/15] WIP --- pnpm-lock.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 202936059b5..d0986929c66 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2454,8 +2454,8 @@ importers: specifier: ^4.21.1 version: 4.21.1 node-fetch: - specifier: ^3.3.1 - version: 3.3.1 + specifier: ^3.3.2 + version: 3.3.2 devDependencies: '@babel/core': specifier: ^7.16.0 @@ -5356,8 +5356,8 @@ importers: specifier: ^11.0.0 version: 11.0.0(webpack@5.94.0(webpack-cli@4.10.0)) node-fetch: - specifier: ^3.3.1 - version: 3.3.1 + specifier: ^3.3.2 + version: 3.3.2 rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -7137,8 +7137,8 @@ importers: specifier: ^16.0.0 version: 16.0.0 node-fetch: - specifier: ^3.3.1 - version: 3.3.1 + specifier: ^3.3.2 + version: 3.3.2 rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -26889,8 +26889,8 @@ packages: resolution: {integrity: sha512-RdbZCEynH2tH46+tj0ua9caUHVWrd/RHnRfvly2EVdqGmI3ndS1Vn/xjm5KuGejDt2RNDQsVRLPNd2QPwcewVg==} engines: {node: ^10.17 || >=12.3} - node-fetch@3.3.1: - resolution: {integrity: sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==} + node-fetch@3.3.2: + resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} node-forge@1.3.1: @@ -53286,7 +53286,7 @@ snapshots: transitivePeerDependencies: - domexception - node-fetch@3.3.1: + node-fetch@3.3.2: dependencies: data-uri-to-buffer: 4.0.1 fetch-blob: 3.2.0 From 3260a41238ef83a68ab6b98132fb49c4c80c07d3 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Thu, 12 Dec 2024 22:47:12 +0100 Subject: [PATCH 06/15] CR request --- .../src/configurations/Configuration.ts | 5 +++-- .../src/requests/ValidationRequests.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts index 507aa8c045b..621557d3528 100644 --- a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts +++ b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts @@ -47,10 +47,11 @@ function fetchExtendedServicesURL(): URL { const getConfigurationPropertyValue = (property: string, defaultValue: T): T => { const value = vscode.workspace.getConfiguration().get(property) as T; - if (!value) { + if (value == null) { console.warn("Property: " + property + " is missing, using the default: " + defaultValue); + value == defaultValue; } - return value || defaultValue; + return value; }; export function fetchConfiguration(): Configuration { diff --git a/packages/extended-services-vscode-extension/src/requests/ValidationRequests.ts b/packages/extended-services-vscode-extension/src/requests/ValidationRequests.ts index 0d752644a69..cb6ada2de9e 100644 --- a/packages/extended-services-vscode-extension/src/requests/ValidationRequests.ts +++ b/packages/extended-services-vscode-extension/src/requests/ValidationRequests.ts @@ -69,14 +69,14 @@ async function validate( export async function validateBPMN( serviceURL: URL, - kieFile: kiefile.KieFile + bpmnFile: kiefile.KieFile ): Promise { try { - return validate(serviceURL, kieFile, "/jitbpmn/validate", validationresponse.parseBPMNValidationResponse); + return validate(serviceURL, bpmnFile, "/jitbpmn/validate", validationresponse.parseBPMNValidationResponse); } catch (error) { console.error( "[Extended Services Extension] An error happened while trying to validate " + - kieFile + + bpmnFile + " from serviceUrl " + serviceURL + ": " + @@ -88,14 +88,14 @@ export async function validateBPMN( export async function validateDMN( serviceURL: URL, - kieFile: kiefile.KieFile + dmnFile: kiefile.KieFile ): Promise { try { - return validate(serviceURL, kieFile, "/jitdmn/validate", validationresponse.parseDMNValidationResponse); + return validate(serviceURL, dmnFile, "/jitdmn/validate", validationresponse.parseDMNValidationResponse); } catch (error) { console.error( "[Extended Services Extension] An error happened while trying to validate " + - kieFile + + dmnFile + " from serviceUrl " + serviceURL + ": " + From 25b56624b58b2cd72d378d82f7439e3a5afae2db Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 16 Dec 2024 12:46:23 +0100 Subject: [PATCH 07/15] wip --- packages/extended-services-vscode-extension/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extended-services-vscode-extension/package.json b/packages/extended-services-vscode-extension/package.json index be6c3b96bb1..d57010b5664 100644 --- a/packages/extended-services-vscode-extension/package.json +++ b/packages/extended-services-vscode-extension/package.json @@ -73,7 +73,7 @@ ], "configuration": { "properties": { - "extendedServices.connectionHeartbeatIntervalinSecs": { + "extendedServices.connectionHeartbeatIntervalInSecs": { "default": 10, "description": "Specifies the interval (in seconds) between each connection check.", "format": "time", From 1b86f15617dda69d285926050fb9f97fc03fc636 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 16 Dec 2024 14:16:23 +0100 Subject: [PATCH 08/15] CR --- .../src/Validator.ts | 12 +++---- .../src/configurations/Configuration.ts | 4 +-- .../src/extension/extension-browser.ts | 33 ++++++++----------- .../src/extension/extension-main.ts | 10 +++--- 4 files changed, 25 insertions(+), 34 deletions(-) diff --git a/packages/extended-services-vscode-extension/src/Validator.ts b/packages/extended-services-vscode-extension/src/Validator.ts index 6048f8355cb..685bb891165 100644 --- a/packages/extended-services-vscode-extension/src/Validator.ts +++ b/packages/extended-services-vscode-extension/src/Validator.ts @@ -57,10 +57,8 @@ export async function validateBPMN(serviceURL: URL, bpmnFile: kieFile.KieFile): ); return createBPMNDiagnostics(validationResponses); } catch (error) { - console.error("An error happened while trying to validate BPMN file: " + kieFile + " with error: " + error.message); - throw new Error( - "An error happened while trying to validate BPMN file: " + kieFile + " with error: " + error.message - ); + console.error(`An error occured while trying to validate DMN file: ${bpmnFile} with error: ${error.message}`); + throw new Error(`An error occured while trying to validate DMN file: ${bpmnFile} with error: ${error.message}`); } } @@ -72,9 +70,7 @@ export async function validateDMN(serviceURL: URL, dmnFile: kieFile.KieFile): Pr ); return createDMNDiagnostics(validationResponses); } catch (error) { - console.error("An error happened while trying to validate DMN file: " + kieFile + " with error: " + error.message); - throw new Error( - "An error happened while trying to validate DMN file: " + kieFile + " with error: " + error.message - ); + console.error(`An error occured while trying to validate DMN file: ${dmnFile} with error: ${error.message}`); + throw new Error(`An error occured while trying to validate DMN file: ${dmnFile} with error: ${error.message}`); } } diff --git a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts index 9269bbbd533..dc83a97c882 100644 --- a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts +++ b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts @@ -41,14 +41,14 @@ function fetchExtendedServicesURL(): URL { try { return new URL(extendedServicesURL); } catch (error) { - throw new Error("URL configuration " + extendedServicesURL + " is invalid: " + error.message); + throw new Error(`URL configuration ${extendedServicesURL} is invalid: ${error.message}`); } } const getConfigurationPropertyValue = (property: string, defaultValue: T): T => { const value = vscode.workspace.getConfiguration().get(property) as T; if (value == null) { - console.warn("Property: " + property + " is missing, using the default: " + defaultValue); + console.warn(`Property: ${property} is missing, using the default: ${defaultValue}`); value == defaultValue; } return value; diff --git a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts index 0aa1ba687ed..b9d7ade2089 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts @@ -74,24 +74,24 @@ function startExtendedServices(): void { try { configuration = fetchConfiguration(); } catch (error) { - console.error("[Extended Services Extension] Extension configuration is wrong: " + error.message); + console.error(`[Extended Services Extension] Extension configuration is wrong: ${error.message}`); vscode.window.showErrorMessage( - "Extension configuration is wrong: " + error.message + " Please fix your local extension's setting" + `Extension configuration is wrong: ${error.message}. Please fix your local extension's setting` ); return; } try { console.debug( - "[Extended Services Extension] Connecting with the Extended Service located: " + configuration.extendedServicesURL + `[Extended Services Extension] Connecting with the Extended Services located: ${configuration.extendedServicesURL}` ); connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalinSecs); } catch (error) { stopExtendedServices(); console.error( - "[Extended Services Extension] An error happened while trying to start the local service:" + error.message + `[Extended Services Extension] An error happened while trying to start the local service: ${error.message}` ); - vscode.window.showErrorMessage("An error happened while trying to start the local service:" + error.message); + vscode.window.showErrorMessage(`An error happened while trying to start the local service: ${error.message}`); } } @@ -111,36 +111,30 @@ async function validate(extendedServicesURL: URL) { for (const bpmnFile of bpmnFiles) { try { - console.debug("[Extended Services Extension] Validating BPMN file: " + bpmnFile.uri.path); + console.debug(`[Extended Services Extension] Validating DMN file: ${bpmnFile.uri.path}`); const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateBPMN(extendedServicesURL, bpmnFile); diagnosticCollection.set(bpmnFile.uri, bpmnDiagnostics); } catch (error) { console.error( - "[Extended Services Extension] An error happened while trying to validate " + - bpmnFile.uri.path + - ": " + - error.message + `[Extended Services Extension] An error happened while trying to validate ${bpmnFile.uri.path}: ${error.message}` ); vscode.window.showErrorMessage( - "An error happened while trying to validate " + bpmnFile.uri.path + ": " + error.message + `An error happened while trying to validate ${bpmnFile.uri.path}: ${error.message}` ); } } for (const dmnFile of dmnFiles) { try { - console.debug("[Extended Services Extension] Validating DMN file: " + dmnFile.uri.path); + console.debug(`[Extended Services Extension] Validating DMN file: ${dmnFile.uri.path}`); const dmnDiagnostics: vscode.Diagnostic[] = await validator.validateDMN(extendedServicesURL, dmnFile); diagnosticCollection.set(dmnFile.uri, dmnDiagnostics); } catch (error) { console.error( - "[Extended Services Extension] An error happened while trying to validate " + - dmnFile.uri.path + - ": " + - error.message + `[Extended Services Extension] An error happened while trying to validate ${dmnFile.uri.path}: ${error.message}` ); vscode.window.showErrorMessage( - "An error happened while trying to validate " + dmnFile.uri.path + ": " + error.message + `An error happened while trying to validate ${dmnFile.uri.path}: ${error.message}` ); } } @@ -160,8 +154,9 @@ export function activate(context: vscode.ExtensionContext) { kieFilesWatcher.subscribeKieFilesOpened(() => { console.debug( - "[Extended Services Extension] A KIE file has been opened. Current opened KIE files: " + + `[Extended Services Extension] A KIE file has been opened. Current opened KIE files: ${ kieFilesWatcher.watchedKieFiles.length + }` ); if (!disconnectedByUser && isConnected && configuration) { validate(configuration.extendedServicesURL); @@ -203,7 +198,7 @@ export function activate(context: vscode.ExtensionContext) { stopExtendedServices(); isConnected = false; console.error("[Extended Services Extension] Connection lost with Extended Services"); - vscode.window.showErrorMessage("Connection error: " + errorMessage); + vscode.window.showErrorMessage(`Connection error: ${errorMessage}`); }); connection.subscribeDisconnected(() => { diff --git a/packages/extended-services-vscode-extension/src/extension/extension-main.ts b/packages/extended-services-vscode-extension/src/extension/extension-main.ts index 6bf0248bdfa..9f8e1e5f2ae 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-main.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-main.ts @@ -43,7 +43,7 @@ let configurationWatcher: ConfigurationWatcher; let connection: Connection; let localService: LocalExtendedServices; -/* Determines if the extension is corrected with the Extended Services Backend */ +/* Determines if the extension is connected with the Extended Services Backend */ let isConnected = false; /* Determines the user explicitely disconnected the Extension from the Extended Services Backend */ let disconnectedByUser: boolean = false; @@ -107,24 +107,24 @@ function stopExtendedServices(configuration: Configuration | null) { } function startLocalExtendedServices(configuration: Configuration, context: vscode.ExtensionContext): void { - console.debug("[Extended Services Extension] Starting a Local Extended Service process"); + console.debug("[Extended Services Extension] Starting a Local Extended Services process"); try { localService.start(configuration.extendedServicesURL, context.extensionPath); } catch (error) { stopExtendedServices(configuration); console.error( - "[Extended Services Extension] An error happened while trying to start the Local Extended Service process:" + + "[Extended Services Extension] An error happened while trying to start the Local Extended Services process:" + error.message ); vscode.window.showErrorMessage( - "An error happened while trying to start the Local Extended Service process:" + error.message + "An error happened while trying to start the Local Extended Services process:" + error.message ); } } function startConnection(configuration: Configuration) { console.debug( - "[Extended Services Extension] Connecting with the Extended Service located: " + configuration.extendedServicesURL + "[Extended Services Extension] Connecting with the Extended Services located: " + configuration.extendedServicesURL ); try { connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalinSecs); From 6f2a0724d49fd752573ebaae2ac810593593351d Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 16 Dec 2024 15:15:06 +0100 Subject: [PATCH 09/15] Added env. --- .../env/index.js | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/extended-services-vscode-extension/env/index.js b/packages/extended-services-vscode-extension/env/index.js index 61bc742bd66..b53ded06d18 100644 --- a/packages/extended-services-vscode-extension/env/index.js +++ b/packages/extended-services-vscode-extension/env/index.js @@ -17,11 +17,28 @@ * under the License. */ -const { varsWithName, composeEnv } = require("@kie-tools-scripts/build-env"); +const { getOrDefault, varsWithName, composeEnv } = require("@kie-tools-scripts/build-env"); module.exports = composeEnv([require("@kie-tools/root-env/env")], { - vars: varsWithName({}), + vars: varsWithName({ + EXTENDED_SERVICES_JAVA__host: { + default: "0.0.0.0", + description: + "Quarkus HTTP Host. Configures the IP address or host to which a Quarkus application binds for incoming HTTP requests.", + }, + EXTENDED_SERVICES_JAVA__port: { + default: "21345", + description: + "Quarkus HTTP Port. Configures the network port on which a Quarkus application accepts incoming HTTP requests.", + }, + }), get env() { - return {}; + return { + extendedServicesJava: { + version: require("../package.json").version, + host: getOrDefault(this.vars.EXTENDED_SERVICES_JAVA__host), + port: getOrDefault(this.vars.EXTENDED_SERVICES_JAVA__port), + }, + }; }, }); From 3d83bf8fbb02ca4de7b0b10f501e5ec7405a9024 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 16 Dec 2024 16:45:45 +0100 Subject: [PATCH 10/15] wip --- .../env/index.js | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/packages/extended-services-vscode-extension/env/index.js b/packages/extended-services-vscode-extension/env/index.js index b53ded06d18..bbd362e8067 100644 --- a/packages/extended-services-vscode-extension/env/index.js +++ b/packages/extended-services-vscode-extension/env/index.js @@ -17,28 +17,11 @@ * under the License. */ -const { getOrDefault, varsWithName, composeEnv } = require("@kie-tools-scripts/build-env"); +const { composeEnv, varsWithName } = require("@kie-tools-scripts/build-env"); -module.exports = composeEnv([require("@kie-tools/root-env/env")], { - vars: varsWithName({ - EXTENDED_SERVICES_JAVA__host: { - default: "0.0.0.0", - description: - "Quarkus HTTP Host. Configures the IP address or host to which a Quarkus application binds for incoming HTTP requests.", - }, - EXTENDED_SERVICES_JAVA__port: { - default: "21345", - description: - "Quarkus HTTP Port. Configures the network port on which a Quarkus application accepts incoming HTTP requests.", - }, - }), +module.exports = composeEnv([require("@kie-tools/root-env/env"), require("@kie-tools/extended-services-java/env")], { + vars: varsWithName({}), get env() { - return { - extendedServicesJava: { - version: require("../package.json").version, - host: getOrDefault(this.vars.EXTENDED_SERVICES_JAVA__host), - port: getOrDefault(this.vars.EXTENDED_SERVICES_JAVA__port), - }, - }; + return {}; }, }); From 89a69b1500d7b351c2f147cd1942b530fafed3b9 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 16 Dec 2024 18:27:47 +0100 Subject: [PATCH 11/15] WIP --- .../src/Connection.ts | 4 +- .../src/configurations/Configuration.ts | 20 +++--- .../configurations/ConfigurationWatcher.ts | 6 +- .../src/extension/extension-browser.ts | 2 +- .../src/extension/extension-main.ts | 2 +- .../webpack.config.js | 62 ++++++++++++++----- 6 files changed, 66 insertions(+), 30 deletions(-) diff --git a/packages/extended-services-vscode-extension/src/Connection.ts b/packages/extended-services-vscode-extension/src/Connection.ts index dc39250f43a..185ffdfa696 100644 --- a/packages/extended-services-vscode-extension/src/Connection.ts +++ b/packages/extended-services-vscode-extension/src/Connection.ts @@ -28,10 +28,10 @@ export class Connection { private timeout: NodeJS.Timeout | null = null; private connected: boolean = false; - public async start(extendedServicesURL: URL, connectionHeartbeatIntervalinSecs: number): Promise { + public async start(extendedServicesURL: URL, connectionHeartbeatIntervalInSecs: number): Promise { this.timeout = setInterval(async () => { this.performHeartbeatCheck(extendedServicesURL); - }, connectionHeartbeatIntervalinSecs * 1000); + }, connectionHeartbeatIntervalInSecs * 1000); } public stop(): void { diff --git a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts index dc83a97c882..acd0f810502 100644 --- a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts +++ b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts @@ -20,23 +20,24 @@ import * as vscode from "vscode"; export const enableAutoRunID = "extendedServices.enableAutorun"; -export const connectionHeartbeatIntervalinSecsID = "extendedServices.connectionHeartbeatIntervalinSecs"; +export const connectionHeartbeatIntervalInSecsID = "extendedServices.connectionHeartbeatIntervalInSecs"; export const extendedServicesURLID = "extendedServices.extendedServicesURL"; const defaultExtendedServicesURL = "http://localhost:21345"; export class Configuration { readonly enableAutoRun: boolean; - readonly connectionHeartbeatIntervalinSecs: number; + readonly connectionHeartbeatIntervalInSecs: number; readonly extendedServicesURL: URL; - constructor(enableAutoRun: boolean, connectionHeartbeatIntervalinSecs: number, extendedServicesURL: URL) { + constructor(enableAutoRun: boolean, connectionHeartbeatIntervalInSecs: number, extendedServicesURL: URL) { this.enableAutoRun = enableAutoRun; - this.connectionHeartbeatIntervalinSecs = connectionHeartbeatIntervalinSecs; + this.connectionHeartbeatIntervalInSecs = connectionHeartbeatIntervalInSecs; this.extendedServicesURL = extendedServicesURL; } } function fetchExtendedServicesURL(): URL { + const defaultExtendedServicesURL = `http://${process.env.WEBPACK_REPLACE__extendedServicesUrlHost}:${process.env.WEBPACK_REPLACE__extendedServicesUrlPort!}`; const extendedServicesURL = getConfigurationPropertyValue(extendedServicesURLID, defaultExtendedServicesURL); try { return new URL(extendedServicesURL); @@ -46,7 +47,10 @@ function fetchExtendedServicesURL(): URL { } const getConfigurationPropertyValue = (property: string, defaultValue: T): T => { - const value = vscode.workspace.getConfiguration().get(property) as T; + console.log(" property " + property); + console.log(" default " + defaultValue); + const value: T | null = vscode.workspace.getConfiguration().get(property) as T; + console.log(" value: " + value); if (value == null) { console.warn(`Property: ${property} is missing, using the default: ${defaultValue}`); value == defaultValue; @@ -56,11 +60,11 @@ const getConfigurationPropertyValue = (property: string, defaultValue: T): T export function fetchConfiguration(): Configuration { const enableAutoRun = getConfigurationPropertyValue(enableAutoRunID, true); - const connectionHeartbeatIntervalinSecs = getConfigurationPropertyValue( - connectionHeartbeatIntervalinSecsID, + const connectionHeartbeatIntervalInSecs = getConfigurationPropertyValue( + connectionHeartbeatIntervalInSecsID, 10 ); const extendedServicesURL = fetchExtendedServicesURL(); - return new Configuration(enableAutoRun, connectionHeartbeatIntervalinSecs, extendedServicesURL); + return new Configuration(enableAutoRun, connectionHeartbeatIntervalInSecs, extendedServicesURL); } diff --git a/packages/extended-services-vscode-extension/src/configurations/ConfigurationWatcher.ts b/packages/extended-services-vscode-extension/src/configurations/ConfigurationWatcher.ts index 62d6e7b4bfb..9e8a8f903bb 100644 --- a/packages/extended-services-vscode-extension/src/configurations/ConfigurationWatcher.ts +++ b/packages/extended-services-vscode-extension/src/configurations/ConfigurationWatcher.ts @@ -30,12 +30,12 @@ export class ConfigurationWatcher { private handleConfigurationChange(configurationChange: vscode.ConfigurationChangeEvent) { const enableAutoRunChanged = configurationChange.affectsConfiguration(configuration.enableAutoRunID); - const connectionHeartbeatIntervalinSecsChanged = configurationChange.affectsConfiguration( - configuration.connectionHeartbeatIntervalinSecsID + const connectionHeartbeatIntervalInSecsChanged = configurationChange.affectsConfiguration( + configuration.connectionHeartbeatIntervalInSecsID ); const extendedServicesURLChanged = configurationChange.affectsConfiguration(configuration.extendedServicesURLID); - if (enableAutoRunChanged || connectionHeartbeatIntervalinSecsChanged || extendedServicesURLChanged) { + if (enableAutoRunChanged || connectionHeartbeatIntervalInSecsChanged || extendedServicesURLChanged) { this.fireConfigurationChangedEvent(); } } diff --git a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts index b9d7ade2089..21a18858b4a 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts @@ -85,7 +85,7 @@ function startExtendedServices(): void { console.debug( `[Extended Services Extension] Connecting with the Extended Services located: ${configuration.extendedServicesURL}` ); - connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalinSecs); + connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalInSecs); } catch (error) { stopExtendedServices(); console.error( diff --git a/packages/extended-services-vscode-extension/src/extension/extension-main.ts b/packages/extended-services-vscode-extension/src/extension/extension-main.ts index 9f8e1e5f2ae..2c0ff43ea42 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-main.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-main.ts @@ -127,7 +127,7 @@ function startConnection(configuration: Configuration) { "[Extended Services Extension] Connecting with the Extended Services located: " + configuration.extendedServicesURL ); try { - connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalinSecs); + connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalInSecs); } catch (error) { stopExtendedServices(configuration); console.error( diff --git a/packages/extended-services-vscode-extension/webpack.config.js b/packages/extended-services-vscode-extension/webpack.config.js index d52f1fb6e7c..50be69a003d 100644 --- a/packages/extended-services-vscode-extension/webpack.config.js +++ b/packages/extended-services-vscode-extension/webpack.config.js @@ -18,6 +18,8 @@ */ const { merge } = require("webpack-merge"); +const { EnvironmentPlugin } = require("webpack"); +const { env } = require("./env"); const common = require("@kie-tools-core/webpack-base/webpack.common.config"); const commonConfig = (webpackEnv) => @@ -30,21 +32,51 @@ const commonConfig = (webpackEnv) => }, externals: { vscode: "commonjs vscode", + plugins: [], }, - plugins: [], }); -module.exports = async (webpackEnv) => [ - merge(commonConfig(webpackEnv), { - target: "node", - entry: { - "extension/extension-main": "./src/extension/extension-main.ts", - }, - }), - merge(commonConfig(webpackEnv), { - target: "web", - entry: { - "extension/extension-browser": "./src/extension/extension-browser.ts", - }, - }), -]; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +const buildEnv = env; // build-env is not typed + +module.exports = async (webpackEnv) => { + const [extendedServices_urlHost, extendedServices_urlPort] = getExtendedServicesArgs(); + + return [ + merge(commonConfig(webpackEnv), { + target: "node", + entry: { + "extension/extension-main": "./src/extension/extension-main.ts", + }, + plugins: [ + new EnvironmentPlugin({ + WEBPACK_REPLACE__extendedServicesUrlHost: extendedServices_urlHost, + WEBPACK_REPLACE__extendedServicesUrlPort: extendedServices_urlPort, + }), + ], + }), + merge(commonConfig(webpackEnv), { + target: "web", + entry: { + "extension/extension-browser": "./src/extension/extension-browser.ts", + }, + plugins: [ + new EnvironmentPlugin({ + WEBPACK_REPLACE__extendedServicesUrlHost: extendedServices_urlHost, + WEBPACK_REPLACE__extendedServicesUrlPort: extendedServices_urlPort, + }), + ], + }), + ]; +}; + +function getExtendedServicesArgs() { + const extendedServicesJavaHost = buildEnv.extendedServicesJava.host; + const extendedServicesJavaPort = buildEnv.extendedServicesJava.port; + + console.info("Extended Services :: URL HOST " + extendedServicesJavaHost); + console.info("Extended Services :: URL PORT: " + extendedServicesJavaPort); + + return [extendedServicesJavaHost, extendedServicesJavaPort]; +} From 5d2b78154b18beecb6b95b3198d30dd08774313b Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 16 Dec 2024 18:43:52 +0100 Subject: [PATCH 12/15] WIP --- .../src/configurations/Configuration.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts index acd0f810502..13ac5352f39 100644 --- a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts +++ b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts @@ -37,7 +37,7 @@ export class Configuration { } function fetchExtendedServicesURL(): URL { - const defaultExtendedServicesURL = `http://${process.env.WEBPACK_REPLACE__extendedServicesUrlHost}:${process.env.WEBPACK_REPLACE__extendedServicesUrlPort!}`; + const defaultExtendedServicesURL = `http://${process.env.WEBPACK_REPLACE__extendedServicesUrlHost}:${process.env.WEBPACK_REPLACE__extendedServicesUrlPort}`; const extendedServicesURL = getConfigurationPropertyValue(extendedServicesURLID, defaultExtendedServicesURL); try { return new URL(extendedServicesURL); @@ -47,10 +47,7 @@ function fetchExtendedServicesURL(): URL { } const getConfigurationPropertyValue = (property: string, defaultValue: T): T => { - console.log(" property " + property); - console.log(" default " + defaultValue); const value: T | null = vscode.workspace.getConfiguration().get(property) as T; - console.log(" value: " + value); if (value == null) { console.warn(`Property: ${property} is missing, using the default: ${defaultValue}`); value == defaultValue; From f9fdc5fad67ceee3a5ac7dd538ec31ddd04e76a6 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 16 Dec 2024 18:47:16 +0100 Subject: [PATCH 13/15] minor --- .../src/configurations/Configuration.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts index 13ac5352f39..790c07729a9 100644 --- a/packages/extended-services-vscode-extension/src/configurations/Configuration.ts +++ b/packages/extended-services-vscode-extension/src/configurations/Configuration.ts @@ -22,7 +22,6 @@ import * as vscode from "vscode"; export const enableAutoRunID = "extendedServices.enableAutorun"; export const connectionHeartbeatIntervalInSecsID = "extendedServices.connectionHeartbeatIntervalInSecs"; export const extendedServicesURLID = "extendedServices.extendedServicesURL"; -const defaultExtendedServicesURL = "http://localhost:21345"; export class Configuration { readonly enableAutoRun: boolean; From 8eebccb8dd561d804bedb032be59fcfd6f62e07f Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Tue, 17 Dec 2024 11:55:07 +0100 Subject: [PATCH 14/15] minor --- .../src/extension/extension-browser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts index 21a18858b4a..17803ce631c 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts @@ -40,7 +40,7 @@ let kieFilesWatcher: KieFilesWatcher; let configurationWatcher: ConfigurationWatcher; let connection: Connection; -/* Determines if the extension is corrected with the Extended Services Backend */ +/* Determines if the extension is connected with the Extended Services Backend */ let isConnected = false; /* Determines the user explicitely disconnected the Extension from the Extended Services Backend */ let disconnectedByUser: boolean = false; From bb985750178f2e472ab26c4458a0398aa1659eec Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Tue, 17 Dec 2024 12:08:02 +0100 Subject: [PATCH 15/15] Minor --- .../src/extension/extension-browser.ts | 3 +- .../src/extension/extension-main.ts | 41 ++++++++----------- .../src/requests/ValidationRequests.ts | 16 ++------ 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts index 17803ce631c..cd81062938d 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-browser.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-browser.ts @@ -175,8 +175,7 @@ export function activate(context: vscode.ExtensionContext) { kieFilesWatcher.subscribeKieFilesClosed(() => { console.debug( - "[Extended Services Extension] A KIE file has been closed. Current opened KIE files: " + - kieFilesWatcher.watchedKieFiles.length + `[Extended Services Extension] A KIE file has been closed. Current opened KIE files: ${kieFilesWatcher.watchedKieFiles.length}` ); }); diff --git a/packages/extended-services-vscode-extension/src/extension/extension-main.ts b/packages/extended-services-vscode-extension/src/extension/extension-main.ts index 2c0ff43ea42..069e531b54c 100644 --- a/packages/extended-services-vscode-extension/src/extension/extension-main.ts +++ b/packages/extended-services-vscode-extension/src/extension/extension-main.ts @@ -79,9 +79,9 @@ function startExtendedServices(context: vscode.ExtensionContext): void { try { configuration = fetchConfiguration(); } catch (error) { - console.error("[Extended Services Extension] Extension configuration is wrong: " + error.message); + console.error(`[Extended Services Extension] Extension configuration is wrong: ${error.message}`); vscode.window.showErrorMessage( - "Extension configuration is wrong: " + error.message + " Please fix your local extension's setting" + `Extension configuration is wrong: ${error.message}. Please fix your local extension's setting.` ); statusBarItem.hide(); return; @@ -113,27 +113,26 @@ function startLocalExtendedServices(configuration: Configuration, context: vscod } catch (error) { stopExtendedServices(configuration); console.error( - "[Extended Services Extension] An error happened while trying to start the Local Extended Services process:" + - error.message + `[Extended Services Extension] An error happened while trying to start the Local Extended Services process: ${error.message}` ); vscode.window.showErrorMessage( - "An error happened while trying to start the Local Extended Services process:" + error.message + `An error happened while trying to start the Local Extended Services process: ${error.message}` ); } } function startConnection(configuration: Configuration) { console.debug( - "[Extended Services Extension] Connecting with the Extended Services located: " + configuration.extendedServicesURL + `[Extended Services Extension] Connecting with the Extended Services located: ${configuration.extendedServicesURL}` ); try { connection.start(configuration.extendedServicesURL, configuration.connectionHeartbeatIntervalInSecs); } catch (error) { stopExtendedServices(configuration); console.error( - "[Extended Services Extension] An error happened while trying to connect to the service:" + error.message + `[Extended Services Extension] An error happened while trying to connect to the service: ${error.message}` ); - vscode.window.showErrorMessage("An error happened while trying to connect to the service:" + error.message); + vscode.window.showErrorMessage(`An error happened while trying to connect to the service: ${error.message}`); } } @@ -147,36 +146,30 @@ async function validate(extendedServicesURL: URL) { for (const bpmnFile of bpmnFiles) { try { - console.debug("[Extended Services Extension] Validating BPMN file: " + bpmnFile.uri.path); + console.debug(`[Extended Services Extension] Validating BPMN file: ${bpmnFile.uri.path}`); const bpmnDiagnostics: vscode.Diagnostic[] = await validator.validateBPMN(extendedServicesURL, bpmnFile); diagnosticCollection.set(bpmnFile.uri, bpmnDiagnostics); } catch (error) { console.error( - "[Extended Services Extension] An error happened while trying to validate " + - bpmnFile.uri.path + - ": " + - error.message + `[Extended Services Extension] An error happened while trying to validate ${bpmnFile.uri.path}: ${error.message}` ); vscode.window.showErrorMessage( - "An error happened while trying to validate " + bpmnFile.uri.path + ": " + error.message + `An error happened while trying to validate ${bpmnFile.uri.path}: ${error.message}` ); } } for (const dmnFile of dmnFiles) { try { - console.debug("[Extended Services Extension] Validating DMN file: " + dmnFile.uri.path); + console.debug(`[Extended Services Extension] Validating DMN file: ${dmnFile.uri.path}`); const dmnDiagnostics: vscode.Diagnostic[] = await validator.validateDMN(extendedServicesURL, dmnFile); diagnosticCollection.set(dmnFile.uri, dmnDiagnostics); } catch (error) { console.error( - "[Extended Services Extension] An error happened while trying to validate " + - dmnFile.uri.path + - ": " + - error.message + `[Extended Services Extension] An error happened while trying to validate ${dmnFile.uri.path}: ${error.message}` ); vscode.window.showErrorMessage( - "An error happened while trying to validate " + dmnFile.uri.path + ": " + error.message + `An error happened while trying to validate ${dmnFile.uri.path}: ${error.message}` ); } } @@ -197,8 +190,9 @@ export function activate(context: vscode.ExtensionContext) { kieFilesWatcher.subscribeKieFilesOpened(() => { console.debug( - "[Extended Services Extension] A KIE file has been opened. Current opened KIE files: " + + `[Extended Services Extension] A KIE file has been opened. Current opened KIE files: ${ kieFilesWatcher.watchedKieFiles.length + }` ); if (!disconnectedByUser && isConnected && configuration) { validate(configuration.extendedServicesURL); @@ -217,8 +211,7 @@ export function activate(context: vscode.ExtensionContext) { kieFilesWatcher.subscribeKieFilesClosed(() => { console.debug( - "[Extended Services Extension] A KIE file has been closed. Current opened KIE files: " + - kieFilesWatcher.watchedKieFiles.length + `[Extended Services Extension] A KIE file has been closed. Current opened KIE files: ${kieFilesWatcher.watchedKieFiles.length}` ); }); @@ -261,7 +254,7 @@ export function activate(context: vscode.ExtensionContext) { stopExtendedServices(configuration); isConnected = false; console.error("[Extended Services Extension] Connection lost with Extended Services"); - vscode.window.showErrorMessage("Connection error: " + errorMessage); + vscode.window.showErrorMessage(`Connection error: ${errorMessage}`); }); connection.subscribeDisconnected(() => { diff --git a/packages/extended-services-vscode-extension/src/requests/ValidationRequests.ts b/packages/extended-services-vscode-extension/src/requests/ValidationRequests.ts index cb6ada2de9e..92bbb3cb76f 100644 --- a/packages/extended-services-vscode-extension/src/requests/ValidationRequests.ts +++ b/packages/extended-services-vscode-extension/src/requests/ValidationRequests.ts @@ -54,7 +54,7 @@ async function validate( textDocument = await vscode.workspace.openTextDocument(kieFile.uri); } const url = new URL(endpoint, serviceURL); - console.debug("[Extended Services Extension] Fetching " + url.toString()); + console.debug(`[Extended Services Extension] Fetching ${url.toString()}`); const response = await fetch(url.toString(), { method: "POST", headers: { @@ -75,12 +75,7 @@ export async function validateBPMN( return validate(serviceURL, bpmnFile, "/jitbpmn/validate", validationresponse.parseBPMNValidationResponse); } catch (error) { console.error( - "[Extended Services Extension] An error happened while trying to validate " + - bpmnFile + - " from serviceUrl " + - serviceURL + - ": " + - error + `[Extended Services Extension] An error happened while trying to validate ${bpmnFile} from serviceUrl ${serviceURL}: ${error.message}` ); throw new Error("VALIDATE BPMN REQUEST ERROR: \n", error.message); } @@ -94,12 +89,7 @@ export async function validateDMN( return validate(serviceURL, dmnFile, "/jitdmn/validate", validationresponse.parseDMNValidationResponse); } catch (error) { console.error( - "[Extended Services Extension] An error happened while trying to validate " + - dmnFile + - " from serviceUrl " + - serviceURL + - ": " + - error + `[Extended Services Extension] An error happened while trying to validate ${dmnFile} from serviceUrl ${serviceURL}: ${error.message}` ); throw new Error("VALIDATE DMN REQUEST ERROR: \n", error.message); }