Skip to content

Commit e29a516

Browse files
authored
allow opening notebooks via uris (#1254)
1 parent 13a5243 commit e29a516

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/dotnet-interactive-vscode/common/vscode/commands.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,20 @@ export function registerFileCommands(context: vscode.ExtensionContext, clientMap
180180
}
181181
}
182182

183-
if (jupyterApi) {
184-
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'jupyter-notebook');
185-
await switchToInteractiveKernel();
186-
} else {
187-
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'dotnet-interactive-jupyter');
183+
const extension = path.extname(notebookUri.fsPath);
184+
switch (extension) {
185+
case '.ipynb':
186+
if (jupyterApi) {
187+
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'jupyter-notebook');
188+
await switchToInteractiveKernel();
189+
} else {
190+
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'dotnet-interactive-jupyter');
191+
}
192+
break;
193+
default:
194+
// was .dib or .dotnet-interactive
195+
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'dotnet-interactive');
196+
break;
188197
}
189198
}));
190199

src/dotnet-interactive-vscode/common/vscode/extension.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@ export async function activate(context: vscode.ExtensionContext) {
5656
// this must happen early, because some following functions use the acquisition command
5757
registerAcquisitionCommands(context, diagnosticsChannel);
5858

59+
vscode.window.registerUriHandler({
60+
handleUri(uri: vscode.Uri): vscode.ProviderResult<void> {
61+
switch (uri.path) {
62+
case '/newNotebook':
63+
vscode.commands.executeCommand('dotnet-interactive.acquire').then(() => {
64+
vscode.commands.executeCommand('dotnet-interactive.newNotebook').then(() => { });
65+
});
66+
break;
67+
case '/openNotebook':
68+
const params = new URLSearchParams(uri.query);
69+
const path = params.get('path');
70+
if (path) {
71+
vscode.commands.executeCommand('dotnet-interactive.acquire').then(() => {
72+
vscode.commands.executeCommand('dotnet-interactive.openNotebook', vscode.Uri.file(path)).then(() => { });
73+
});
74+
}
75+
break;
76+
}
77+
}
78+
});
79+
5980
// register with VS Code
6081
const clientMapper = new ClientMapper(async (notebookPath) => {
6182
const minDotNetSdkVersion = config.get<string>('minimumDotNetSdkVersion') || '5.0';

src/dotnet-interactive-vscode/insiders/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"PowerShell"
4141
],
4242
"activationEvents": [
43+
"onUri",
4344
"onNotebook:dotnet-interactive",
4445
"onNotebook:*",
4546
"onCommand:dotnet-interactive.acquire",
@@ -103,7 +104,7 @@
103104
},
104105
"dotnet-interactive.minimumInteractiveToolVersion": {
105106
"type": "string",
106-
"default": "1.0.221403",
107+
"default": "1.0.221503",
107108
"description": "The minimum required version of the .NET Interactive tool."
108109
}
109110
}

src/dotnet-interactive-vscode/stable/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"PowerShell"
4141
],
4242
"activationEvents": [
43+
"onUri",
4344
"onNotebook:dotnet-interactive",
4445
"onNotebook:dotnet-interactive-jupyter",
4546
"onNotebook:*",
@@ -112,7 +113,7 @@
112113
},
113114
"dotnet-interactive.minimumInteractiveToolVersion": {
114115
"type": "string",
115-
"default": "1.0.221403",
116+
"default": "1.0.221503",
116117
"description": "The minimum required version of the .NET Interactive tool."
117118
},
118119
"dotnet-interactive.useDotNetInteractiveExtensionForIpynbFiles": {

0 commit comments

Comments
 (0)