提交 ff5e7462 编写于 作者: R rebornix

activate extension by notebook view type

上级 62f68fec
......@@ -19,7 +19,8 @@
"Other"
],
"activationEvents": [
"*"
"onNotebookEditor:jupyter",
"onNotebookEditor:jupytertest"
],
"contributes": {
"commands": [
......
......@@ -288,7 +288,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
return input.resolve();
})
.then(async model => {
if (this.model !== undefined && this.model.textModel === model.textModel && this.webview !== null) {
if (this.model !== undefined && this.model === model && this.webview !== null) {
return;
}
......
......@@ -4,8 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { EditorInput, EditorModel, IEditorInput, GroupIdentifier, ISaveOptions } from 'vs/workbench/common/editor';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { ITextModel } from 'vs/editor/common/model';
import { Emitter, Event } from 'vs/base/common/event';
import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { INotebook, ICell, NotebookCellsSplice } from 'vs/workbench/contrib/notebook/common/notebookCommon';
......@@ -21,8 +19,7 @@ export class NotebookEditorModel extends EditorModel {
get onDidChangeCells(): Event<NotebookCellsSplice[]> { return this._onDidChangeCells.event; }
constructor(
public readonly textModel: ITextModel,
private _notebook: INotebook | undefined
private _notebook: INotebook
) {
super();
......@@ -44,16 +41,9 @@ export class NotebookEditorModel extends EditorModel {
}
getNotebook(): INotebook {
if (this._notebook) {
return this._notebook;
}
// TODO, remove file based notebook from core
let content = this.textModel.getValue();
this._notebook = JSON.parse(content);
return this._notebook!;
}
insertCell(cell: ICell, index: number) {
let notebook = this.getNotebook();
......@@ -100,8 +90,7 @@ export class NotebookEditorInput extends EditorInput {
public resource: URI,
public name: string,
public readonly viewType: string | undefined,
@INotebookService private readonly notebookService: INotebookService,
@ITextModelService private readonly textModelResolverService: ITextModelService
@INotebookService private readonly notebookService: INotebookService
) {
super();
}
......@@ -128,18 +117,12 @@ export class NotebookEditorInput extends EditorInput {
return undefined;
}
resolve(): Promise<NotebookEditorModel> {
async resolve(): Promise<NotebookEditorModel> {
if (!this.promise) {
this.promise = this.textModelResolverService.createModelReference(this.resource)
.then(async ref => {
const textModel = ref.object.textEditorModel;
let notebook: INotebook | undefined = undefined;
if (this.viewType !== undefined) {
notebook = await this.notebookService.resolveNotebook(this.viewType, this.resource);
}
await this.notebookService.canResolve(this.viewType!);
this.textModel = new NotebookEditorModel(textModel, notebook);
this.promise = this.notebookService.resolveNotebook(this.viewType!, this.resource).then(notebook => {
this.textModel = new NotebookEditorModel(notebook!);
this.textModel.onDidChangeDirty(() => this._onDidChangeDirty.fire());
return this.textModel;
});
......
......@@ -11,6 +11,7 @@ import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/noteb
import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.protocol';
import { Emitter, Event } from 'vs/base/common/event';
import { INotebook, ICell, INotebookMimeTypeSelector } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
function MODEL_ID(resource: URI): string {
return resource.toString();
......@@ -30,6 +31,7 @@ export interface IMainNotebookController {
export interface INotebookService {
_serviceBrand: undefined;
canResolve(viewType: string): Promise<void>;
onDidChangeActiveEditor: Event<{ viewType: string, uri: URI }>;
registerNotebookController(viewType: string, extensionData: NotebookExtensionDescription, controller: IMainNotebookController): void;
unregisterNotebookProvider(viewType: string): void;
......@@ -97,8 +99,11 @@ export class NotebookService extends Disposable implements INotebookService {
private readonly _models: { [modelId: string]: ModelData; };
private _onDidChangeActiveEditor = new Emitter<{ viewType: string, uri: URI }>();
onDidChangeActiveEditor: Event<{ viewType: string, uri: URI }> = this._onDidChangeActiveEditor.event;
private _resolvePool = new Map<string, () => void>();
constructor() {
constructor(
@IExtensionService private readonly extensionService: IExtensionService
) {
super();
this._models = {};
......@@ -119,8 +124,27 @@ export class NotebookService extends Disposable implements INotebookService {
}
async canResolve(viewType: string): Promise<void> {
if (this._notebookProviders.has(viewType)) {
return;
}
this.extensionService.activateByEvent(`onNotebookEditor:${viewType}`);
let resolve: () => void;
const promise = new Promise<void>(r => { resolve = r; });
this._resolvePool.set(viewType, resolve!);
return promise;
}
registerNotebookController(viewType: string, extensionData: NotebookExtensionDescription, controller: IMainNotebookController) {
this._notebookProviders.set(viewType, { extensionData, controller });
let resolve = this._resolvePool.get(viewType);
if (resolve) {
resolve();
this._resolvePool.delete(viewType);
}
}
unregisterNotebookProvider(viewType: string): void {
......
......@@ -5,7 +5,7 @@
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IResourceInput, ITextEditorOptions, IEditorOptions, EditorActivation } from 'vs/platform/editor/common/editor';
import { SideBySideEditor as SideBySideEditorChoice, IEditorInput, IEditor, GroupIdentifier, IFileEditorInput, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, IFileInputFactory, EditorInput, SideBySideEditorInput, IEditorInputWithOptions, isEditorInputWithOptions, EditorOptions, TextEditorOptions, IEditorIdentifier, IEditorCloseEvent, ITextEditor, ITextDiffEditor, ITextSideBySideEditor, IRevertOptions, SaveReason, EditorsOrder, isTextEditor, ICompositeCodeEditor, IWorkbenchEditorConfiguration, toResource } from 'vs/workbench/common/editor';
import { SideBySideEditor as SideBySideEditorChoice, IEditorInput, IEditor, GroupIdentifier, IFileEditorInput, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, EditorInput, SideBySideEditorInput, IEditorInputWithOptions, isEditorInputWithOptions, EditorOptions, TextEditorOptions, IEditorIdentifier, IEditorCloseEvent, ITextEditor, ITextDiffEditor, ITextSideBySideEditor, IRevertOptions, SaveReason, EditorsOrder, isTextEditor, ICompositeCodeEditor, IWorkbenchEditorConfiguration, toResource } from 'vs/workbench/common/editor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { Registry } from 'vs/platform/registry/common/platform';
import { ResourceMap } from 'vs/base/common/map';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册