Skip to content

Commit 59eb220

Browse files
committed
Don't open a folder by default when launching a workspace
Fixes #20.
1 parent 66be22e commit 59eb220

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

src/commands.ts

+31-21
Original file line numberDiff line numberDiff line change
@@ -152,37 +152,47 @@ export class Commands {
152152

153153
// A workspace can have multiple agents, but that's handled
154154
// when opening a workspace unless explicitly specified.
155-
let uri = vscode.Uri.parse(`vscode-remote://ssh-remote+${Remote.Prefix}${workspaceOwner}--${workspaceName}/`)
155+
const remoteAuthority = `ssh-remote+${Remote.Prefix}${workspaceOwner}--${workspaceName}`
156156

157157
const output: {
158158
workspaces: { folderUri: vscode.Uri; remoteAuthority: string }[]
159159
} = await vscode.commands.executeCommand("_workbench.getRecentlyOpened")
160160
const opened = output.workspaces.filter(
161161
// Filter out `/` since that's added below.
162-
(opened) => opened.folderUri?.authority === uri.authority && uri.path !== "/",
162+
(opened) => opened.folderUri?.authority === remoteAuthority,
163163
)
164-
// Always add `/` as an option to open. If we don't, it can become hard
165-
// to open multiple VS Code windows.
166-
opened.splice(0, 0, {
167-
folderUri: uri,
168-
remoteAuthority: "coder",
169-
})
170-
if (opened.length > 1) {
171-
const items: vscode.QuickPickItem[] = opened.map((folder): vscode.QuickPickItem => {
172-
return {
173-
label: folder.folderUri.fsPath,
164+
if (opened.length > 0) {
165+
let selected: typeof opened[0]
166+
167+
if (opened.length > 1) {
168+
const items: vscode.QuickPickItem[] = opened.map((folder): vscode.QuickPickItem => {
169+
return {
170+
label: folder.folderUri.fsPath,
171+
}
172+
})
173+
const item = await vscode.window.showQuickPick(items, {
174+
title: "Select a recently opened folder",
175+
})
176+
if (!item) {
177+
return
174178
}
175-
})
176-
const item = await vscode.window.showQuickPick(items, {
177-
title: "Select a recently opened folder",
178-
})
179-
if (!item) {
180-
return
179+
selected = opened[items.indexOf(item)]
180+
} else {
181+
selected = opened[0]
181182
}
182-
const selected = opened[items.indexOf(item)]
183-
uri = vscode.Uri.joinPath(uri, selected.folderUri.path)
183+
184+
await vscode.commands.executeCommand(
185+
"vscode.openFolder",
186+
vscode.Uri.from({
187+
scheme: "vscode-remote",
188+
authority: remoteAuthority,
189+
path: selected.folderUri.path,
190+
}),
191+
)
192+
return
184193
}
185194

186-
await vscode.commands.executeCommand("vscode.openFolder", uri)
195+
// This opens the workspace without an active folder opened.
196+
await vscode.commands.executeCommand("vscode.newWindow", { remoteAuthority: remoteAuthority, reuseWindow: true })
187197
}
188198
}

src/extension.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,9 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
7878
// Since the "onResolveRemoteAuthority:ssh-remote" activation event exists
7979
// in package.json we're able to perform actions before the authority is
8080
// resolved by the remote SSH extension.
81-
const activeRemotes = vscode.workspace.workspaceFolders?.filter((folder) => folder.uri.scheme === "vscode-remote")
82-
// If the currently opened folder isn't remote we can return early!
83-
if (activeRemotes?.length !== 1) {
81+
if (!vscodeProposed.env.remoteAuthority) {
8482
return
8583
}
86-
const activeRemote = activeRemotes[0].uri
87-
88-
ctx.globalStorageUri
89-
9084
const remote = new Remote(vscodeProposed, storage, ctx.extensionMode)
91-
await remote.setup(activeRemote)
85+
await remote.setup(vscodeProposed.env.remoteAuthority)
9286
}

src/remote.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export class Remote {
3232
private readonly mode: vscode.ExtensionMode,
3333
) {}
3434

35-
public async setup(uri: vscode.Uri): Promise<vscode.Disposable | undefined> {
36-
const authorityParts = uri.authority.split("+")
35+
public async setup(remoteAuthority: string): Promise<vscode.Disposable | undefined> {
36+
const authorityParts = remoteAuthority.split("+")
3737
// If the URI passed doesn't have the proper prefix
3838
// ignore it. We don't need to do anything special,
3939
// because this isn't trying to open a Coder workspace.
@@ -110,7 +110,7 @@ export class Remote {
110110
await this.closeRemote()
111111
}
112112
await vscode.commands.executeCommand("coder.login", this.storage.getURL())
113-
await this.setup(uri)
113+
await this.setup(remoteAuthority)
114114
return
115115
}
116116
default:

0 commit comments

Comments
 (0)