提交 e3c3ea27 编写于 作者: R rebornix

Switch kernel info.

上级 b353f507
......@@ -1795,6 +1795,7 @@ declare module 'vscode' {
}
export interface NotebookKernel {
label: string;
preloads?: Uri[];
executeCell(document: NotebookDocument, cell: NotebookCell, token: CancellationToken): Promise<void>;
executeAllCells(document: NotebookDocument, token: CancellationToken): Promise<void>;
......
......@@ -134,8 +134,8 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
return;
}
async $registerNotebookKernel(extension: NotebookExtensionDescription, id: string, selectors: (string | IRelativePattern)[], preloads: UriComponents[]): Promise<void> {
const kernel = new MainThreadNotebookKernel(this._proxy, id, selectors, extension.id, URI.revive(extension.location), preloads.map(preload => URI.revive(preload)));
async $registerNotebookKernel(extension: NotebookExtensionDescription, id: string, label: string, selectors: (string | IRelativePattern)[], preloads: UriComponents[]): Promise<void> {
const kernel = new MainThreadNotebookKernel(this._proxy, id, label, selectors, extension.id, URI.revive(extension.location), preloads.map(preload => URI.revive(preload)));
this._notebookKernels.set(id, kernel);
this._notebookService.registerNotebookKernel(kernel);
return;
......@@ -345,6 +345,7 @@ export class MainThreadNotebookKernel implements INotebookKernelInfo {
constructor(
private readonly _proxy: ExtHostNotebookShape,
readonly id: string,
readonly label: string,
readonly selectors: (string | IRelativePattern)[],
readonly extension: ExtensionIdentifier,
readonly extensionLocation: URI,
......
......@@ -693,7 +693,7 @@ export interface MainThreadNotebookShape extends IDisposable {
$unregisterNotebookProvider(viewType: string): Promise<void>;
$registerNotebookRenderer(extension: NotebookExtensionDescription, type: string, selectors: INotebookMimeTypeSelector, handle: number, preloads: UriComponents[]): Promise<void>;
$unregisterNotebookRenderer(handle: number): Promise<void>;
$registerNotebookKernel(extension: NotebookExtensionDescription, id: string, selectors: (string | IRelativePattern)[], preloads: UriComponents[]): Promise<void>;
$registerNotebookKernel(extension: NotebookExtensionDescription, id: string, label: string, selectors: (string | IRelativePattern)[], preloads: UriComponents[]): Promise<void>;
$unregisterNotebookKernel(id: string): Promise<void>;
$tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[], renderers: number[]): Promise<boolean>;
$updateNotebookLanguages(viewType: string, resource: UriComponents, languages: string[]): Promise<void>;
......
......@@ -731,7 +731,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
this._notebookKernels.set(id, { kernel, extension });
const transformedSelectors = selectors.map(selector => typeConverters.GlobPattern.from(selector));
this._proxy.$registerNotebookKernel({ id: extension.identifier, location: extension.extensionLocation }, id, transformedSelectors, kernel.preloads || []);
this._proxy.$registerNotebookKernel({ id: extension.identifier, location: extension.extensionLocation }, id, kernel.label, transformedSelectors, kernel.preloads || []);
return new VSCodeDisposable(() => {
this._notebookKernels.delete(id);
this._proxy.$unregisterNotebookKernel(id);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { INotebookEditor, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IStatusbarService, IStatusbarEntryAccessor, IStatusbarEntry, StatusbarAlignment } from 'vs/workbench/services/statusbar/common/statusbar';
import { IQuickInputService, QuickPickInput, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import * as nls from 'vs/nls';
import { registerAction2, Action2 } from 'vs/platform/actions/common/actions';
import { NOTEBOOK_ACTIONS_CATEGORY, INotebookCellActionContext } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { INotebookKernelInfo } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { Registry } from 'vs/platform/registry/common/platform';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
export class NotebookEditorStatus extends Disposable implements IWorkbenchContribution {
private _localStore: DisposableStore = new DisposableStore();
private kernelInfoElement = this._register(new MutableDisposable<IStatusbarEntryAccessor>());
constructor(
@IEditorService private readonly editorService: IEditorService,
@IStatusbarService private readonly statusbarService: IStatusbarService,
) {
super();
this.registerListeners();
}
private registerListeners(): void {
this._register(this.editorService.onDidActiveEditorChange(() => this.updateStatusBar()));
this.updateStatusBar();
}
private async updateStatusBar(): Promise<void> {
this._localStore.clear();
const activeEditorPane = this.editorService.activeEditorPane as any | undefined;
if (!activeEditorPane?.isNotebookEditor) {
this.kernelInfoElement.clear();
return;
}
const editor = activeEditorPane.getControl() as INotebookEditor;
this._localStore.add(editor.onDidChangeKernel(() => {
this.updateKernelInfo(editor.activeKernel);
}));
this.updateKernelInfo(editor.activeKernel);
}
private updateKernelInfo(kernelInfo: INotebookKernelInfo | undefined) {
if (!kernelInfo) {
this.kernelInfoElement.clear();
return;
}
const props: IStatusbarEntry = {
text: kernelInfo.label,
ariaLabel: kernelInfo.label,
tooltip: nls.localize('selectKernel', "Select Notebook Kernel"),
command: 'notebook.selectKernel'
};
this.updateElement(this.kernelInfoElement, props, 'status.notebook.kernel', nls.localize('selectKernel', "Select Notebook Kernel"), StatusbarAlignment.RIGHT, 50);
}
private updateElement(element: MutableDisposable<IStatusbarEntryAccessor>, props: IStatusbarEntry, id: string, name: string, alignment: StatusbarAlignment, priority: number) {
if (!element.value) {
element.value = this.statusbarService.addEntry(props, id, name, alignment, priority);
} else {
element.value.update(props);
}
}
}
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(NotebookEditorStatus, LifecyclePhase.Eventually);
registerAction2(class extends Action2 {
constructor() {
super({
id: 'notebook.selectKernel',
category: NOTEBOOK_ACTIONS_CATEGORY,
title: nls.localize('notebookActions.selectKernel', "Select Notebook Kernel"),
precondition: ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_EDITOR_FOCUSED),
f1: true
});
}
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
const editorService = accessor.get<IEditorService>(IEditorService);
const notebookService = accessor.get<INotebookService>(INotebookService);
const quickInputService = accessor.get<IQuickInputService>(IQuickInputService);
const activeEditorPane = editorService.activeEditorPane as any | undefined;
if (!activeEditorPane?.isNotebookEditor) {
return;
}
const editor = activeEditorPane.getControl() as INotebookEditor;
const activeKernel = editor.activeKernel;
const availableKernels = notebookService.getContributedNotebookKernels(editor.viewModel!.viewType, editor.viewModel!.uri);
const picks: QuickPickInput<IQuickPickItem & { run(): void; }>[] = availableKernels.map((a) => {
return {
id: a.id,
label: a.label,
picked: a.id === activeKernel?.id,
description: a.extension.value + (a.id === activeKernel?.id
? nls.localize('currentActiveKernel', " (Currently Active)")
: ''),
run: () => {
editor.activeKernel = a;
}
};
});
const action = await quickInputService.pick(picks, { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true });
return action?.run();
}
});
......@@ -45,6 +45,7 @@ import 'vs/workbench/contrib/notebook/browser/contrib/fold/folding';
import 'vs/workbench/contrib/notebook/browser/contrib/format/formatting';
import 'vs/workbench/contrib/notebook/browser/contrib/toc/tocProvider';
import 'vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider';
import 'vs/workbench/contrib/notebook/browser/contrib/status/editorStatus';
// Output renderers registration
......
......@@ -23,7 +23,7 @@ import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/outpu
import { CellLanguageStatusBarItem, TimerRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer';
import { CellViewModel, IModelDecorationsChangeAccessor, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { CellKind, IOutput, IRenderOutput, NotebookCellMetadata, NotebookDocumentMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, IOutput, IRenderOutput, NotebookCellMetadata, NotebookDocumentMetadata, INotebookKernelInfo } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { Webview } from 'vs/workbench/contrib/webview/browser/webview';
import { ICompositeCodeEditor } from 'vs/editor/common/editorCommon';
......@@ -150,6 +150,8 @@ export interface INotebookEditor extends ICompositeCodeEditor {
*/
readonly onDidChangeModel: Event<void>;
isNotebookEditor: boolean;
activeKernel: INotebookKernelInfo | undefined;
readonly onDidChangeKernel: Event<void>;
getDomNode(): HTMLElement;
getInnerWebview(): Webview | undefined;
......
......@@ -105,6 +105,7 @@ export interface INotebookRendererInfo {
export interface INotebookKernelInfo {
id: string;
label: string,
selectors: (string | glob.IRelativePattern)[],
extension: ExtensionIdentifier;
extensionLocation: URI,
......
......@@ -19,7 +19,7 @@ import { NotebookEventDispatcher } from 'vs/workbench/contrib/notebook/browser/v
import { CellViewModel, IModelDecorationsChangeAccessor, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { CellKind, CellUri, INotebookEditorModel, IOutput, NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellUri, INotebookEditorModel, IOutput, NotebookCellMetadata, INotebookKernelInfo } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { Webview } from 'vs/workbench/contrib/webview/browser/webview';
import { ICompositeCodeEditor, IEditor } from 'vs/editor/common/editorCommon';
export class TestCell extends NotebookCellTextModel {
......@@ -43,6 +43,8 @@ export class TestNotebookEditor implements INotebookEditor {
constructor(
) { }
activeKernel: INotebookKernelInfo | undefined;
onDidChangeKernel: Event<void> = new Emitter<void>().event;
onDidChangeActiveEditor: Event<ICompositeCodeEditor> = new Emitter<ICompositeCodeEditor>().event;
activeCodeEditor: IEditor | undefined;
getDomNode(): HTMLElement {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册