Skip to content

Commit

Permalink
notebooks: add a button to search for a renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Sep 20, 2021
1 parent e53e1fe commit cc9e4e1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
const editorOptions = this.configurationService.getValue<ICodeEditorOptions>('editor');
this._fontInfo = readFontInfo(BareFontInfo.createFromRawSettings(editorOptions, getZoomLevel(), getPixelRatio()));
this._revealFirst = true;
this._outputRenderer = new OutputRenderer(this, this.instantiationService);
this._outputRenderer = this.instantiationService.createInstance(OutputRenderer, this);
}

toggleNotebookCellSelection(cell: IGenericCellViewModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
}));

const that = this;
this._outputRenderer = this._register(new OutputRenderer({
this._outputRenderer = this._register(this.instantiationService.createInstance(OutputRenderer, {
get creationOptions() { return that.creationOptions; },
getCellOutputLayoutInfo: that._getCellOutputLayoutInfo.bind(that)
}, this.instantiationService));
}));
this._scrollBeyondLastLine = this.configurationService.getValue<boolean>('editor.scrollBeyondLastLine');

this._register(this.configurationService.onDidChangeConfiguration(e => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { OutputRendererRegistry } from 'vs/workbench/contrib/notebook/browser/view/output/rendererRegistry';
import { Button } from 'vs/base/browser/ui/button/button';
import { onUnexpectedError } from 'vs/base/common/errors';
import { ICellOutputViewModel, IRenderOutput, RenderOutputType } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { dispose } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ICellOutputViewModel, IRenderOutput, RenderOutputType } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookDelegateForOutput, IOutputTransformContribution } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';
import { OutputRendererRegistry } from 'vs/workbench/contrib/notebook/browser/view/output/rendererRegistry';

export class OutputRenderer {

private readonly _richMimeTypeRenderers = new Map<string, IOutputTransformContribution>();

constructor(
private readonly notebookEditor: INotebookDelegateForOutput,
private readonly instantiationService: IInstantiationService
@IInstantiationService private readonly instantiationService: IInstantiationService,
@ICommandService private readonly commandservice: ICommandService,
) {
}
dispose(): void {
Expand Down Expand Up @@ -52,6 +55,27 @@ export class OutputRenderer {
return { type: RenderOutputType.Mainframe };
}

private _renderSearchForMimetype(container: HTMLElement, mimeType: string): IRenderOutput {
const disposable = new DisposableStore();

const contentNode = document.createElement('p');
contentNode.innerText = localize('noRenderer.1', "No renderer could be found for mimetype \"{0}\", but one might be available on the Marketplace.", mimeType);

const button = new Button(container);
button.label = localize('noRenderer.search', 'Search Marketplace');
button.element.style.maxWidth = `200px`;
disposable.add(button.onDidClick(() => this.commandservice.executeCommand('workbench.extensions.search', `@tag:notebookRenderer ${mimeType}`)));
disposable.add(button);

container.appendChild(contentNode);
container.appendChild(button.element);

return {
type: RenderOutputType.Mainframe,
disposable,
};
}

render(viewModel: ICellOutputViewModel, container: HTMLElement, preferredMimeType: string | undefined, notebookUri: URI): IRenderOutput {
this._initialize();
if (!viewModel.model.outputs.length) {
Expand All @@ -64,12 +88,12 @@ export class OutputRenderer {
}
if (!preferredMimeType || !this._richMimeTypeRenderers.has(preferredMimeType)) {
if (preferredMimeType) {
return this._renderMessage(container, localize('noRenderer.1', "No renderer could be found for mimetype: {0}", preferredMimeType));
return this._renderSearchForMimetype(container, preferredMimeType);
}
}
const renderer = this._richMimeTypeRenderers.get(preferredMimeType);
if (!renderer) {
return this._renderMessage(container, localize('noRenderer.1', "No renderer could be found for mimetype: {0}", preferredMimeType));
return this._renderSearchForMimetype(container, preferredMimeType);
}
const first = viewModel.model.outputs.find(op => op.mime === preferredMimeType);
if (!first) {
Expand Down
57 changes: 29 additions & 28 deletions src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,52 @@

import * as DOM from 'vs/base/browser/dom';
import { IListRenderer, IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
import { VSBuffer } from 'vs/base/common/buffer';
import { NotImplementedError } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { Mimes } from 'vs/base/common/mime';
import { URI } from 'vs/base/common/uri';
import { mock } from 'vs/base/test/common/mock';
import { EditorFontLigatures } from 'vs/editor/common/config/editorOptions';
import { FontInfo } from 'vs/editor/common/config/fontInfo';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IModeService } from 'vs/editor/common/services/modeService';
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { BrowserClipboardService } from 'vs/platform/clipboard/browser/clipboardService';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { NullCommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { IListService, ListService } from 'vs/platform/list/browser/listService';
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { UndoRedoService } from 'vs/platform/undoRedo/common/undoRedoService';
import { IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { EditorModel } from 'vs/workbench/common/editor/editorModel';
import { ICellViewModel, IActiveNotebookEditorDelegate, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { IActiveNotebookEditorDelegate, ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { ListViewInfoAccessor } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
import { NotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookCellList';
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
import { NotebookEventDispatcher } from 'vs/workbench/contrib/notebook/browser/viewModel/eventDispatcher';
import { CellViewModel, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { ViewContext } from 'vs/workbench/contrib/notebook/browser/viewModel/viewContext';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { CellKind, CellUri, INotebookDiffEditorModel, INotebookEditorModel, IOutputDto, IResolvedNotebookEditorModel, NotebookCellMetadata, SelectionStateType, } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellUri, INotebookDiffEditorModel, INotebookEditorModel, IOutputDto, IResolvedNotebookEditorModel, NotebookCellMetadata, SelectionStateType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { UndoRedoService } from 'vs/platform/undoRedo/common/undoRedoService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { NotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookCellList';
import { ListViewInfoAccessor } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
import { mock } from 'vs/base/test/common/mock';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { BrowserClipboardService } from 'vs/platform/clipboard/browser/clipboardService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
import { IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust';
import { TestWorkspaceTrustRequestService } from 'vs/workbench/services/workspaces/test/common/testWorkspaceTrustService';
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
import { ViewContext } from 'vs/workbench/contrib/notebook/browser/viewModel/viewContext';
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
import { Mimes } from 'vs/base/common/mime';
import { VSBuffer } from 'vs/base/common/buffer';
import { FontInfo } from 'vs/editor/common/config/fontInfo';
import { EditorFontLigatures } from 'vs/editor/common/config/editorOptions';
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';

export class TestCell extends NotebookCellTextModel {
constructor(
Expand Down Expand Up @@ -271,7 +272,7 @@ function _createTestNotebookEditor(instantiationService: TestInstantiationServic
}, true)
};
}
}, instantiationService);
}, instantiationService, NullCommandService);
}
override async layoutNotebookCell() { }
override async removeInset() { }
Expand Down

0 comments on commit cc9e4e1

Please sign in to comment.