Skip to content

fix: resolve odd label formatting for recently opened #95

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

Merged
merged 1 commit into from
May 3, 2023
Merged
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
37 changes: 28 additions & 9 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export class Remote {

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

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

// Register the label formatter again because SSH overrides it!
let label = `${this.storage.workspace.owner_name}/${this.storage.workspace.name}`
if (agents.length > 1) {
label += `/${agent.name}`
}

const workspace = this.storage.workspace
const agentName = agents.length > 1 ? agent.name : undefined
disposables.push(
vscode.extensions.onDidChange(() => {
disposables.push(this.registerLabelFormatter(label))
disposables.push(this.registerLabelFormatter(remoteAuthority, workspace.owner_name, workspace.name, agentName))
}),
)

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

private registerLabelFormatter(suffix: string): vscode.Disposable {
private registerLabelFormatter(
remoteAuthority: string,
owner: string,
workspace: string,
agent?: string,
): vscode.Disposable {
// VS Code splits based on the separator when displaying the label
// in a recently opened dialog. If the workspace suffix contains /,
// then it'll visually display weird:
// "/home/kyle [Coder: kyle/workspace]" displays as "workspace] /home/kyle [Coder: kyle"
// For this reason, we use a different / that visually appears the
// same on non-monospace fonts "∕".
let suffix = `Coder: ${owner}∕${workspace}`
if (agent) {
suffix += `∕${agent}`
}
// VS Code caches resource label formatters in it's global storage SQLite database
// under the key "memento/cachedResourceLabelFormatters2".
return this.vscodeProposed.workspace.registerResourceLabelFormatter({
scheme: "vscode-remote",
// authority is optional but VS Code prefers formatters that most
// accurately match the requested authority, so we include it.
authority: remoteAuthority,
formatting: {
label: "${path}",
separator: "/",
tildify: true,
workspaceSuffix: `Coder: ${suffix}`,
workspaceSuffix: suffix,
},
})
}
Expand Down