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

0.0.13 - BugFix: hash correctly workspace folders to assign unique port #10

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 4 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ 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;
}
const hash = identifier.split("").reduce((a: number, b: string) => {
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;
}

Expand All @@ -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
) {
Expand Down Expand Up @@ -182,7 +182,7 @@ function setupRestControl(context: vscode.ExtensionContext) {
const enabled = config.get<number | null>("enable");
if (enabled) {
const port = config.get<number | null>("port") || getDefaultPortForWorkspace();
killPreviousProcessIfUsingTcpPort(context, port);
killPreviousVscodeProcessIfUsingTcpPort(context, port);
const fallbackPorts = config.get<number[] | null>("fallbacks");
startHttpServer(
context,
Expand Down
Loading