mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Show codelens to ipynb json to open in notebook editor
This commit is contained in:
parent
b16832cd3a
commit
3567a2f2bc
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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'));
|
||||
|
|
Loading…
Reference in a new issue