Skip to content

Commit bc2c136

Browse files
Debug Attach: fix process picker error (#1412)
1 parent aadc148 commit bc2c136

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/extension.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,42 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
934934
}),
935935
vscode.commands.registerCommand("vscode-objectscript.pickProcess", async (config) => {
936936
const system = config.system;
937-
const api = new AtelierAPI(vscode.window.activeTextEditor?.document.uri);
937+
let connectionUri = vscode.window.activeTextEditor?.document.uri;
938+
if (connectionUri) {
939+
// Ignore active editor if its document is outside the workspace (e.g. user settings.json)
940+
connectionUri = vscode.workspace.getWorkspaceFolder(connectionUri)?.uri;
941+
}
942+
if (!connectionUri) {
943+
// May need to ask the user
944+
const workspaceFolders = vscode.workspace.workspaceFolders || [];
945+
if (workspaceFolders.length == 0) {
946+
vscode.window.showErrorMessage(`Attaching to a server process requires a workspace to be open.`, {
947+
modal: true,
948+
});
949+
return;
950+
}
951+
if (workspaceFolders.length == 1) {
952+
connectionUri = workspaceFolders[0].uri;
953+
} else {
954+
// Pick from the workspace folders
955+
connectionUri = (
956+
await vscode.window.showWorkspaceFolderPick({
957+
ignoreFocusOut: true,
958+
placeHolder: "Pick the workspace folder to get server connection information from",
959+
})
960+
)?.uri;
961+
}
962+
}
963+
if (!connectionUri) {
964+
return;
965+
}
966+
const api = new AtelierAPI(connectionUri);
967+
if (!api.active) {
968+
vscode.window.showErrorMessage(`No active server connection.`, {
969+
modal: true,
970+
});
971+
return;
972+
}
938973

939974
const list = await api.getJobs(system).then(async (jobData) => {
940975
// NOTE: We do not know if the current user has permissions to other namespaces
@@ -969,14 +1004,14 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
9691004
});
9701005
});
9711006
if (!list.length) {
972-
vscode.window.showInformationMessage(`No attachable processes are running in ${api.ns}.`, {
1007+
vscode.window.showInformationMessage(`No attachable processes are running in ${api.ns} on '${api.serverId}'.`, {
9731008
modal: true,
9741009
});
9751010
return;
9761011
}
9771012
return vscode.window
9781013
.showQuickPick<vscode.QuickPickItem>(list, {
979-
placeHolder: "Pick the process to attach to",
1014+
placeHolder: `Pick the process to attach to in ${api.ns} on '${api.serverId}'`,
9801015
matchOnDescription: true,
9811016
})
9821017
.then((value) => {

0 commit comments

Comments
 (0)