提交 b6e58e71 编写于 作者: R rebornix

notebook editor contribution priority.

上级 4e02919b
......@@ -7,17 +7,20 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
import * as nls from 'vs/nls';
import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { NotebookSelector } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { NotebookEditorPriority } from 'vs/workbench/contrib/notebook/common/notebookCommon';
namespace NotebookEditorContribution {
export const viewType = 'viewType';
export const displayName = 'displayName';
export const selector = 'selector';
export const priority = 'priority';
}
export interface INotebookEditorContribution {
readonly [NotebookEditorContribution.viewType]: string;
readonly [NotebookEditorContribution.displayName]: string;
readonly [NotebookEditorContribution.selector]?: readonly NotebookSelector[];
readonly [NotebookEditorContribution.priority]?: string;
}
namespace NotebookRendererContribution {
......@@ -32,8 +35,6 @@ interface INotebookRendererContribution {
readonly [NotebookRendererContribution.mimeTypes]?: readonly string[];
}
const notebookProviderContribution: IJSONSchema = {
description: nls.localize('contributes.notebook.provider', 'Contributes notebook document provider.'),
type: 'array',
......@@ -70,6 +71,19 @@ const notebookProviderContribution: IJSONSchema = {
}
}
}
},
[NotebookEditorContribution.priority]: {
type: 'string',
markdownDeprecationMessage: nls.localize('contributes.priority', 'Controls if the custom editor is enabled automatically when the user opens a file. This may be overridden by users using the `workbench.editorAssociations` setting.'),
enum: [
NotebookEditorPriority.default,
NotebookEditorPriority.option,
],
markdownEnumDescriptions: [
nls.localize('contributes.priority.default', 'The editor is automatically used when the user opens a resource, provided that no other default custom editors are registered for that resource.'),
nls.localize('contributes.priority.option', 'The editor is not automatically used when the user opens a resource, but a user can switch to the editor using the `Reopen With` command.'),
],
default: 'default'
}
}
}
......
......@@ -31,7 +31,7 @@ import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEd
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl';
import { CellKind, CellUri, NotebookDocumentBackupData } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellUri, NotebookDocumentBackupData, NotebookEditorPriority } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { IEditorGroup, OpenEditorContext } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
......@@ -298,6 +298,19 @@ export class NotebookContribution extends Disposable implements IWorkbenchContri
// user pick a non-notebook editor for this resource
return undefined;
}
// user might pick a notebook editor
const associatedEditors = distinct([
...this.getUserAssociatedNotebookEditors(resource),
...this.getContributedEditors(resource)
], editor => editor.id).filter(editor => editor.priority === NotebookEditorPriority.default);
if (!associatedEditors.length) {
// there is no notebook editor contribution which is enabled by default
return;
}
} else {
const existingEditors = group.editors.filter(editor => editor.resource && isEqual(editor.resource, resource) && (editor instanceof NotebookEditorInput) && editor.viewType === id);
......
......@@ -11,7 +11,7 @@ import { notebookProviderExtensionPoint, notebookRendererExtensionPoint, INotebo
import { NotebookProviderInfo, NotebookEditorDescriptor } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.protocol';
import { Emitter, Event } from 'vs/base/common/event';
import { INotebookTextModel, INotebookRendererInfo, NotebookDocumentMetadata, ICellDto2, INotebookKernelInfo, CellOutputKind, ITransformedDisplayOutputDto, IDisplayOutput, ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, NOTEBOOK_DISPLAY_ORDER, sortMimeTypes, IOrderedMimeType, mimeTypeSupportedByCore, IOutputRenderRequestOutputInfo, IOutputRenderRequestCellInfo, NotebookCellOutputsSplice, ICellEditOperation, CellEditType, ICellInsertEdit, IOutputRenderResponse, IProcessedOutput, BUILTIN_RENDERER_ID } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookTextModel, INotebookRendererInfo, NotebookDocumentMetadata, ICellDto2, INotebookKernelInfo, CellOutputKind, ITransformedDisplayOutputDto, IDisplayOutput, ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, NOTEBOOK_DISPLAY_ORDER, sortMimeTypes, IOrderedMimeType, mimeTypeSupportedByCore, IOutputRenderRequestOutputInfo, IOutputRenderRequestCellInfo, NotebookCellOutputsSplice, ICellEditOperation, CellEditType, ICellInsertEdit, IOutputRenderResponse, IProcessedOutput, BUILTIN_RENDERER_ID, NotebookEditorPriority } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { NotebookOutputRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookOutputRenderer';
import { Iterable } from 'vs/base/common/iterator';
......@@ -57,6 +57,7 @@ export class NotebookProviderInfoStore implements IDisposable {
id: notebookContribution.viewType,
displayName: notebookContribution.displayName,
selector: notebookContribution.selector || [],
priority: this.convertPriority(notebookContribution.priority),
providerDisplayName: extension.description.isBuiltin ? nls.localize('builtinProviderDisplayName', "Built-in") : extension.description.displayName || extension.description.identifier.value,
providerExtensionLocation: extension.description.extensionLocation
}));
......@@ -68,6 +69,19 @@ export class NotebookProviderInfoStore implements IDisposable {
this._memento.saveMemento();
}
private convertPriority(priority?: string) {
if (!priority) {
return NotebookEditorPriority.default;
}
if (priority === NotebookEditorPriority.default) {
return NotebookEditorPriority.default;
}
return NotebookEditorPriority.option;
}
dispose(): void {
}
......
......@@ -575,3 +575,8 @@ export interface IEditor extends editorCommon.ICompositeCodeEditor {
hasFocus(): boolean;
hasModel(): boolean;
}
export enum NotebookEditorPriority {
default = 'default',
option = 'option',
}
......@@ -6,7 +6,7 @@
import * as glob from 'vs/base/common/glob';
import { URI } from 'vs/base/common/uri';
import { basename } from 'vs/base/common/path';
import { INotebookKernelInfoDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookKernelInfoDto, NotebookEditorPriority } from 'vs/workbench/contrib/notebook/common/notebookCommon';
export interface NotebookSelector {
readonly filenamePattern?: string;
......@@ -17,6 +17,7 @@ export interface NotebookEditorDescriptor {
readonly id: string;
readonly displayName: string;
readonly selector: readonly NotebookSelector[];
readonly priority: NotebookEditorPriority;
readonly providerDisplayName: string;
readonly providerExtensionLocation: URI;
kernel?: INotebookKernelInfoDto;
......@@ -27,6 +28,7 @@ export class NotebookProviderInfo implements NotebookEditorDescriptor {
readonly id: string;
readonly displayName: string;
readonly selector: readonly NotebookSelector[];
readonly priority: NotebookEditorPriority;
readonly providerDisplayName: string;
readonly providerExtensionLocation: URI;
kernel?: INotebookKernelInfoDto;
......@@ -35,6 +37,7 @@ export class NotebookProviderInfo implements NotebookEditorDescriptor {
this.id = descriptor.id;
this.displayName = descriptor.displayName;
this.selector = descriptor.selector;
this.priority = descriptor.priority;
this.providerDisplayName = descriptor.providerDisplayName;
this.providerExtensionLocation = descriptor.providerExtensionLocation;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册