Skip to content

Commit

Permalink
allow opening notebooks via uris (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo authored Apr 15, 2021
1 parent 13a5243 commit e29a516
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/dotnet-interactive-vscode/common/vscode/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,20 @@ export function registerFileCommands(context: vscode.ExtensionContext, clientMap
}
}

if (jupyterApi) {
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'jupyter-notebook');
await switchToInteractiveKernel();
} else {
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'dotnet-interactive-jupyter');
const extension = path.extname(notebookUri.fsPath);
switch (extension) {
case '.ipynb':
if (jupyterApi) {

This comment has been minimized.

Copy link
@WhiteBlackGoose

WhiteBlackGoose Apr 16, 2021

Contributor

Might it be a good idea to have { on a separate line? Or it doesn't matter?

This comment has been minimized.

Copy link
@jonsequitur

jonsequitur Apr 16, 2021

Contributor

Same line is the more common convention in JavaScript and TypeScript.

This comment has been minimized.

Copy link
@WhiteBlackGoose

WhiteBlackGoose Apr 16, 2021

Contributor

Ohhhh, I'm sorry, I didn't notice that it's not C#. Wow, awesome how similar it looks

await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'jupyter-notebook');
await switchToInteractiveKernel();
} else {
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'dotnet-interactive-jupyter');
}
break;
default:
// was .dib or .dotnet-interactive
await vscode.commands.executeCommand('vscode.openWith', notebookUri, 'dotnet-interactive');
break;
}
}));

Expand Down
21 changes: 21 additions & 0 deletions src/dotnet-interactive-vscode/common/vscode/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ export async function activate(context: vscode.ExtensionContext) {
// this must happen early, because some following functions use the acquisition command
registerAcquisitionCommands(context, diagnosticsChannel);

vscode.window.registerUriHandler({
handleUri(uri: vscode.Uri): vscode.ProviderResult<void> {
switch (uri.path) {
case '/newNotebook':
vscode.commands.executeCommand('dotnet-interactive.acquire').then(() => {
vscode.commands.executeCommand('dotnet-interactive.newNotebook').then(() => { });
});
break;
case '/openNotebook':
const params = new URLSearchParams(uri.query);
const path = params.get('path');
if (path) {
vscode.commands.executeCommand('dotnet-interactive.acquire').then(() => {
vscode.commands.executeCommand('dotnet-interactive.openNotebook', vscode.Uri.file(path)).then(() => { });
});
}
break;
}
}
});

// register with VS Code
const clientMapper = new ClientMapper(async (notebookPath) => {
const minDotNetSdkVersion = config.get<string>('minimumDotNetSdkVersion') || '5.0';
Expand Down
3 changes: 2 additions & 1 deletion src/dotnet-interactive-vscode/insiders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"PowerShell"
],
"activationEvents": [
"onUri",
"onNotebook:dotnet-interactive",
"onNotebook:*",
"onCommand:dotnet-interactive.acquire",
Expand Down Expand Up @@ -103,7 +104,7 @@
},
"dotnet-interactive.minimumInteractiveToolVersion": {
"type": "string",
"default": "1.0.221403",
"default": "1.0.221503",
"description": "The minimum required version of the .NET Interactive tool."
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/dotnet-interactive-vscode/stable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"PowerShell"
],
"activationEvents": [
"onUri",
"onNotebook:dotnet-interactive",
"onNotebook:dotnet-interactive-jupyter",
"onNotebook:*",
Expand Down Expand Up @@ -112,7 +113,7 @@
},
"dotnet-interactive.minimumInteractiveToolVersion": {
"type": "string",
"default": "1.0.221403",
"default": "1.0.221503",
"description": "The minimum required version of the .NET Interactive tool."
},
"dotnet-interactive.useDotNetInteractiveExtensionForIpynbFiles": {
Expand Down

0 comments on commit e29a516

Please sign in to comment.