Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/vs/workbench/contrib/customEditor/browser/customEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { CONTEXT_ACTIVE_CUSTOM_EDITOR_ID, CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, CustomEditorCapabilities, CustomEditorInfo, CustomEditorInfoCollection, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
import { CustomEditorModelManager } from 'vs/workbench/contrib/customEditor/common/customEditorModelManager';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorResolverService, IEditorType, RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService';
import { DiffEditorInputFactoryFunction, EditorInputFactoryFunction, IEditorResolverService, IEditorType, RegisteredEditorPriority, UntitledEditorInputFactoryFunction } from 'vs/workbench/services/editor/common/editorResolverService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ContributedCustomEditors } from '../common/contributedCustomEditors';
import { CustomEditorInput } from './customEditorInput';
Expand Down Expand Up @@ -116,6 +116,17 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
if (!globPattern.filenamePattern) {
continue;
}

const editorInputFactory: EditorInputFactoryFunction = ({ resource }, group) => {
return { editor: CustomEditorInput.create(this.instantiationService, resource, contributedEditor.id, group.id) };
};
const untitledEditorInputFactory: UntitledEditorInputFactoryFunction = ({ resource }, group) => {
return { editor: CustomEditorInput.create(this.instantiationService, resource ?? URI.from({ scheme: Schemas.untitled, authority: `Untitled-${this._untitledCounter++}` }), contributedEditor.id, group.id) };
};
const diffEditorInputFactory: DiffEditorInputFactoryFunction = (diffEditorInput, group) => {
return { editor: this.createDiffEditorInput(diffEditorInput, contributedEditor.id, group) };
};

this._editorResolverDisposables.add(this.editorResolverService.registerEditor(
globPattern.filenamePattern,
{
Expand All @@ -127,14 +138,10 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
{
singlePerResource: () => !this.getCustomEditorCapabilities(contributedEditor.id)?.supportsMultipleEditorsPerDocument ?? true
},
({ resource }, group) => {
return { editor: CustomEditorInput.create(this.instantiationService, resource, contributedEditor.id, group.id) };
},
({ resource }, group) => {
return { editor: CustomEditorInput.create(this.instantiationService, resource ?? URI.from({ scheme: Schemas.untitled, authority: `Untitled-${this._untitledCounter++}` }), contributedEditor.id, group.id) };
},
(diffEditorInput, group) => {
return { editor: this.createDiffEditorInput(diffEditorInput, contributedEditor.id, group) };
{
createEditorInput: editorInputFactory,
createUntitledEditorInput: untitledEditorInputFactory,
createDiffEditorInput: diffEditorInputFactory,
}
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
canSupportResource: uri => uri.scheme === Schemas.vscodeInteractiveInput,
singlePerResource: true
},
({ resource }) => {
const editorInput = editorService.getEditors(EditorsOrder.SEQUENTIAL).find(editor => editor.editor instanceof InteractiveEditorInput && editor.editor.inputResource.toString() === resource.toString());
return editorInput!;
{
createEditorInput: ({ resource }) => {
const editorInput = editorService.getEditors(EditorsOrder.SEQUENTIAL).find(editor => editor.editor instanceof InteractiveEditorInput && editor.editor.inputResource.toString() === resource.toString());
return editorInput!;
}
}
);

Expand All @@ -220,23 +222,25 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
canSupportResource: uri => uri.scheme === Schemas.vscodeInteractive || (uri.scheme === Schemas.vscodeNotebookCell && extname(uri) === '.interactive'),
singlePerResource: true
},
({ resource, options }) => {
const data = CellUri.parse(resource);
let notebookUri: URI = resource;
let cellOptions: IResourceEditorInput | undefined;

if (data) {
notebookUri = data.notebook;
cellOptions = { resource, options };
}
{
createEditorInput: ({ resource, options }) => {
const data = CellUri.parse(resource);
let notebookUri: URI = resource;
let cellOptions: IResourceEditorInput | undefined;

if (data) {
notebookUri = data.notebook;
cellOptions = { resource, options };
}

const notebookOptions = { ...options, cellOptions } as INotebookEditorOptions;
const notebookOptions = { ...options, cellOptions } as INotebookEditorOptions;

const editorInput = editorService.getEditors(EditorsOrder.SEQUENTIAL).find(editor => editor.editor instanceof InteractiveEditorInput && editor.editor.resource?.toString() === notebookUri.toString());
return {
editor: editorInput!.editor,
options: notebookOptions
};
const editorInput = editorService.getEditors(EditorsOrder.SEQUENTIAL).find(editor => editor.editor instanceof InteractiveEditorInput && editor.editor.resource?.toString() === notebookUri.toString());
return {
editor: editorInput!.editor,
options: notebookOptions
};
}
}
);
}
Expand Down
92 changes: 48 additions & 44 deletions src/vs/workbench/contrib/mergeEditor/browser/view/mergeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { MergeEditorViewModel } from 'vs/workbench/contrib/mergeEditor/browser/v
import { ctxBaseResourceScheme, ctxIsMergeEditor, ctxMergeEditorLayout, MergeEditorLayoutTypes } from 'vs/workbench/contrib/mergeEditor/common/mergeEditor';
import { settingsSashBorder } from 'vs/workbench/contrib/preferences/common/settingsEditorColorRegistry';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorResolverService, RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService';
import { EditorInputFactoryFunction, IEditorResolverService, MergeEditorInputFactoryFunction, RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import './colors';
import { InputCodeEditorView } from './editors/inputCodeEditorView';
Expand Down Expand Up @@ -510,6 +510,50 @@ export class MergeEditorResolverContribution extends Disposable {
) {
super();

const editorInputFactory: EditorInputFactoryFunction = (editor) => {
return {
editor: instantiationService.createInstance(
MergeEditorInput,
editor.resource,
{
uri: editor.resource,
title: '',
description: '',
detail: ''
},
{
uri: editor.resource,
title: '',
description: '',
detail: ''
},
editor.resource
)
};
};

const mergeEditorInputFactory: MergeEditorInputFactoryFunction = (mergeEditor: IResourceMergeEditorInput): EditorInputWithOptions => {
return {
editor: instantiationService.createInstance(
MergeEditorInput,
mergeEditor.base.resource,
{
uri: mergeEditor.input1.resource,
title: basename(mergeEditor.input1.resource),
description: '',
detail: ''
},
{
uri: mergeEditor.input2.resource,
title: basename(mergeEditor.input2.resource),
description: '',
detail: ''
},
mergeEditor.result.resource
)
};
};

this._register(editorResolverService.registerEditor(
`*`,
{
Expand All @@ -519,49 +563,9 @@ export class MergeEditorResolverContribution extends Disposable {
priority: RegisteredEditorPriority.option
},
{},
(editor) => {
return {
editor: instantiationService.createInstance(
MergeEditorInput,
editor.resource,
{
uri: editor.resource,
title: '',
description: '',
detail: ''
},
{
uri: editor.resource,
title: '',
description: '',
detail: ''
},
editor.resource
)
};
},
undefined,
undefined,
(mergeEditor: IResourceMergeEditorInput): EditorInputWithOptions => {
return {
editor: instantiationService.createInstance(
MergeEditorInput,
mergeEditor.base.resource,
{
uri: mergeEditor.input1.resource,
title: basename(mergeEditor.input1.resource),
description: '',
detail: ''
},
{
uri: mergeEditor.input2.resource,
title: basename(mergeEditor.input2.resource),
description: '',
detail: ''
},
mergeEditor.result.resource
)
};
{
createEditorInput: editorInputFactory,
createMergeEditorInput: mergeEditorInputFactory
}
));
}
Expand Down
47 changes: 40 additions & 7 deletions src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { updateEditorTopPadding } from 'vs/workbench/contrib/notebook/common/not
import { NotebookOutputRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookOutputRenderer';
import { NotebookEditorDescriptor, NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { ComplexNotebookProviderInfo, INotebookContentProvider, INotebookSerializer, INotebookService, SimpleNotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookService';
import { DiffEditorInputFactoryFunction, EditorInputFactoryFunction, IEditorResolverService, IEditorType, RegisteredEditorInfo, RegisteredEditorPriority, UntitledEditorInputFactoryFunction } from 'vs/workbench/services/editor/common/editorResolverService';
import { DiffEditorInputFactoryFunction, EditorInputFactoryFunction, EditorInputFactoryObject, IEditorResolverService, IEditorType, RegisteredEditorInfo, RegisteredEditorPriority, UntitledEditorInputFactoryFunction } from 'vs/workbench/services/editor/common/editorResolverService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';

Expand Down Expand Up @@ -195,23 +195,56 @@ export class NotebookProviderInfoStore extends Disposable {
const notebookDiffEditorInputFactory: DiffEditorInputFactoryFunction = ({ modified, original, label, description }) => {
return { editor: NotebookDiffEditorInput.create(this._instantiationService, modified.resource!, label, description, original.resource!, notebookProviderInfo.id) };
};

const notebookFactoryObject: EditorInputFactoryObject = {
createEditorInput: notebookEditorInputFactory,
createDiffEditorInput: notebookDiffEditorInputFactory,
createUntitledEditorInput: notebookUntitledEditorFactory,
};
const notebookCellFactoryObject: EditorInputFactoryObject = {
createEditorInput: notebookEditorInputFactory,
createDiffEditorInput: notebookDiffEditorInputFactory,
};

// TODO @lramos15 find a better way to toggle handling diff editors than needing these listeners for every registration
// This is a lot of event listeners especially if there are many notebooks
disposables.add(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(NotebookSetting.textDiffEditorPreview)) {
const canHandleDiff = !!this._configurationService.getValue(NotebookSetting.textDiffEditorPreview) && !this._accessibilityService.isScreenReaderOptimized();
if (canHandleDiff) {
notebookFactoryObject.createDiffEditorInput = notebookDiffEditorInputFactory;
notebookCellFactoryObject.createDiffEditorInput = notebookDiffEditorInputFactory;
} else {
notebookFactoryObject.createDiffEditorInput = undefined;
notebookCellFactoryObject.createDiffEditorInput = undefined;
}
}
}));

disposables.add(this._accessibilityService.onDidChangeScreenReaderOptimized(() => {
const canHandleDiff = !!this._configurationService.getValue(NotebookSetting.textDiffEditorPreview) && !this._accessibilityService.isScreenReaderOptimized();
if (canHandleDiff) {
notebookFactoryObject.createDiffEditorInput = notebookDiffEditorInputFactory;
notebookCellFactoryObject.createDiffEditorInput = notebookDiffEditorInputFactory;
} else {
notebookFactoryObject.createDiffEditorInput = undefined;
notebookCellFactoryObject.createDiffEditorInput = undefined;
}
}));

// Register the notebook editor
disposables.add(this._editorResolverService.registerEditor(
globPattern,
notebookEditorInfo,
notebookEditorOptions,
notebookEditorInputFactory,
notebookUntitledEditorFactory,
notebookDiffEditorInputFactory
notebookFactoryObject,
));
// Then register the schema handler as exclusive for that notebook
disposables.add(this._editorResolverService.registerEditor(
`${Schemas.vscodeNotebookCell}:/**/${globPattern}`,
{ ...notebookEditorInfo, priority: RegisteredEditorPriority.exclusive },
notebookEditorOptions,
notebookEditorInputFactory,
undefined,
notebookDiffEditorInputFactory
notebookCellFactoryObject
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ suite('NotebookProviderInfoStore', function () {
},
instantiationService.createInstance(EditorResolverService),
new TestConfigurationService(),
new class extends mock<IAccessibilityService>() { },
new class extends mock<IAccessibilityService>() {
override onDidChangeScreenReaderOptimized: Event<void> = Event.None;
},
instantiationService,
new class extends mock<IFileService>() {
override hasProvider() { return true; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,35 @@ export class PreferencesContribution implements IWorkbenchContribution {
label: nls.localize('splitSettingsEditorLabel', "Split Settings Editor"),
priority: RegisteredEditorPriority.builtin,
},
{},
{
canHandleDiff: false,
},
({ resource, options }): EditorInputWithOptions => {
// Global User Settings File
if (isEqual(resource, this.userDataProfileService.currentProfile.settingsResource)) {
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.USER_LOCAL, resource), options };
}
createEditorInput: ({ resource, options }): EditorInputWithOptions => {
// Global User Settings File
if (isEqual(resource, this.userDataProfileService.currentProfile.settingsResource)) {
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.USER_LOCAL, resource), options };
}

// Single Folder Workspace Settings File
const state = this.workspaceService.getWorkbenchState();
if (state === WorkbenchState.FOLDER) {
const folders = this.workspaceService.getWorkspace().folders;
if (isEqual(resource, folders[0].toResource(FOLDER_SETTINGS_PATH))) {
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.WORKSPACE, resource), options };
// Single Folder Workspace Settings File
const state = this.workspaceService.getWorkbenchState();
if (state === WorkbenchState.FOLDER) {
const folders = this.workspaceService.getWorkspace().folders;
if (isEqual(resource, folders[0].toResource(FOLDER_SETTINGS_PATH))) {
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.WORKSPACE, resource), options };
}
}
}

// Multi Folder Workspace Settings File
else if (state === WorkbenchState.WORKSPACE) {
const folders = this.workspaceService.getWorkspace().folders;
for (const folder of folders) {
if (isEqual(resource, folder.toResource(FOLDER_SETTINGS_PATH))) {
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.WORKSPACE_FOLDER, resource), options };
// Multi Folder Workspace Settings File
else if (state === WorkbenchState.WORKSPACE) {
const folders = this.workspaceService.getWorkspace().folders;
for (const folder of folders) {
if (isEqual(resource, folder.toResource(FOLDER_SETTINGS_PATH))) {
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.WORKSPACE_FOLDER, resource), options };
}
}
}
}

return { editor: this.textEditorService.createTextEditor({ resource }), options };
return { editor: this.textEditorService.createTextEditor({ resource }), options };
}
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ class SearchEditorContribution implements IWorkbenchContribution {
},
{
singlePerResource: true,
canHandleDiff: false,
canSupportResource: resource => (extname(resource) === SEARCH_EDITOR_EXT)
},
({ resource }) => {
return { editor: instantiationService.invokeFunction(getOrMakeSearchEditorInput, { from: 'existingFile', fileUri: resource }) };
{
createEditorInput: ({ resource }) => {
return { editor: instantiationService.invokeFunction(getOrMakeSearchEditorInput, { from: 'existingFile', fileUri: resource }) };
}
}
);
}
Expand Down
Loading