diff --git a/package.json b/package.json index b613dc2..5290ca4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "servermanager", "displayName": "InterSystems Server Manager", - "version": "2.0.0-SNAPSHOT.2", + "version": "2.0.0-SNAPSHOT.3", "publisher": "intersystems-community", "description": "Helper extension for defining connections to InterSystems servers.", "repository": { @@ -297,6 +297,16 @@ { "command": "intersystems-community.servermanager.resetIconColor", "title": "default" + }, + { + "command": "intersystems-community.servermanager.editNamespace", + "title": "Edit Code in Namespace", + "icon": "$(edit)" + }, + { + "command": "intersystems-community.servermanager.viewNamespace", + "title": "View Code in Namespace", + "icon": "$(eye)" } ], "submenus": [ @@ -391,6 +401,16 @@ "when": "view == intersystems-community_servermanager && viewItem == starred.server.starred", "group": "inline@10" }, + { + "command": "intersystems-community.servermanager.editNamespace", + "when": "view == intersystems-community_servermanager && viewItem =~ /namespace$/", + "group": "inline@10" + }, + { + "command": "intersystems-community.servermanager.viewNamespace", + "when": "view == intersystems-community_servermanager && viewItem =~ /namespace$/", + "group": "inline@20" + }, { "command": "intersystems-community.servermanager.openPortalTab", "when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\./", diff --git a/src/extension.ts b/src/extension.ts index b15df35..b9847f6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -187,6 +187,43 @@ export function activate(context: vscode.ExtensionContext) { }) ); + const addWorkspaceFolderAsync = async (readonly: boolean, namespaceTreeItem?: ServerTreeItem) => { + if (namespaceTreeItem) { + const pathParts = namespaceTreeItem.id?.split(':'); + if (pathParts && pathParts.length === 4) { + const serverName = pathParts[1]; + const namespace = pathParts[3]; + const serverSpec = await getServerSpec(serverName, undefined, undefined, true); + if (serverSpec) { + const uri = vscode.Uri.parse(`isfs${readonly ? "-readonly" : ""}://${serverName}:${namespace}/${serverSpec.webServer.pathPrefix || ''}`); + const label = `${serverName}:${namespace}${readonly ? " (read-only)" : ""}`; + const added = vscode.workspace.updateWorkspaceFolders( + vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders.length : 0, + 0, + { uri, name: label } + ); + // Switch to Explorer view so user sees the outcome + await vscode.commands.executeCommand("workbench.view.explorer"); + // Handle failure + if (added) { + await view.addToRecents(serverName); + } + else { + vscode.window.showErrorMessage(`Folder ${uri.toString()} could not be added. Maybe it already exists in the workspace.`, "Close") + } + } + } + } + } + + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.editNamespace`, async (namespaceTreeItem?: ServerTreeItem) => {await addWorkspaceFolderAsync(false, namespaceTreeItem)}) + ); + + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.viewNamespace`, async (namespaceTreeItem?: ServerTreeItem) => {await addWorkspaceFolderAsync(true, namespaceTreeItem)}) + ); + // Listen for relevant configuration changes context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => { if (e.affectsConfiguration('intersystems.servers') || e.affectsConfiguration('objectscript.conn')) {