Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yesamer committed Dec 16, 2024
1 parent 3d83bf8 commit 89a69b1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
4 changes: 2 additions & 2 deletions packages/extended-services-vscode-extension/src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
public async start(extendedServicesURL: URL, connectionHeartbeatIntervalInSecs: number): Promise<void> {
this.timeout = setInterval(async () => {
this.performHeartbeatCheck(extendedServicesURL);
}, connectionHeartbeatIntervalinSecs * 1000);
}, connectionHeartbeatIntervalInSecs * 1000);
}

public stop(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(extendedServicesURLID, defaultExtendedServicesURL);
try {
return new URL(extendedServicesURL);
Expand All @@ -46,7 +47,10 @@ function fetchExtendedServicesURL(): URL {
}

const getConfigurationPropertyValue = <T>(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;
Expand All @@ -56,11 +60,11 @@ const getConfigurationPropertyValue = <T>(property: string, defaultValue: T): T

export function fetchConfiguration(): Configuration {
const enableAutoRun = getConfigurationPropertyValue<boolean>(enableAutoRunID, true);
const connectionHeartbeatIntervalinSecs = getConfigurationPropertyValue<number>(
connectionHeartbeatIntervalinSecsID,
const connectionHeartbeatIntervalInSecs = getConfigurationPropertyValue<number>(
connectionHeartbeatIntervalInSecsID,
10
);
const extendedServicesURL = fetchExtendedServicesURL();

return new Configuration(enableAutoRun, connectionHeartbeatIntervalinSecs, extendedServicesURL);
return new Configuration(enableAutoRun, connectionHeartbeatIntervalInSecs, extendedServicesURL);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
62 changes: 47 additions & 15 deletions packages/extended-services-vscode-extension/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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];
}

0 comments on commit 89a69b1

Please sign in to comment.