Skip to content
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

Make it easier to add namespace from same server to workspace #1232

Merged
Merged
Show file tree
Hide file tree
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
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