Skip to content

Commit dece118

Browse files
authored
fix: resolve odd label formatting for recently opened (#95)
1 parent 9868091 commit dece118

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/remote.ts

+28-9
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ export class Remote {
122122

123123
const disposables: vscode.Disposable[] = []
124124
// Register before connection so the label still displays!
125-
disposables.push(this.registerLabelFormatter(`${this.storage.workspace.owner_name}/${this.storage.workspace.name}`))
125+
disposables.push(
126+
this.registerLabelFormatter(remoteAuthority, this.storage.workspace.owner_name, this.storage.workspace.name),
127+
)
126128

127129
let buildComplete: undefined | (() => void)
128130
if (this.storage.workspace.latest_build.status === "stopped") {
@@ -420,14 +422,11 @@ export class Remote {
420422
})
421423

422424
// Register the label formatter again because SSH overrides it!
423-
let label = `${this.storage.workspace.owner_name}/${this.storage.workspace.name}`
424-
if (agents.length > 1) {
425-
label += `/${agent.name}`
426-
}
427-
425+
const workspace = this.storage.workspace
426+
const agentName = agents.length > 1 ? agent.name : undefined
428427
disposables.push(
429428
vscode.extensions.onDidChange(() => {
430-
disposables.push(this.registerLabelFormatter(label))
429+
disposables.push(this.registerLabelFormatter(remoteAuthority, workspace.owner_name, workspace.name, agentName))
431430
}),
432431
)
433432

@@ -679,14 +678,34 @@ export class Remote {
679678
await vscode.commands.executeCommand("workbench.action.reloadWindow")
680679
}
681680

682-
private registerLabelFormatter(suffix: string): vscode.Disposable {
681+
private registerLabelFormatter(
682+
remoteAuthority: string,
683+
owner: string,
684+
workspace: string,
685+
agent?: string,
686+
): vscode.Disposable {
687+
// VS Code splits based on the separator when displaying the label
688+
// in a recently opened dialog. If the workspace suffix contains /,
689+
// then it'll visually display weird:
690+
// "/home/kyle [Coder: kyle/workspace]" displays as "workspace] /home/kyle [Coder: kyle"
691+
// For this reason, we use a different / that visually appears the
692+
// same on non-monospace fonts "∕".
693+
let suffix = `Coder: ${owner}${workspace}`
694+
if (agent) {
695+
suffix += `∕${agent}`
696+
}
697+
// VS Code caches resource label formatters in it's global storage SQLite database
698+
// under the key "memento/cachedResourceLabelFormatters2".
683699
return this.vscodeProposed.workspace.registerResourceLabelFormatter({
684700
scheme: "vscode-remote",
701+
// authority is optional but VS Code prefers formatters that most
702+
// accurately match the requested authority, so we include it.
703+
authority: remoteAuthority,
685704
formatting: {
686705
label: "${path}",
687706
separator: "/",
688707
tildify: true,
689-
workspaceSuffix: `Coder: ${suffix}`,
708+
workspaceSuffix: suffix,
690709
},
691710
})
692711
}

0 commit comments

Comments
 (0)