From cbc6e75d6b06b37e8932a5060825f46c42d92533 Mon Sep 17 00:00:00 2001 From: gjsjohnmurray Date: Fri, 15 Sep 2023 13:41:45 +0100 Subject: [PATCH] Make it easier to add namespace from same server to workspace --- src/commands/addServerNamespaceToWorkspace.ts | 49 +++++++++++++++---- src/extension.ts | 4 +- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/commands/addServerNamespaceToWorkspace.ts b/src/commands/addServerNamespaceToWorkspace.ts index 48368d83..9e7463eb 100644 --- a/src/commands/addServerNamespaceToWorkspace.ts +++ b/src/commands/addServerNamespaceToWorkspace.ts @@ -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 { // Get its namespace list const uri = vscode.Uri.parse(`isfs://${serverName}:%sys/`); await resolveConnectionSpec(serverName); @@ -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 { - const picks = await pickServerAndNamespace("Adding a server namespace to a workspace"); - if (picks == undefined) { - return; +export async function addServerNamespaceToWorkspace(resource?: vscode.Uri): Promise { + 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( [ diff --git a/src/extension.ts b/src/extension.ts index 853accd9..8be9d6dd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -990,8 +990,8 @@ export async function activate(context: vscode.ExtensionContext): Promise { 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();