Skip to content

Commit 196894d

Browse files
committed
🤖 refactor: clean up VS Code extension code
- Remove redundant condition check in formatWorkspaceLabel - Remove console.log from activate function - Simplify path handling in getRemoteWorkspacePath - Replace .then() chains with async/await for better readability - Remove unused getRemoteSshExtensionId function
1 parent 8d9e140 commit 196894d

File tree

3 files changed

+23
-44
lines changed

3 files changed

+23
-44
lines changed

vscode/src/cmuxConfig.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ export function getRemoteWorkspacePath(
124124
const projectName = path.basename(workspace.projectPath);
125125
const srcBaseDir = workspace.runtimeConfig.srcBaseDir;
126126

127-
// Ensure path starts with / for absolute path
128-
const basePath = srcBaseDir.startsWith("~")
129-
? srcBaseDir
130-
: srcBaseDir.startsWith("/")
127+
// Remote paths should be absolute (starting with / or ~)
128+
const basePath =
129+
srcBaseDir.startsWith("/") || srcBaseDir.startsWith("~")
131130
? srcBaseDir
132131
: `/${srcBaseDir}`;
133132

vscode/src/extension.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import { openWorkspace } from "./workspaceOpener";
66
* Format workspace for display in QuickPick
77
*/
88
function formatWorkspaceLabel(workspace: WorkspaceWithContext): string {
9-
const isRemote =
10-
workspace.runtimeConfig && workspace.runtimeConfig.type === "ssh";
11-
12-
if (isRemote && workspace.runtimeConfig?.type === "ssh") {
9+
if (workspace.runtimeConfig?.type === "ssh") {
1310
return `$(remote) [${workspace.projectName}] ${workspace.name} (ssh: ${workspace.runtimeConfig.host})`;
1411
}
1512

@@ -76,8 +73,6 @@ async function openWorkspaceCommand() {
7673
* Activate the extension
7774
*/
7875
export function activate(context: vscode.ExtensionContext) {
79-
console.log('cmux extension is now active');
80-
8176
// Register the openWorkspace command
8277
const disposable = vscode.commands.registerCommand(
8378
"cmux.openWorkspace",

vscode/src/workspaceOpener.ts

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ function isRemoteSshInstalled(): boolean {
1616
);
1717
}
1818

19-
/**
20-
* Get the ID of the installed Remote-SSH extension
21-
*/
22-
function getRemoteSshExtensionId(): string | undefined {
23-
if (vscode.extensions.getExtension("ms-vscode-remote.remote-ssh")) {
24-
return "ms-vscode-remote.remote-ssh";
25-
}
26-
if (vscode.extensions.getExtension("anysphere.remote-ssh")) {
27-
return "anysphere.remote-ssh";
28-
}
29-
return undefined;
30-
}
31-
3219
/**
3320
* Open a local workspace in a new VS Code window
3421
*/
@@ -50,22 +37,22 @@ async function openLocalWorkspace(workspace: WorkspaceWithContext) {
5037
async function openSshWorkspace(workspace: WorkspaceWithContext) {
5138
// Check if Remote-SSH is installed
5239
if (!isRemoteSshInstalled()) {
53-
vscode.window.showErrorMessage(
40+
const selection = await vscode.window.showErrorMessage(
5441
'cmux: The "Remote - SSH" extension is required to open SSH workspaces. ' +
5542
"Please install it from the Extensions marketplace.",
5643
"Open Extensions"
57-
).then((selection) => {
58-
if (selection === "Open Extensions") {
59-
// Search for the appropriate extension based on the editor
60-
const extensionId = vscode.env.appName.toLowerCase().includes("cursor")
61-
? "anysphere.remote-ssh"
62-
: "ms-vscode-remote.remote-ssh";
63-
vscode.commands.executeCommand(
64-
"workbench.extensions.search",
65-
`@id:${extensionId}`
66-
);
67-
}
68-
});
44+
);
45+
46+
if (selection === "Open Extensions") {
47+
// Search for the appropriate extension based on the editor
48+
const extensionId = vscode.env.appName.toLowerCase().includes("cursor")
49+
? "anysphere.remote-ssh"
50+
: "ms-vscode-remote.remote-ssh";
51+
await vscode.commands.executeCommand(
52+
"workbench.extensions.search",
53+
`@id:${extensionId}`
54+
);
55+
}
6956
return;
7057
}
7158

@@ -91,18 +78,16 @@ async function openSshWorkspace(workspace: WorkspaceWithContext) {
9178
{ forceNewWindow: true }
9279
);
9380
} catch (error) {
94-
vscode.window.showErrorMessage(
81+
const selection = await vscode.window.showErrorMessage(
9582
`cmux: Failed to open SSH workspace on host "${host}". ` +
9683
`Make sure the host is configured in your ~/.ssh/config or in the Remote-SSH extension. ` +
9784
`Error: ${error instanceof Error ? error.message : String(error)}`,
9885
"Open SSH Config"
99-
).then((selection) => {
100-
if (selection === "Open SSH Config") {
101-
vscode.commands.executeCommand(
102-
"remote-ssh.openConfigFile"
103-
);
104-
}
105-
});
86+
);
87+
88+
if (selection === "Open SSH Config") {
89+
await vscode.commands.executeCommand("remote-ssh.openConfigFile");
90+
}
10691
}
10792
}
10893

0 commit comments

Comments
 (0)