diff --git a/CHANGELOG.md b/CHANGELOG.md index e6bc12b..3da80a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [0.0.13] + +- Bug Fix: VSCode folder to port hashing algorithm was not working correctly. + ## [0.0.12] - Bug Fix: When executing command "Developer: Reload Window", the previous TCP port could not be reused because the old extension process was not kill. Now it saves the PID and kills it the next time the extension is activated. diff --git a/package.json b/package.json index 5976c39..8204f29 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "This extension allows you to remotely control Visual Studio Code via a REST endpoint, taking automation to the next level.", "publisher": "dpar39", "license": "MIT", - "version": "0.0.12", + "version": "0.0.13", "engines": { "vscode": "^1.55.0" }, diff --git a/src/extension.ts b/src/extension.ts index 23c44ce..807edc0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -127,7 +127,7 @@ const startHttpServer = async ( function getDefaultPortForWorkspace(): number { const identifier = vscode.workspace.workspaceFile ? vscode.workspace.workspaceFile.toString() - : vscode.workspace.workspaceFolders?.join(""); + : vscode.workspace.workspaceFolders?.map(f => f.uri.toString()).join(""); if (!identifier) { return 37100; } @@ -135,7 +135,7 @@ function getDefaultPortForWorkspace(): number { a = (a << 5) - a + b.charCodeAt(0); return a & a; }, 0); - const port = 37100 + (Math.abs(hash) % 900); + const port = 37100 + (Math.abs(hash) % (65535-37100)); return port; } @@ -147,7 +147,7 @@ function httpPortToPid(context: vscode.ExtensionContext, port: number): string { return cacheDir + "/" + port + ".pid"; } -function killPreviousProcessIfUsingTcpPort( +function killPreviousVscodeProcessIfUsingTcpPort( context: vscode.ExtensionContext, port: number | undefined ) { @@ -182,7 +182,7 @@ function setupRestControl(context: vscode.ExtensionContext) { const enabled = config.get("enable"); if (enabled) { const port = config.get("port") || getDefaultPortForWorkspace(); - killPreviousProcessIfUsingTcpPort(context, port); + killPreviousVscodeProcessIfUsingTcpPort(context, port); const fallbackPorts = config.get("fallbacks"); startHttpServer( context,