Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | 1x 4x 4x 1x 1x 4x 3x 4x 1x 1x 3x 3x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import * as vscode from 'vscode';
import { container } from 'tsyringe';
import { ServiceToken } from '@src/services/tokens';
import { ISparqlConnectionService } from '@src/languages/sparql/services';
export const setNotebookConnection = {
id: 'mentor.command.setNotebookConnection',
handler: async (context?: any) => {
const connectionService = container.resolve<ISparqlConnectionService>(ServiceToken.SparqlConnectionService);
// Get the notebook from various possible argument types
let notebook: vscode.NotebookDocument | undefined;
if (context && typeof context === 'object') {
if ('notebook' in context && context.notebook) {
// Direct NotebookEditor from notebook toolbar
notebook = context.notebook;
} else if (E'notebookEditor' in context && context.notebookEditor) {
// From notebook toolbar context object
notebook = context.notebookEditor.notebook;
} else if ('scheme' in context && 'fsPath' in context) {
// URI passed
notebook = vscode.workspace.notebookDocuments.find(n => n.uri.toString() === context.toString());
}
}
// Fallback to active notebook editor
if (!notebook) {
notebook = vscode.window.activeNotebookEditor?.notebook;
}
if (!notebook) {
vscode.window.showWarningMessage('No notebook is currently open.');
return;
}
// Show quick pick to select connection
const connections = connectionService.getConnections();
if (connections.length === 0) {
vscode.window.showWarningMessage('No SPARQL connections configured.');
return;
}
const items = connections.map(connection => ({
label: `$(database) ${connection.endpointUrl}`,
description: connection.description,
connection
}));
const selected = await vscode.window.showQuickPick(items, {
placeHolder: 'Select SPARQL connection for all cells in this notebook'
});
Iif (!selected) {
return;
}
// Update all cells in the notebook
const cells = notebook.getCells();
const edits: vscode.NotebookEdit[] = [];
for (const cell of cells) {
const metadata = { ...cell.metadata, connectionId: selected.connection.id };
edits.push(vscode.NotebookEdit.updateCellMetadata(cell.index, metadata));
}
Eif (edits.length > 0) {
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(notebook.uri, edits);
await vscode.workspace.applyEdit(workspaceEdit);
// Notify listeners to refresh code lenses
connectionService.notifyDocumentConnectionChanged(notebook.uri);
}
vscode.window.setStatusBarMessage(
`Set connection to "${selected.connection.endpointUrl}" for all ${cells.length} cells`,
3000
);
}
};
|