提交 b64d2985 编写于 作者: R rebornix

notebook respect editor association

上级 7f5bada0
......@@ -31,6 +31,10 @@ import { CellKind, CellUri } from 'vs/workbench/contrib/notebook/common/notebook
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { CustomEditorsAssociations, customEditorsAssociationsSettingId } from 'vs/workbench/services/editor/common/editorAssociationsSetting';
import { coalesce, distinct } from 'vs/base/common/arrays';
import { CustomEditorInfo } from 'vs/workbench/contrib/customEditor/common/customEditor';
// Editor Contribution
......@@ -96,7 +100,8 @@ export class NotebookContribution implements IWorkbenchContribution {
constructor(
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService,
@IInstantiationService private readonly instantiationService: IInstantiationService
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
this.editorService.overrideOpenEditor({
......@@ -106,9 +111,12 @@ export class NotebookContribution implements IWorkbenchContribution {
return [];
}
const infos = notebookService.getContributedNotebookProviders(resource);
const associatedEditors = distinct([
...this.getUserAssociatedNotebookEditors(resource),
...this.getContributedEditors(resource)
], editor => editor.id);
return infos.map(info => {
return associatedEditors.map(info => {
return {
label: info.displayName,
id: info.id,
......@@ -128,12 +136,41 @@ export class NotebookContribution implements IWorkbenchContribution {
});
}
getUserAssociatedEditors(resource: URI) {
const rawAssociations = this.configurationService.getValue<CustomEditorsAssociations>(customEditorsAssociationsSettingId) || [];
return coalesce(rawAssociations
.filter(association => CustomEditorInfo.selectorMatches(association, resource)));
}
getUserAssociatedNotebookEditors(resource: URI) {
const rawAssociations = this.configurationService.getValue<CustomEditorsAssociations>(customEditorsAssociationsSettingId) || [];
return coalesce(rawAssociations
.filter(association => CustomEditorInfo.selectorMatches(association, resource))
.map(association => this.notebookService.getContributedNotebookProvider(association.viewType)));
}
getContributedEditors(resource: URI) {
return this.notebookService.getContributedNotebookProviders(resource);
}
private onEditorOpening(originalInput: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup, id: string | undefined): IOpenEditorOverride | undefined {
let resource = originalInput.resource;
if (!resource) {
return undefined;
}
if (id === undefined) {
const userAssociatedEditors = this.getUserAssociatedEditors(resource);
const notebookEditor = userAssociatedEditors.filter(association => this.notebookService.getContributedNotebookProvider(association.viewType));
if (userAssociatedEditors.length && !notebookEditor.length) {
// user pick a non-notebook editor for this resource
return undefined;
}
}
if (this._resourceMapping.has(resource)) {
const input = this._resourceMapping.get(resource);
......@@ -145,7 +182,7 @@ export class NotebookContribution implements IWorkbenchContribution {
let info: NotebookProviderInfo | undefined;
const data = CellUri.parse(resource);
if (data) {
const infos = this.notebookService.getContributedNotebookProviders(data.notebook);
const infos = this.getContributedEditors(data.notebook);
if (infos.length) {
const info = id === undefined ? infos[0] : (infos.find(info => info.id === id) || infos[0]);
......
......@@ -49,6 +49,7 @@ export interface INotebookService {
executeNotebookCell(viewType: string, uri: URI, handle: number, token: CancellationToken): Promise<void>;
getContributedNotebookProviders(resource: URI): readonly NotebookProviderInfo[];
getContributedNotebookProvider(viewType: string): NotebookProviderInfo | undefined;
getNotebookProviderResourceRoots(): URI[];
destoryNotebookDocument(viewType: string, notebook: INotebookTextModel): void;
updateActiveNotebookDocument(viewType: string, resource: URI): void;
......@@ -273,6 +274,10 @@ export class NotebookService extends Disposable implements INotebookService, ICu
return this.notebookProviderInfoStore.getContributedNotebook(resource);
}
getContributedNotebookProvider(viewType: string): NotebookProviderInfo | undefined {
return this.notebookProviderInfoStore.get(viewType);
}
getContributedNotebookOutputRenderers(mimeType: string): readonly NotebookOutputRendererInfo[] {
return this.notebookRenderersInfoStore.getContributedRenderer(mimeType);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册