more editor service tests
This commit is contained in:
parent
8f7851d082
commit
5dc8004326
2 changed files with 175 additions and 19 deletions
|
@ -8,7 +8,7 @@ import { EditorActivation, EditorOverride, IResourceEditorInput } from 'vs/platf
|
|||
import { URI } from 'vs/base/common/uri';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { DEFAULT_EDITOR_ASSOCIATION, EditorsOrder, GroupIdentifier, IEditorInputWithOptions, IEditorPane, IResourceDiffEditorInput, isEditorInputWithOptions, isResourceDiffEditorInput, isUntitledResourceEditorInput, IUntitledTextResourceEditorInput, IUntypedEditorInput, UntypedEditorContext } from 'vs/workbench/common/editor';
|
||||
import { workbenchInstantiationService, TestServiceAccessor, registerTestEditor, TestFileEditorInput, ITestInstantiationService, registerTestResourceEditor, registerTestSideBySideEditor, createEditorPart, registerTestFileEditor } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { workbenchInstantiationService, TestServiceAccessor, registerTestEditor, TestFileEditorInput, ITestInstantiationService, registerTestResourceEditor, registerTestSideBySideEditor, createEditorPart, registerTestFileEditor, TestEditorWithOptions, TestTextFileEditor } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { TextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput';
|
||||
import { EditorService } from 'vs/workbench/services/editor/browser/editorService';
|
||||
import { IEditorGroup, IEditorGroupsService, GroupDirection, GroupsArrangement } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
|
@ -71,7 +71,7 @@ suite('EditorService', () => {
|
|||
return [part, editorService, instantiationService.createInstance(TestServiceAccessor)];
|
||||
}
|
||||
|
||||
test('openEditor', async () => {
|
||||
test('basics', async () => {
|
||||
const [, service] = await createEditorService();
|
||||
|
||||
let input = new TestFileEditorInput(URI.parse('my://resource-basics'), TEST_EDITOR_INPUT_ID);
|
||||
|
@ -178,11 +178,11 @@ suite('EditorService', () => {
|
|||
didCloseEditorListener.dispose();
|
||||
});
|
||||
|
||||
test('openEditor - override handling', () => {
|
||||
test('openEditor()', () => {
|
||||
return testOpenEditors(false);
|
||||
});
|
||||
|
||||
test('openEditors - override handling', () => {
|
||||
test('openEditors()', () => {
|
||||
return testOpenEditors(true);
|
||||
});
|
||||
|
||||
|
@ -265,10 +265,11 @@ suite('EditorService', () => {
|
|||
{
|
||||
let untypedEditor: IResourceEditorInput = { resource: URI.file('file.editor-service-override-tests') };
|
||||
let pane = await openEditor(untypedEditor);
|
||||
let typedEditor = pane?.input;
|
||||
|
||||
assert.strictEqual(pane?.group, rootGroup);
|
||||
assert.ok(pane.input instanceof TestFileEditorInput);
|
||||
assert.strictEqual(pane.input.resource.toString(), untypedEditor.resource.toString());
|
||||
assert.ok(typedEditor instanceof TestFileEditorInput);
|
||||
assert.strictEqual(typedEditor.resource.toString(), untypedEditor.resource.toString());
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 1);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 0);
|
||||
|
@ -278,6 +279,31 @@ suite('EditorService', () => {
|
|||
assert.ok(!lastUntitledEditorFactoryEditor);
|
||||
assert.ok(!lastDiffEditorFactoryEditor);
|
||||
|
||||
// opening the same editor should not create
|
||||
// a new editor input
|
||||
pane = await openEditor(untypedEditor);
|
||||
assert.strictEqual(pane?.input, typedEditor);
|
||||
|
||||
// replaceEditors should work too
|
||||
let untypedEditorReplacement: IResourceEditorInput = { resource: URI.file('file-replaced.editor-service-override-tests') };
|
||||
await service.replaceEditors([{
|
||||
editor: typedEditor,
|
||||
replacement: untypedEditorReplacement
|
||||
}], rootGroup);
|
||||
|
||||
typedEditor = rootGroup.activeEditor!;
|
||||
|
||||
assert.ok(typedEditor instanceof TestFileEditorInput);
|
||||
assert.strictEqual(typedEditor.resource.toString(), untypedEditorReplacement.resource.toString());
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 3);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 0);
|
||||
assert.strictEqual(diffEditorFactoryCalled, 0);
|
||||
|
||||
assert.strictEqual(lastEditorFactoryEditor, untypedEditorReplacement);
|
||||
assert.ok(!lastUntitledEditorFactoryEditor);
|
||||
assert.ok(!lastDiffEditorFactoryEditor);
|
||||
|
||||
await resetTestState();
|
||||
}
|
||||
|
||||
|
@ -285,10 +311,11 @@ suite('EditorService', () => {
|
|||
{
|
||||
let untypedEditor: IResourceEditorInput = { resource: URI.file('file.editor-service-override-tests'), options: { override: EditorOverride.DISABLED } };
|
||||
let pane = await openEditor(untypedEditor);
|
||||
let typedEditor = pane?.input;
|
||||
|
||||
assert.strictEqual(pane?.group, rootGroup);
|
||||
assert.ok(pane.input instanceof FileEditorInput);
|
||||
assert.strictEqual(pane.input.resource.toString(), untypedEditor.resource.toString());
|
||||
assert.ok(typedEditor instanceof FileEditorInput);
|
||||
assert.strictEqual(typedEditor.resource.toString(), untypedEditor.resource.toString());
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 0);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 0);
|
||||
|
@ -298,6 +325,11 @@ suite('EditorService', () => {
|
|||
assert.ok(!lastUntitledEditorFactoryEditor);
|
||||
assert.ok(!lastDiffEditorFactoryEditor);
|
||||
|
||||
// opening the same editor should not create
|
||||
// a new editor input
|
||||
pane = await openEditor(untypedEditor);
|
||||
assert.strictEqual(pane?.input, typedEditor);
|
||||
|
||||
await resetTestState();
|
||||
}
|
||||
|
||||
|
@ -458,10 +490,11 @@ suite('EditorService', () => {
|
|||
{
|
||||
let typedEditor = new TestFileEditorInput(URI.file('file.editor-service-override-tests'), TEST_EDITOR_INPUT_ID);
|
||||
let pane = await openEditor({ editor: typedEditor });
|
||||
let typedInput = pane?.input;
|
||||
|
||||
assert.strictEqual(pane?.group, rootGroup);
|
||||
assert.ok(pane.input instanceof TestFileEditorInput);
|
||||
assert.strictEqual(pane.input.resource.toString(), typedEditor.resource.toString());
|
||||
assert.ok(typedInput instanceof TestFileEditorInput);
|
||||
assert.strictEqual(typedInput.resource.toString(), typedEditor.resource.toString());
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 1);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 0);
|
||||
|
@ -471,6 +504,31 @@ suite('EditorService', () => {
|
|||
assert.ok(!lastUntitledEditorFactoryEditor);
|
||||
assert.ok(!lastDiffEditorFactoryEditor);
|
||||
|
||||
// opening the same editor should not create
|
||||
// a new editor input
|
||||
pane = await openEditor(typedEditor);
|
||||
assert.strictEqual(pane?.input, typedInput);
|
||||
|
||||
// replaceEditors should work too
|
||||
let typedEditorReplacement = new TestFileEditorInput(URI.file('file-replaced.editor-service-override-tests'), TEST_EDITOR_INPUT_ID);
|
||||
await service.replaceEditors([{
|
||||
editor: typedEditor,
|
||||
replacement: typedEditorReplacement
|
||||
}], rootGroup);
|
||||
|
||||
typedInput = rootGroup.activeEditor!;
|
||||
|
||||
assert.ok(typedInput instanceof TestFileEditorInput);
|
||||
assert.strictEqual(typedInput.resource.toString(), typedEditorReplacement.resource.toString());
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 3);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 0);
|
||||
assert.strictEqual(diffEditorFactoryCalled, 0);
|
||||
|
||||
assert.strictEqual((lastEditorFactoryEditor as IResourceEditorInput).resource.toString(), typedInput.resource.toString());
|
||||
assert.ok(!lastUntitledEditorFactoryEditor);
|
||||
assert.ok(!lastDiffEditorFactoryEditor);
|
||||
|
||||
await resetTestState();
|
||||
}
|
||||
|
||||
|
@ -478,10 +536,11 @@ suite('EditorService', () => {
|
|||
{
|
||||
let typedEditor = new TestFileEditorInput(URI.file('file.editor-service-override-tests'), TEST_EDITOR_INPUT_ID);
|
||||
let pane = await openEditor({ editor: typedEditor, options: { override: EditorOverride.DISABLED } });
|
||||
let typedInput = pane?.input;
|
||||
|
||||
assert.strictEqual(pane?.group, rootGroup);
|
||||
assert.ok(pane.input instanceof TestFileEditorInput);
|
||||
assert.strictEqual(pane.input.resource.toString(), typedEditor.resource.toString());
|
||||
assert.ok(typedInput instanceof TestFileEditorInput);
|
||||
assert.strictEqual(typedInput.resource.toString(), typedEditor.resource.toString());
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 0);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 0);
|
||||
|
@ -491,6 +550,11 @@ suite('EditorService', () => {
|
|||
assert.ok(!lastUntitledEditorFactoryEditor);
|
||||
assert.ok(!lastDiffEditorFactoryEditor);
|
||||
|
||||
// opening the same editor should not create
|
||||
// a new editor input
|
||||
pane = await openEditor(typedEditor);
|
||||
assert.strictEqual(pane?.input, typedInput);
|
||||
|
||||
await resetTestState();
|
||||
}
|
||||
|
||||
|
@ -692,10 +756,11 @@ suite('EditorService', () => {
|
|||
{
|
||||
let untypedEditor: IUntitledTextResourceEditorInput = { resource: URI.file('file-original.editor-service-override-tests').with({ scheme: 'untitled' }) };
|
||||
let pane = await openEditor(untypedEditor);
|
||||
let typedEditor = pane?.input;
|
||||
|
||||
assert.strictEqual(pane?.group, rootGroup);
|
||||
assert.ok(pane.input instanceof TestFileEditorInput);
|
||||
assert.strictEqual(pane.input.resource.scheme, 'untitled');
|
||||
assert.ok(typedEditor instanceof TestFileEditorInput);
|
||||
assert.strictEqual(typedEditor.resource.scheme, 'untitled');
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 0);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 1);
|
||||
|
@ -705,6 +770,11 @@ suite('EditorService', () => {
|
|||
assert.strictEqual(lastUntitledEditorFactoryEditor, untypedEditor);
|
||||
assert.ok(!lastDiffEditorFactoryEditor);
|
||||
|
||||
// opening the same editor should not create
|
||||
// a new editor input
|
||||
pane = await openEditor(untypedEditor);
|
||||
assert.strictEqual(pane?.input, typedEditor);
|
||||
|
||||
await resetTestState();
|
||||
}
|
||||
|
||||
|
@ -736,11 +806,16 @@ suite('EditorService', () => {
|
|||
{
|
||||
// untyped diff editor, no options, no group
|
||||
{
|
||||
let untypedEditor: IResourceDiffEditorInput = { originalInput: { resource: URI.file('file-original.editor-service-override-tests') }, modifiedInput: { resource: URI.file('file-modified.editor-service-override-tests') }, options: { override: 'editorServiceOverrideTests' } };
|
||||
let untypedEditor: IResourceDiffEditorInput = {
|
||||
originalInput: { resource: URI.file('file-original.editor-service-override-tests') },
|
||||
modifiedInput: { resource: URI.file('file-modified.editor-service-override-tests') },
|
||||
options: { override: 'editorServiceOverrideTests' }
|
||||
};
|
||||
let pane = await openEditor(untypedEditor);
|
||||
let typedEditor = pane?.input;
|
||||
|
||||
assert.strictEqual(pane?.group, rootGroup);
|
||||
assert.ok(pane.input instanceof TestFileEditorInput);
|
||||
assert.ok(typedEditor instanceof TestFileEditorInput);
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 0);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 0);
|
||||
|
@ -755,7 +830,11 @@ suite('EditorService', () => {
|
|||
|
||||
// untyped diff editor, no options, SIDE_GROUP
|
||||
{
|
||||
let untypedEditor: IResourceDiffEditorInput = { originalInput: { resource: URI.file('file-original.editor-service-override-tests') }, modifiedInput: { resource: URI.file('file-modified.editor-service-override-tests') }, options: { override: 'editorServiceOverrideTests' } };
|
||||
let untypedEditor: IResourceDiffEditorInput = {
|
||||
originalInput: { resource: URI.file('file-original.editor-service-override-tests') },
|
||||
modifiedInput: { resource: URI.file('file-modified.editor-service-override-tests') },
|
||||
options: { override: 'editorServiceOverrideTests' }
|
||||
};
|
||||
let pane = await openEditor(untypedEditor, SIDE_GROUP);
|
||||
|
||||
assert.strictEqual(accessor.editorGroupService.groups.length, 2);
|
||||
|
@ -893,8 +972,66 @@ suite('EditorService', () => {
|
|||
await resetTestState();
|
||||
}
|
||||
}
|
||||
|
||||
// openEditors with >1 editor
|
||||
if (useOpenEditors) {
|
||||
|
||||
// mix of untyped and typed editors
|
||||
{
|
||||
let untypedEditor1: IResourceEditorInput = { resource: URI.file('file1.editor-service-override-tests') };
|
||||
let untypedEditor2: IResourceEditorInput = { resource: URI.file('file2.editor-service-override-tests'), options: { override: EditorOverride.DISABLED } };
|
||||
let untypedEditor3: IEditorInputWithOptions = { editor: new TestFileEditorInput(URI.file('file3.editor-service-override-tests'), TEST_EDITOR_INPUT_ID) };
|
||||
let untypedEditor4: IEditorInputWithOptions = { editor: new TestFileEditorInput(URI.file('file4.editor-service-override-tests'), TEST_EDITOR_INPUT_ID), options: { override: EditorOverride.DISABLED } };
|
||||
let untypedEditor5: IResourceEditorInput = { resource: URI.file('file5.editor-service-override-tests') };
|
||||
let pane = (await service.openEditors([untypedEditor1, untypedEditor2, untypedEditor3, untypedEditor4, untypedEditor5]))[0];
|
||||
|
||||
assert.strictEqual(pane?.group, rootGroup);
|
||||
assert.strictEqual(pane?.group.count, 5);
|
||||
|
||||
assert.strictEqual(editorFactoryCalled, 3);
|
||||
assert.strictEqual(untitledEditorFactoryCalled, 0);
|
||||
assert.strictEqual(diffEditorFactoryCalled, 0);
|
||||
|
||||
assert.ok(lastEditorFactoryEditor);
|
||||
assert.ok(!lastUntitledEditorFactoryEditor);
|
||||
assert.ok(!lastDiffEditorFactoryEditor);
|
||||
|
||||
await resetTestState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test('openEditor() applies options if editor already opened', async () => {
|
||||
disposables.add(registerTestFileEditor());
|
||||
|
||||
const [, service, accessor] = await createEditorService();
|
||||
|
||||
disposables.add(accessor.editorOverrideService.registerEditor(
|
||||
'*.editor-service-override-tests',
|
||||
{ id: 'editorServiceOverrideTests', label: 'Label', priority: RegisteredEditorPriority.exclusive },
|
||||
{},
|
||||
editor => ({ editor: new TestFileEditorInput(editor.resource, 'editorServiceOverrideTests') })
|
||||
));
|
||||
|
||||
// Typed editor
|
||||
let pane = await service.openEditor(new TestFileEditorInput(URI.parse('my://resource-openEditors'), 'editorServiceOverrideTests'));
|
||||
pane = await service.openEditor(new TestFileEditorInput(URI.parse('my://resource-openEditors'), 'editorServiceOverrideTests'), { sticky: true, preserveFocus: true });
|
||||
|
||||
assert.ok(pane instanceof TestEditorWithOptions);
|
||||
assert.strictEqual(pane.lastSetOptions?.sticky, true);
|
||||
assert.strictEqual(pane.lastSetOptions?.preserveFocus, true);
|
||||
|
||||
await pane.group?.closeAllEditors();
|
||||
|
||||
// Untyped editor (without registered editor)
|
||||
pane = await service.openEditor({ resource: URI.file('resource-openEditors') });
|
||||
pane = await service.openEditor({ resource: URI.file('resource-openEditors'), options: { sticky: true, preserveFocus: true } });
|
||||
|
||||
assert.ok(pane instanceof TestTextFileEditor);
|
||||
assert.strictEqual(pane.lastSetOptions?.sticky, true);
|
||||
assert.strictEqual(pane.lastSetOptions?.preserveFocus, true);
|
||||
});
|
||||
|
||||
test('isOpen() with side by side editor', async () => {
|
||||
const [part, service] = await createEditorService();
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configur
|
|||
import { IWorkbenchLayoutService, Parts, Position as PartPosition } from 'vs/workbench/services/layout/browser/layoutService';
|
||||
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
|
||||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { IEditorOptions, IResourceEditorInput, IEditorModel, IResourceEditorInputIdentifier, ITextResourceEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { IEditorOptions, IResourceEditorInput, IEditorModel, IResourceEditorInputIdentifier, ITextResourceEditorInput, ITextEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { IUntitledTextEditorService, UntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { ILifecycleService, BeforeShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase, WillShutdownEvent } from 'vs/workbench/services/lifecycle/common/lifecycle';
|
||||
|
@ -168,6 +168,14 @@ export class TestTextResourceEditor extends TextResourceEditor {
|
|||
|
||||
export class TestTextFileEditor extends TextFileEditor {
|
||||
|
||||
lastSetOptions: ITextEditorOptions | undefined = undefined;
|
||||
|
||||
override setOptions(options: ITextEditorOptions | undefined): void {
|
||||
this.lastSetOptions = options;
|
||||
|
||||
super.setOptions(options);
|
||||
}
|
||||
|
||||
protected override createEditorControl(parent: HTMLElement, configuration: any): IEditor {
|
||||
return this.instantiationService.createInstance(TestCodeEditor, parent, configuration, {});
|
||||
}
|
||||
|
@ -1310,8 +1318,19 @@ export class TestEditorInput extends EditorInput {
|
|||
}
|
||||
}
|
||||
|
||||
export abstract class TestEditorWithOptions extends EditorPane {
|
||||
|
||||
lastSetOptions: ITextEditorOptions | undefined = undefined;
|
||||
|
||||
override setOptions(options: ITextEditorOptions | undefined): void {
|
||||
this.lastSetOptions = options;
|
||||
|
||||
super.setOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
export function registerTestEditor(id: string, inputs: SyncDescriptor<EditorInput>[], serializerInputId?: string): IDisposable {
|
||||
class TestEditor extends EditorPane {
|
||||
class TestEditor extends TestEditorWithOptions {
|
||||
|
||||
private _scopedContextKeyService: IContextKeyService;
|
||||
|
||||
|
|
Loading…
Reference in a new issue