vscode: Content providers do not have `exclusive` property on vscode.dev

Version: 1.64.2 Commit: f80445acd5a3dadef24aa209168452a3d97cc326 Date: 2022-02-09T22:00:24.333Z Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.50

Live Share Jupyter notebooks in vscode.dev are currently broken because the Live Share content provider is not being used to open the files. Rather, the built-in vscode.dev Jupyter notebooks provider is being used.

We used to use the exclusive flag in NotebookRegistrationData to mark a content provider as the default one for a file type. PR here: https://github.com/microsoft/vscode/commit/f5b2c93911a4c8115387c297db61e1d1efc71d96. When I made a repro extension, vscode.proposed.notebookContentProvider.d.ts:registerNotebookContentProvider does not include a parameter for NotebookRegistrationData, so it looks like that option has been removed?

We need a way to mark Live Share content providers as ‘default’ or ‘exclusive’ so that they are used rather than the built-in ones.

This extension creates a content provider for *.ipynb files, but when opening one on web, the file automatically opens and shows the built-in default was selected: image

extension.ts

import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
	const contentProvider = new NotebookContentProvider('ally-vsls');
	context.subscriptions.push(vscode.workspace.registerNotebookContentProvider(
		'ally-vsls',
		contentProvider,
		{
			transientOutputs: false,
			transientCellMetadata: {},
			transientDocumentMetadata: {}
		}
	));
	context.subscriptions.push(vscode.workspace.onDidOpenNotebookDocument((document: vscode.NotebookDocument) => onDidOpenNotebookDocument(document)));
}
export function deactivate() {}
class NotebookContentProvider implements vscode.NotebookContentProvider {
    constructor(private readonly viewType: string) {}
    async openNotebook(uri: vscode.Uri): Promise<vscode.NotebookData> {
        let metadata = {};
        return {cells: [ new vscode.NotebookCellData(vscode.NotebookCellKind.Code, 'Ally\'s Content Provider', 'cpp')], metadata: metadata};
    }
    async saveNotebook(): Promise<void> { }
    async saveNotebookAs(): Promise<void> { }
    async backupNotebook(): Promise<vscode.NotebookDocumentBackup> { return { id: '', delete: () => { } }; }
}

cc @rebornix

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Yes, the fix works.

I would expect ally-vsls to conflict with the built-in python content provider because they both have the same filenamePattern *.ipynb

We do support that - you can have multiple possible editors for a file type. Unless “exclusive” is used, VS Code allows you to open a file with any of them and also allows to reopen a file with another editor. Notebooks also support that. What’s not supported is

  • define the same notebook type multiple times, e.g you can have {"type": "ally-notebook", "selector": [{"filenamePattern": "*.ipynb" }]} and {"type": "jupyter-notebook", "selector": [{"filenamePattern": "*.ipynb" }]} because the type property is different but you cannot reuse the same type property
  • you can reopen notebooks with different serialisers (different notebook types) but one file can only opened as one notebook type at a time.

https://github.com/microsoft/vscode/blob/4a130c40ed876644ed8af2943809d08221375408/src/vscode-dts/vscode.proposed.notebookLiveShare.d.ts#L13

@alyssajotice The exclusive flag is now in notebookLiveShare proposed api so you may need to add that to you enable proposed api list.