Skip to content

Commit

Permalink
Remove Server Manager tree integration experiment
Browse files Browse the repository at this point in the history
It used unstable API from the Jupyter extension which isn't likely to stabilize (see microsoft/vscode-jupyter#16221)
  • Loading branch information
gjsjohnmurray committed Nov 15, 2024
1 parent d2186ef commit af855bc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 116 deletions.
22 changes: 0 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,6 @@
]
}
],
"commands": [
{
"command": "iris-jupyter-server.intersystems-servermanager.newNotebook",
"title": "New Notebook",
"icon": "$(notebook)"
}
],
"menus": {
"view/item/context": [
{
"command": "iris-jupyter-server.intersystems-servermanager.newNotebook",
"when": "view == intersystems-community_servermanager && viewItem =~ /namespace$/",
"group": "inline@26"
}
],
"commandPalette": [
{
"command": "iris-jupyter-server.intersystems-servermanager.newNotebook",
"when": "false"
}
]
},
"configuration": {
"title": "IRIS Jupyter Server",
"properties": {
Expand Down
94 changes: 0 additions & 94 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,100 +306,6 @@ export async function activate(context: vscode.ExtensionContext) {
};


// The command we add to the Server Manager tree at the namespace level
context.subscriptions.push(vscode.commands.registerCommand('iris-jupyter-server.intersystems-servermanager.newNotebook', async (serverTreeItem) => {
const idArray: string[] = serverTreeItem.id.split(':');
const serverId = idArray[1];
const namespace = idArray[3];
const serverNamespace = `${serverId}:${namespace}`;
let firstCall = false;

if (!jupyterKernelService) {
firstCall = true;
jupyterKernelService = await jupyterApi.getKernelService();
if (!jupyterKernelService) {
vscode.window.showErrorMessage('Cannot access jupyterApi.getKernelService() - try using VS Code Insiders');
return;
}
jupyterKernelService.onDidChangeKernelSpecifications(() => {
console.log('Kernel specs changed');
});
}

await vscode.commands.executeCommand('ipynb.newUntitledIpynb');
const nbEditor = vscode.window.activeNotebookEditor;
if (!nbEditor) {
return;
}
const nbUri = nbEditor.notebook.uri;

const SECONDS_TO_WAIT = 5;
if (firstCall) {
const waitMessageCell = new vscode.NotebookCellData(vscode.NotebookCellKind.Markup, `Please wait ${SECONDS_TO_WAIT} seconds while your first IRIS notebook initializes...`, 'markdown');
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(nbUri, [new vscode.NotebookEdit(new vscode.NotebookRange(0, nbEditor.notebook.cellCount), [waitMessageCell])]);
await vscode.workspace.applyEdit(workspaceEdit);
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: `Waiting ${SECONDS_TO_WAIT} seconds for IRIS Notebook Servers to be ready...` }, async (progress) => {
for (let i = 0; i < SECONDS_TO_WAIT; i++) {
progress.report({ increment: Math.ceil(100 / SECONDS_TO_WAIT) });
await new Promise(resolve => setTimeout(resolve, 1_000));
}
});
}

const kernelConnectionMetadataArray = await jupyterKernelService.getKernelSpecifications();

// What to find
const kind = 'startUsingRemoteKernelSpec';
const baseUrl = jupyterServer(serverNamespace).connectionInformation?.baseUrl?.toString(true) || '';
const kernelSpecName = 'iris-objectscript';

// Find it
const kernelConnectionMetadata = kernelConnectionMetadataArray.find((item: any) => item.kind === kind && item.baseUrl === baseUrl && item.kernelSpec.name === kernelSpecName);
if (!kernelConnectionMetadata) {

const hosts = vscode.workspace.getConfiguration('iris-jupyter-server').get<IHosts>('hosts') || {};
if (!hosts[serverNamespace]?.enabled) {
const serverSpec = await serverManagerApi.getServerSpec(serverId);
if (!serverSpec?.superServer?.port) {
const errorMessageCell = new vscode.NotebookCellData(vscode.NotebookCellKind.Markup, `To operate as an IRIS Notebook Host the **${serverId}** server definition requires its superserver port number.`, 'markdown');
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(nbUri, [new vscode.NotebookEdit(new vscode.NotebookRange(0, nbEditor.notebook.cellCount), [errorMessageCell])]);
await vscode.workspace.applyEdit(workspaceEdit);
return;
}
await vscode.workspace.getConfiguration('iris-jupyter-server').update('hosts', { ...hosts, [serverNamespace]: { enabled: true } }, vscode.ConfigurationTarget.Global);
}


const mdMessage =
`# First Time Use on ${serverNamespace}
The IRIS Notebook Host **${serverNamespace}** must initially be accessed from the notebook kernel picker.
## Instructions
1. Click the button in the top right of this notebook, captioned either **Select Kernel** or **Detecting Kernels**.
2. If the next picker is titled 'Select Kernel' choose **IRIS Notebook Servers...**. Otherwise choose **Select Another Kernel...**, then choose **IRIS Notebook Servers...** from that picker.
4. Choose **${serverNamespace}** from the picker titled 'Select a Jupyter Server'.
5. When the picker titled 'Select a Kernel from ${serverNamespace}' is populated wait a couple of seconds, then press the 'Esc' key while focus is on its input field.
6. Back on the INTERSYSTEMS: SERVERS view click again on the **New Notebook** button of the **${namespace}** namespace folder under the **${serverId}** server.
You can then close and discard the original notebook containing these instructions.
`;
const waitMessageCell = new vscode.NotebookCellData(vscode.NotebookCellKind.Markup, mdMessage, 'markdown');
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(nbUri, [new vscode.NotebookEdit(new vscode.NotebookRange(0, nbEditor.notebook.cellCount), [waitMessageCell])]);
await vscode.workspace.applyEdit(workspaceEdit);
return;
}
await jupyterApi.openNotebook(nbUri, kernelConnectionMetadata.id);
const welcomeMessageCell = new vscode.NotebookCellData(vscode.NotebookCellKind.Markup, `New IRIS ObjectScript notebook connected to **${serverNamespace}**`, 'markdown');
const infoCell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, ' WRITE "Process ", $JOB, " in namespace ", $NAMESPACE, " on server ", $SYSTEM, " (", $ZVERSION, ")",!', 'objectscript-int');
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(nbUri, [new vscode.NotebookEdit(new vscode.NotebookRange(0, nbEditor.notebook.cellCount), [welcomeMessageCell, infoCell])]);
await vscode.workspace.applyEdit(workspaceEdit);
await vscode.commands.executeCommand('notebook.execute');
}));

// Return the JupyterServer object for a given server:NAMESPACE
function jupyterServer(serverNamespace: string): JupyterServer {
return {
Expand Down

0 comments on commit af855bc

Please sign in to comment.