Skip to content

Commit

Permalink
Make it easier to add namespace from same server to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsjohnmurray committed Sep 15, 2023
1 parent 0d8ecb1 commit cbc6e75
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
49 changes: 40 additions & 9 deletions src/commands/addServerNamespaceToWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export async function pickServerAndNamespace(message?: string): Promise<{ server
if (!serverName) {
return;
}
const namespace = await pickNamespaceOnServer(serverName);
if (!namespace) {
return;
}
return { serverName, namespace };
}

async function pickNamespaceOnServer(serverName: string): Promise<string> {
// Get its namespace list
const uri = vscode.Uri.parse(`isfs://${serverName}:%sys/`);
await resolveConnectionSpec(serverName);
Expand Down Expand Up @@ -69,18 +77,41 @@ export async function pickServerAndNamespace(message?: string): Promise<{ server
placeHolder: `Namespace on server '${serverName}' (${connDisplayString})`,
ignoreFocusOut: true,
});
if (!namespace) {
return;
}
return { serverName, namespace };
return namespace;
}

export async function addServerNamespaceToWorkspace(): Promise<void> {
const picks = await pickServerAndNamespace("Adding a server namespace to a workspace");
if (picks == undefined) {
return;
export async function addServerNamespaceToWorkspace(resource?: vscode.Uri): Promise<void> {
const TITLE = "Add server namespace to workspace";
let serverName = "";
let namespace = "";
if (filesystemSchemas.includes(resource?.scheme)) {
serverName = resource.authority.split(":")[0];
if (serverName) {
const ANOTHER = "Choose another server";
const choice = await vscode.window.showQuickPick([`Add a '${serverName}' namespace`, ANOTHER], {
title: TITLE,
});
if (!choice) {
return;
}
if (choice === ANOTHER) {
serverName = "";
}
}
}
if (serverName === "") {
const picks = await pickServerAndNamespace(TITLE);
if (picks == undefined) {
return;
}
serverName = picks.serverName;
namespace = picks.namespace;
} else {
namespace = await pickNamespaceOnServer(serverName);
if (!namespace) {
return;
}
}
const { serverName, namespace } = picks;
// Prompt the user for edit or read-only
const mode = await vscode.window.showQuickPick(
[
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
vscode.commands.registerCommand("vscode-objectscript.previewXml", () => {
xml2doc(context, vscode.window.activeTextEditor);
}),
vscode.commands.registerCommand("vscode-objectscript.addServerNamespaceToWorkspace", () => {
addServerNamespaceToWorkspace();
vscode.commands.registerCommand("vscode-objectscript.addServerNamespaceToWorkspace", (resource?: vscode.Uri) => {
addServerNamespaceToWorkspace(resource);
}),
vscode.commands.registerCommand("vscode-objectscript.connectFolderToServerNamespace", () => {
connectFolderToServerNamespace();
Expand Down

0 comments on commit cbc6e75

Please sign in to comment.