Skip to content

Commit

Permalink
Untyped Editors within override service (#126918)
Browse files Browse the repository at this point in the history
* Initial function changes for untyped overrides

* Hook up openEditor

* Untyped reopen

* Open editors

* Fix open editor tests

* Address PR feedback

* Update src/vs/workbench/services/editor/browser/editorService.ts

Co-authored-by: Benjamin Pasero <benjpas@microsoft.com>

* Cleanup code based on PR feedback

* Use active group for picker

* Decouple editor id resolving

* Fix tests

* Comment out untitled notebook test for now

* Further enrich replace

* some 💄 and tests

* remove `toUntyped` for side by side editor input for now

* adjust `replaceEditors`

* adjust `findTargetGroup`

* variable renames

* adjust `openEditors`

* more cleanup

* Fix reopen with

* more lipstick

* fix cycle

* properly mixin activation back into options

* cleanup doResolveEditorOverride

* more use of `IEditorInputWithOptions`

* make sure to pass proper `IEditorInputWithOptions`

* IEditorService#replaceEditors should require a typed editor input for editor (fix #127134)

* Change doResolveEditor

* Fix untitled notebook test

* Fix test cases

* Untitled custom editor

Co-authored-by: Benjamin Pasero <benjamin.pasero@microsoft.com>
Co-authored-by: Benjamin Pasero <benjpas@microsoft.com>
  • Loading branch information
3 people committed Jun 25, 2021
1 parent 49f5aba commit d0ca6c7
Show file tree
Hide file tree
Showing 21 changed files with 396 additions and 285 deletions.
2 changes: 1 addition & 1 deletion src/vs/platform/editor/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export enum EditorActivation {
* Activate the editor after it opened. This will automatically restore
* the editor if it is minimized.
*/
ACTIVATE,
ACTIVATE = 1,

/**
* Only restore the editor if it is minimized but do not activate it.
Expand Down
11 changes: 1 addition & 10 deletions src/vs/workbench/browser/parts/editor/editorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { IListService, IOpenEvent } from 'vs/platform/list/browser/listService';
import { List } from 'vs/base/browser/ui/list/listWidget';
import { distinct, coalesce } from 'vs/base/common/arrays';
import { IEditorGroupsService, IEditorGroup, GroupDirection, GroupLocation, GroupsOrder, preferredSideBySideGroupDirection, EditorGroupLayout } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorGroupsService, IEditorGroup, GroupDirection, GroupLocation, GroupsOrder, preferredSideBySideGroupDirection, EditorGroupLayout, isEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
Expand Down Expand Up @@ -1045,15 +1045,6 @@ export function getMultiSelectedEditorContexts(editorContext: IEditorCommandsCon
return !!editorContext ? [editorContext] : [];
}

function isEditorGroup(thing: unknown): thing is IEditorGroup {
const group = thing as IEditorGroup | undefined;
if (!group) {
return false;
}

return typeof group.id === 'number' && Array.isArray(group.editors);
}

export function setup(): void {
registerActiveEditorMoveCommand();
registerEditorGroupsLayoutCommand();
Expand Down
13 changes: 8 additions & 5 deletions src/vs/workbench/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { IPathData } from 'vs/platform/windows/common/windows';
import { coalesce } from 'vs/base/common/arrays';
import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IExtUri } from 'vs/base/common/resources';
import { Schemas } from 'vs/base/common/network';

// Static values for editor contributions
export const EditorExtensions = {
Expand Down Expand Up @@ -312,6 +313,12 @@ export function isResourceDiffEditorInput(editor: IUntypedEditorInput): editor i
return candidate.originalInput !== undefined && candidate.modifiedInput !== undefined;
}

export function isUntitledResourceEditorInput(editor: IUntypedEditorInput): editor is IUntitledTextResourceEditorInput {
const candidate = editor as IUntitledTextResourceEditorInput;

return candidate.resource === undefined || candidate.resource.scheme === Schemas.untitled;
}

export const enum Verbosity {
SHORT,
MEDIUM,
Expand Down Expand Up @@ -725,12 +732,8 @@ export interface IEditorInputWithOptions {
options?: IEditorOptions;
}

export interface IEditorInputWithOptionsAndGroup extends IEditorInputWithOptions {
group?: IEditorGroup;
}

export function isEditorInputWithOptions(obj: unknown): obj is IEditorInputWithOptions {
const editorInputWithOptions = obj as IEditorInputWithOptions;
const editorInputWithOptions = obj as IEditorInputWithOptions | undefined;

return !!editorInputWithOptions && !!editorInputWithOptions.editor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { coalesce } from 'vs/base/common/arrays';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { extname, isEqual } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { RedoCommand, UndoCommand } from 'vs/editor/browser/editorExtensions';
Expand Down Expand Up @@ -33,6 +34,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
_serviceBrand: any;

private readonly _contributedEditors: ContributedCustomEditors;
private _untitledCounter = 0;
private readonly _editorOverrideDisposables: IDisposable[] = [];
private readonly _editorCapabilities = new Map<string, CustomEditorCapabilities>();

Expand Down Expand Up @@ -123,10 +125,13 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
{
singlePerResource: () => !this.getCustomEditorCapabilities(contributedEditor.id)?.supportsMultipleEditorsPerDocument ?? true
},
(resource, options, group) => {
({ resource }, group) => {
return { editor: CustomEditorInput.create(this.instantiationService, resource, contributedEditor.id, group.id) };
},
(diffEditorInput, options, group) => {
({ 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) };
}
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
input.setForceOpenAsText();

// Try to let the user pick an override if there is one availabe
let overridenInput: ReturnedOverride | undefined = await this.editorOverrideService.resolveEditorOverride(editor, { ...options, override: EditorOverride.PICK, }, this.group);
let overridenInput: ReturnedOverride | undefined = await this.editorOverrideService.resolveEditorInput({ resource: editor.resource, options: { ...options, override: EditorOverride.PICK } }, this.group);
if (overridenInput === OverrideStatus.NONE) {
overridenInput = undefined;
} else if (overridenInput === OverrideStatus.ABORT) {
Expand All @@ -70,7 +70,7 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
...overridenInput?.options ?? options,
override: EditorOverride.DISABLED
}
}], overridenInput?.group ?? this.group);
}], this.group);
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class NotebookProviderInfoStore extends Disposable {
private readonly _memento: Memento;
private _handled: boolean = false;

private _untitledCounter = 1;

private readonly _contributedEditors = new Map<string, NotebookProviderInfo>();
private readonly _contributedEditorDisposables = new DisposableStore();

Expand Down Expand Up @@ -154,7 +156,7 @@ export class NotebookProviderInfoStore extends Disposable {
canHandleDiff: () => !!this._configurationService.getValue(NotebookTextDiffEditorPreview) && !this._accessibilityService.isScreenReaderOptimized(),
canSupportResource: (resource: URI) => resource.scheme === Schemas.untitled || resource.scheme === Schemas.vscodeNotebookCell || this._fileService.canHandleResource(resource)
};
const notebookEditorInputFactory: EditorInputFactoryFunction = (resource, options, group) => {
const notebookEditorInputFactory: EditorInputFactoryFunction = ({ resource, options }, group) => {
const data = CellUri.parse(resource);
let notebookUri: URI = resource;
let cellOptions: IResourceEditorInput | undefined;
Expand All @@ -178,6 +180,15 @@ export class NotebookProviderInfoStore extends Disposable {
notebookEditorInfo,
notebookEditorOptions,
notebookEditorInputFactory,
({ resource, options }, group) => {
if (!resource) {
resource = URI.from({
scheme: Schemas.untitled,
authority: `Untitled-${this._untitledCounter++}`
});
}
return notebookEditorInputFactory({ resource, options }, group);
},
notebookEditorDiffFactory
));
// Then register the schema handler as exclusive for that notebook
Expand All @@ -186,6 +197,7 @@ export class NotebookProviderInfoStore extends Disposable {
{ ...notebookEditorInfo, priority: RegisteredEditorPriority.exclusive },
notebookEditorOptions,
notebookEditorInputFactory,
undefined,
notebookEditorDiffFactory
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService';
import * as nls from 'vs/nls';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ConfigurationScope, Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuration';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IEditorInputWithOptions } from 'vs/workbench/common/editor';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { RegisteredEditorPriority, IEditorOverrideService } from 'vs/workbench/services/editor/common/editorOverrideService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { FOLDER_SETTINGS_PATH, IPreferencesService, USE_SPLIT_JSON_SETTING } from 'vs/workbench/services/preferences/common/preferences';
Expand Down Expand Up @@ -70,7 +68,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
priority: RegisteredEditorPriority.builtin,
},
{},
(resource: URI, options: IEditorOptions | undefined, group: IEditorGroup): IEditorInputWithOptions => {
({ resource, options }, group): IEditorInputWithOptions => {
// Global User Settings File
if (isEqual(resource, this.environmentService.settingsResource)) {
return { editor: this.preferencesService.getCurrentOrNewSplitJsonEditorInput(ConfigurationTarget.USER_LOCAL, resource, group), options };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SearchEditorContribution implements IWorkbenchContribution {
canHandleDiff: false,
canSupportResource: resource => (extname(resource) === SEARCH_EDITOR_EXT)
},
(resource, options, group) => {
({ resource }) => {
return { editor: instantiationService.invokeFunction(getOrMakeSearchEditorInput, { from: 'existingFile', fileUri: resource }) };
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class TerminalService implements ITerminalService {
canSupportResource: uri => uri.scheme === Schemas.vscodeTerminal,
singlePerResource: true
},
(resource, options, group) => {
({ resource, options }) => {
let instance = this.getInstanceFromResource(resource);
if (instance) {
const sourceGroup = this._terminalGroupService.getGroupForInstance(instance);
Expand Down

0 comments on commit d0ca6c7

Please sign in to comment.