Add notebook open protocol handler (#6093)

Adds a protocol handler for notebook open, which can be used from browsers
Uses extension-based handler support so all URIs must start with `azuredatastudio://microsoft.notebook`

Adds 2 actions:
- `/new` opens a new empty notebook
- `/open` opens a HTTP/S file as an untitled notebook or text document

Sample URL:
```
azuredatastudio://microsoft.notebook/open?url=https%3A%2F%2Fraw.githubusercontent.com%2Fkevcunnane%2Fmsbuild_ads_demo%2Fmaster%2F0_YoAzdata.ipynb
```
This commit is contained in:
Kevin Cunnane
2019-06-20 11:00:24 -07:00
committed by GitHub
parent 72c3239d63
commit 578ac6cae5
3 changed files with 143 additions and 4 deletions

View File

@@ -13,7 +13,8 @@ import { AppContext } from './common/appContext';
import { ApiWrapper } from './common/apiWrapper';
import { IExtensionApi } from './types';
import { CellType } from './contracts/content';
import { getErrorMessage } from './common/utils';
import { getErrorMessage, isEditorTitleFree } from './common/utils';
import { NotebookUriHandler } from './protocol/notebookUriHandler';
const localize = nls.loadMessageBundle();
@@ -74,6 +75,8 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.analyzeNotebook', (explorerContext: azdata.ObjectExplorerContext) => {
analyzeNotebook(explorerContext);
}));
extensionContext.subscriptions.push(vscode.window.registerUriHandler(new NotebookUriHandler()));
let appContext = new AppContext(extensionContext, new ApiWrapper());
controller = new JupyterController(appContext);
@@ -112,9 +115,7 @@ function findNextUntitledEditorName(): string {
// Note: this will go forever if it's coded wrong, or you have infinite Untitled notebooks!
while (true) {
let title = `Notebook-${nextVal}`;
let hasTextDoc = vscode.workspace.textDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
let hasNotebookDoc = azdata.nb.notebookDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
if (!hasTextDoc && !hasNotebookDoc) {
if (isEditorTitleFree(title)) {
return title;
}
nextVal++;