Show codelens to ipynb json to open in notebook editor

This commit is contained in:
rebornix 2022-02-18 14:54:40 -08:00
parent b16832cd3a
commit 3567a2f2bc
No known key found for this signature in database
GPG key ID: 181FC90D15393C20
2 changed files with 32 additions and 0 deletions

View file

@ -32,6 +32,10 @@
{
"command": "ipynb.newUntitledIpynb",
"title": "Jupyter Notebook"
},
{
"command": "ipynb.openIpynbInNotebookEditor",
"title": "Open ipynb file in notebook editor"
}
],
"notebooks": [
@ -52,6 +56,16 @@
"command": "ipynb.newUntitledIpynb",
"when": "!jupyterEnabled"
}
],
"commandPalette": [
{
"command": "ipynb.newUntitledIpynb",
"when": "false"
},
{
"command": "ipynb.openIpynbInNotebookEditor",
"when": "false"
}
]
}
},

View file

@ -37,6 +37,16 @@ export function activate(context: vscode.ExtensionContext) {
}
}));
vscode.languages.registerCodeLensProvider({ pattern: '**/*.ipynb' }, {
provideCodeLenses: (document) => {
if (document.uri.scheme === 'vscode-notebook-cell') {
return [];
}
const codelens = new vscode.CodeLens(new vscode.Range(0, 0, 0, 0), { title: 'Open in Notebook Editor', command: 'ipynb.openIpynbInNotebookEditor', arguments: [document.uri] });
return [codelens];
}
});
context.subscriptions.push(vscode.commands.registerCommand('ipynb.newUntitledIpynb', async () => {
const language = 'python';
const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, '', language);
@ -55,6 +65,14 @@ export function activate(context: vscode.ExtensionContext) {
await vscode.window.showNotebookDocument(doc);
}));
context.subscriptions.push(vscode.commands.registerCommand('ipynb.openIpynbInNotebookEditor', async (uri: vscode.Uri) => {
if (vscode.window.activeTextEditor?.document.uri.toString() === uri.toString()) {
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
}
const document = await vscode.workspace.openNotebookDocument(uri);
await vscode.window.showNotebookDocument(document);
}));
// Update new file contribution
vscode.extensions.onDidChange(() => {
vscode.commands.executeCommand('setContext', 'jupyterEnabled', vscode.extensions.getExtension('ms-toolsai.jupyter'));