提交 64d980d8 编写于 作者: B Benjamin Pasero

grid - more cleanup

上级 3abb1619
......@@ -748,45 +748,3 @@ export function ninvoke<T>(thisArg: any, fn: Function, ...args: any[]): TPromise
export function ninvoke(thisArg: any, fn: Function, ...args: any[]): any {
return new TPromise((c, e) => fn.call(thisArg, ...args, (err: any, result: any) => err ? e(err) : c(result)), () => null);
}
/**
* An emitter that will ignore any events that occur during a specific code
* execution triggered via throttle() until the promise has finished (either
* successfully or with an error). Only after the promise has finished, the
* last event that was fired during the operation will get emitted.
*
*/
export class ThrottledEmitter<T> extends Emitter<T> {
private suspended: boolean;
private lastEvent: T;
private hasLastEvent: boolean;
public throttle<C>(promise: TPromise<C>): TPromise<C> {
this.suspended = true;
return always(promise, () => this.resume());
}
public fire(event?: T): any {
if (this.suspended) {
this.lastEvent = event;
this.hasLastEvent = true;
return;
}
return super.fire(event);
}
private resume(): void {
this.suspended = false;
if (this.hasLastEvent) {
this.fire(this.lastEvent);
}
this.hasLastEvent = false;
this.lastEvent = void 0;
}
}
......@@ -603,29 +603,4 @@ suite('Async', () => {
const r1Queue2 = queue.queueFor(URI.file('/some/path'));
assert.notEqual(r1Queue, r1Queue2); // previous one got disposed after finishing
});
test('ThrottledEmitter', function () {
const emitter = new Async.ThrottledEmitter();
const fnThatEmitsEvent = () => {
emitter.fire();
};
const promiseFn = TPromise.timeout(0).then(() => {
fnThatEmitsEvent();
fnThatEmitsEvent();
fnThatEmitsEvent();
});
let count = 0;
emitter.event(() => {
count++;
});
emitter.throttle(promiseFn);
promiseFn.then(() => {
assert.equal(count, 1);
});
});
});
......@@ -11,7 +11,6 @@ import { TextCompareEditorVisibleContext, EditorInput, IEditorIdentifier, IEdito
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor';
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes';
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
......@@ -540,21 +539,28 @@ function resolveCommandsContext(editorGroupService: INextEditorGroupsService, co
}
export function getMultiSelectedEditorContexts(editorContext: IEditorCommandsContext, listService: IListService, editorGroupService: INextEditorGroupsService): IEditorCommandsContext[] {
// First check for a focused list to return the selected items from
const list = listService.lastFocusedList;
if (list instanceof List && list.isDOMFocused()) {
const elementToContext = (element: IEditorIdentifier | EditorGroup) =>
element instanceof EditorGroup ? { groupId: element.id, editorIndex: undefined } : { groupId: element.groupId, editorIndex: editorGroupService.getGroup(element.groupId).getIndexOfEditor(element.editor) };
const onlyEditorGroupAndEditor = (e: IEditorIdentifier | EditorGroup) => e instanceof EditorGroup || ('editor' in e && 'group' in e);
const elementToContext = (element: IEditorIdentifier | IEditorGroup) => {
if (isEditorGroup(element)) {
return { groupId: element.id, editorIndex: void 0 };
}
return { groupId: element.groupId, editorIndex: editorGroupService.getGroup(element.groupId).getIndexOfEditor(element.editor) };
};
const focusedElements: (IEditorIdentifier | EditorGroup)[] = list.getFocusedElements().filter(onlyEditorGroupAndEditor);
// need to take into account when editor context is { group: group }
const focus = editorContext ? editorContext : focusedElements.length ? focusedElements.map(elementToContext)[0] : undefined;
const onlyEditorGroupAndEditor = (e: IEditorIdentifier | IEditorGroup) => isEditorGroup(e) || isEditorIdentifier(e);
const focusedElements: (IEditorIdentifier | IEditorGroup)[] = list.getFocusedElements().filter(onlyEditorGroupAndEditor);
const focus = editorContext ? editorContext : focusedElements.length ? focusedElements.map(elementToContext)[0] : void 0; // need to take into account when editor context is { group: group }
if (focus) {
const selection: (IEditorIdentifier | EditorGroup)[] = list.getSelectedElements().filter(onlyEditorGroupAndEditor);
const selection: (IEditorIdentifier | IEditorGroup)[] = list.getSelectedElements().filter(onlyEditorGroupAndEditor);
// Only respect selection if it contains focused element
if (selection && selection.some(s => s instanceof EditorGroup ? s.id === focus.groupId : s.groupId === focus.groupId && editorGroupService.getGroup(s.groupId).getIndexOfEditor(s.editor) === focus.editorIndex)) {
if (selection && selection.some(s => isEditorGroup(s) ? s.id === focus.groupId : s.groupId === focus.groupId && editorGroupService.getGroup(s.groupId).getIndexOfEditor(s.editor) === focus.editorIndex)) {
return selection.map(elementToContext);
}
......@@ -566,6 +572,18 @@ export function getMultiSelectedEditorContexts(editorContext: IEditorCommandsCon
return !!editorContext ? [editorContext] : [];
}
function isEditorGroup(thing: any): thing is IEditorGroup {
const group = thing as IEditorGroup;
return group && typeof group.id === 'number' && Array.isArray(group.editors);
}
function isEditorIdentifier(thing: any): thing is IEditorIdentifier {
const identifier = thing as IEditorIdentifier;
return identifier && typeof identifier.groupId === 'number';
}
export function setup(): void {
registerActiveEditorMoveCommand();
registerDiffEditorCommands();
......
......@@ -11,7 +11,7 @@ import * as types from 'vs/base/common/types';
import URI from 'vs/base/common/uri';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { IEditor as ICodeEditor, IEditorViewState, ScrollType, IDiffEditor } from 'vs/editor/common/editorCommon';
import { IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position } from 'vs/platform/editor/common/editor';
import { IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput } from 'vs/platform/editor/common/editor';
import { IInstantiationService, IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation';
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { Registry } from 'vs/platform/registry/common/platform';
......@@ -1176,57 +1176,3 @@ export const Extensions = {
};
Registry.add(Extensions.EditorInputFactories, new EditorInputFactoryRegistry());
//#region TODO@grid obsolete
export interface IStacksModelChangeEvent {
group: ILegacyEditorGroup;
editor?: IEditorInput;
structural?: boolean;
}
export interface IEditorStacksModel {
onModelChanged: Event<IStacksModelChangeEvent>;
onWillCloseEditor: Event<IEditorCloseEvent>;
onEditorClosed: Event<IEditorCloseEvent>;
groups: ILegacyEditorGroup[];
activeGroup: ILegacyEditorGroup;
isActive(group: ILegacyEditorGroup): boolean;
getGroup(id: GroupIdentifier): ILegacyEditorGroup;
positionOfGroup(group: ILegacyEditorGroup): Position;
groupAt(position: Position): ILegacyEditorGroup;
next(jumpGroups: boolean, cycleAtEnd?: boolean): IEditorIdentifier;
previous(jumpGroups: boolean, cycleAtStart?: boolean): IEditorIdentifier;
last(): IEditorIdentifier;
isOpen(resource: URI): boolean;
toString(): string;
}
export interface ILegacyEditorGroup {
id: GroupIdentifier;
count: number;
activeEditor: IEditorInput;
previewEditor: IEditorInput;
getEditor(index: number): IEditorInput;
getEditor(resource: URI): IEditorInput;
indexOf(editor: IEditorInput): number;
contains(editorOrResource: IEditorInput | URI): boolean;
getEditors(mru?: boolean): IEditorInput[];
isActive(editor: IEditorInput): boolean;
isPreview(editor: IEditorInput): boolean;
isPinned(index: number): boolean;
isPinned(editor: IEditorInput): boolean;
}
//#endregion
......@@ -6,7 +6,7 @@
'use strict';
import { Event, Emitter, once } from 'vs/base/common/event';
import { Extensions, IEditorInputFactoryRegistry, EditorInput, toResource, ILegacyEditorGroup, IEditorIdentifier, IEditorCloseEvent, GroupIdentifier, SideBySideEditorInput, CloseDirection } from 'vs/workbench/common/editor';
import { Extensions, IEditorInputFactoryRegistry, EditorInput, toResource, IEditorIdentifier, IEditorCloseEvent, GroupIdentifier, SideBySideEditorInput, CloseDirection } from 'vs/workbench/common/editor';
import URI from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
......@@ -54,7 +54,7 @@ export function isSerializedEditorGroup(obj?: any): obj is ISerializedEditorGrou
return obj && typeof obj === 'object' && Array.isArray(group.editors) && Array.isArray(group.mru);
}
export class EditorGroup extends Disposable implements ILegacyEditorGroup {
export class EditorGroup extends Disposable {
private static IDS = 0;
......
......@@ -12,19 +12,19 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { ConfigurationResolverService } from 'vs/workbench/services/configurationResolver/electron-browser/configurationResolverService';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { TestEnvironmentService, TestNextEditorService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { TestEnvironmentService, TestEditorService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
suite('Configuration Resolver Service', () => {
let configurationResolverService: IConfigurationResolverService;
let envVariables: { [key: string]: string } = { key1: 'Value for key1', key2: 'Value for key2' };
let mockCommandService: MockCommandService;
let editorService: TestNextEditorService;
let editorService: TestEditorService;
let workspace: IWorkspaceFolder;
setup(() => {
mockCommandService = new MockCommandService();
editorService = new TestNextEditorService();
editorService = new TestEditorService();
workspace = {
uri: uri.parse('file:///VSCode/workspaceLocation'),
name: 'hey',
......@@ -116,7 +116,7 @@ suite('Configuration Resolver Service', () => {
}
});
let service = new ConfigurationResolverService(envVariables, new TestNextEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
let service = new ConfigurationResolverService(envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} xyz'), 'abc foo xyz');
});
......@@ -133,7 +133,7 @@ suite('Configuration Resolver Service', () => {
}
});
let service = new ConfigurationResolverService(envVariables, new TestNextEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
let service = new ConfigurationResolverService(envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} ${config:terminal.integrated.fontFamily} xyz'), 'abc foo bar xyz');
});
......@@ -150,7 +150,7 @@ suite('Configuration Resolver Service', () => {
}
});
let service = new ConfigurationResolverService(envVariables, new TestNextEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
let service = new ConfigurationResolverService(envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
if (platform.isWindows) {
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} ${workspaceFolder} ${env:key1} xyz'), 'abc foo \\VSCode\\workspaceLocation Value for key1 xyz');
} else {
......@@ -171,7 +171,7 @@ suite('Configuration Resolver Service', () => {
}
});
let service = new ConfigurationResolverService(envVariables, new TestNextEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
let service = new ConfigurationResolverService(envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
if (platform.isWindows) {
assert.strictEqual(service.resolve(workspace, '${config:editor.fontFamily} ${config:terminal.integrated.fontFamily} ${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), 'foo bar \\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation Value for key1 - Value for key2');
} else {
......@@ -205,7 +205,7 @@ suite('Configuration Resolver Service', () => {
}
});
let service = new ConfigurationResolverService(envVariables, new TestNextEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
let service = new ConfigurationResolverService(envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} ${config:editor.lineNumbers} ${config:editor.insertSpaces} xyz'), 'abc foo 123 false xyz');
});
......@@ -215,7 +215,7 @@ suite('Configuration Resolver Service', () => {
editor: {}
});
let service = new ConfigurationResolverService(envVariables, new TestNextEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
let service = new ConfigurationResolverService(envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
assert.strictEqual(service.resolve(workspace, 'abc ${unknownVariable} xyz'), 'abc ${unknownVariable} xyz');
assert.strictEqual(service.resolve(workspace, 'abc ${env:unknownVariable} xyz'), 'abc xyz');
});
......@@ -228,7 +228,7 @@ suite('Configuration Resolver Service', () => {
}
});
let service = new ConfigurationResolverService(envVariables, new TestNextEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
let service = new ConfigurationResolverService(envVariables, new TestEditorService(), TestEnvironmentService, configurationService, mockCommandService, new TestContextService());
assert.throws(() => service.resolve(workspace, 'abc ${env} xyz'));
assert.throws(() => service.resolve(workspace, 'abc ${env:} xyz'));
......
......@@ -11,7 +11,7 @@ import { IEditorOptions, ITextEditorOptions, Position, IResourceInput } from 'vs
import URI from 'vs/base/common/uri';
import { Registry } from 'vs/platform/registry/common/platform';
import { basename } from 'vs/base/common/paths';
import { EditorInput, EditorOptions, TextEditorOptions, Extensions as EditorExtensions, IResourceDiffInput, IResourceSideBySideInput, IUntitledResourceInput, SideBySideEditorInput, IFileEditorInput, IFileInputFactory, IEditorInputFactoryRegistry, IEditorStacksModel, IEditorOpeningEvent, ILegacyEditorGroup, IStacksModelChangeEvent, IEditorCloseEvent, IEditorIdentifier, CloseDirection, IEditor, IEditorInput } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, TextEditorOptions, Extensions as EditorExtensions, IResourceDiffInput, IResourceSideBySideInput, IUntitledResourceInput, SideBySideEditorInput, IFileEditorInput, IFileInputFactory, IEditorInputFactoryRegistry, IEditorOpeningEvent, IEditorCloseEvent, IEditorIdentifier, CloseDirection, IEditor, IEditorInput } from 'vs/workbench/common/editor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
......@@ -142,7 +142,7 @@ export interface IEditorPart {
export class NoOpEditorPart implements IEditorPart, IEditorGroupService {
_serviceBrand: ServiceIdentifier<any>;
stacks: IEditorStacksModel;
stacks: any;
constructor(private instantiationService: IInstantiationService) {
this.stacks = new NoOpEditorStacksModel();
......@@ -175,7 +175,7 @@ export class NoOpEditorPart implements IEditorPart, IEditorGroupService {
moveEditor(...args: any[]) { }
getStacksModel(): IEditorStacksModel {
getStacksModel(): any {
return this.stacks;
}
......@@ -230,28 +230,28 @@ export class NoOpEditorPart implements IEditorPart, IEditorGroupService {
}
}
export class NoOpEditorStacksModel implements IEditorStacksModel {
export class NoOpEditorStacksModel {
onModelChanged: Event<IStacksModelChangeEvent> = new Emitter<IStacksModelChangeEvent>().event;
onModelChanged: Event<any> = new Emitter<any>().event;
onWillCloseEditor: Event<IEditorCloseEvent> = new Emitter<IEditorCloseEvent>().event;
onEditorClosed: Event<IEditorCloseEvent> = new Emitter<IEditorCloseEvent>().event;
groups: ILegacyEditorGroup[] = [];
activeGroup: ILegacyEditorGroup;
groups: any[] = [];
activeGroup: any;
isActive(group: ILegacyEditorGroup): boolean {
isActive(group: any): boolean {
return false;
}
getGroup(id: number): ILegacyEditorGroup {
getGroup(id: number): any {
return null;
}
positionOfGroup(group: ILegacyEditorGroup): Position {
positionOfGroup(group: any): Position {
return Position.ONE;
}
groupAt(position: Position): ILegacyEditorGroup {
groupAt(position: Position): any {
return null;
}
......
......@@ -7,7 +7,7 @@
import { createDecorator, ServiceIdentifier, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { Position } from 'vs/platform/editor/common/editor';
import { IEditorStacksModel, ILegacyEditorGroup, IEditorOpeningEvent, IEditorInput } from 'vs/workbench/common/editor';
import { IEditorOpeningEvent, IEditorInput } from 'vs/workbench/common/editor';
import { Event } from 'vs/base/common/event';
export enum GroupArrangement {
......@@ -75,19 +75,19 @@ export interface IEditorGroupService {
/**
* Keyboard focus the editor group at the provided position.
*/
focusGroup(group: ILegacyEditorGroup): void;
focusGroup(group: any): void;
focusGroup(position: Position): void;
/**
* Activate the editor group at the provided position without moving focus.
*/
activateGroup(group: ILegacyEditorGroup): void;
activateGroup(group: any): void;
activateGroup(position: Position): void;
/**
* Allows to move the editor group from one position to another.
*/
moveGroup(from: ILegacyEditorGroup, to: ILegacyEditorGroup): void;
moveGroup(from: any, to: any): void;
moveGroup(from: Position, to: Position): void;
/**
......@@ -114,20 +114,20 @@ export interface IEditorGroupService {
/**
* Adds the pinned state to an editor, removing it from being a preview editor.
*/
pinEditor(group: ILegacyEditorGroup, input: IEditorInput): void;
pinEditor(group: any, input: IEditorInput): void;
pinEditor(position: Position, input: IEditorInput): void;
/**
* Moves an editor from one group to another. The index in the group is optional.
* The inactive option is applied when moving across groups.
*/
moveEditor(input: IEditorInput, from: ILegacyEditorGroup, to: ILegacyEditorGroup, moveOptions?: IMoveOptions): void;
moveEditor(input: IEditorInput, from: any, to: any, moveOptions?: IMoveOptions): void;
moveEditor(input: IEditorInput, from: Position, to: Position, moveOptions?: IMoveOptions): void;
/**
* Provides access to the editor stacks model
*/
getStacksModel(): IEditorStacksModel;
getStacksModel(): any;
/**
* Returns tab options.
......
......@@ -16,7 +16,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { KeyCode, SimpleKeybinding, ChordKeybinding } from 'vs/base/common/keyCodes';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import * as extfs from 'vs/base/node/extfs';
import { TestTextFileService, TestLifecycleService, TestBackupFileService, TestContextService, TestTextResourceConfigurationService, TestHashService, TestEnvironmentService, TestStorageService, TestNextEditorGroupsService, TestNextEditorService } from 'vs/workbench/test/workbenchTestServices';
import { TestTextFileService, TestLifecycleService, TestBackupFileService, TestContextService, TestTextResourceConfigurationService, TestHashService, TestEnvironmentService, TestStorageService, TestEditorGroupsService, TestEditorService } from 'vs/workbench/test/workbenchTestServices';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
......@@ -78,8 +78,8 @@ suite('Keybindings Editing', () => {
instantiationService.stub(ILifecycleService, lifecycleService);
instantiationService.stub(IContextKeyService, <IContextKeyService>instantiationService.createInstance(MockContextKeyService));
instantiationService.stub(IHashService, new TestHashService());
instantiationService.stub(INextEditorGroupsService, new TestNextEditorGroupsService());
instantiationService.stub(INextEditorService, new TestNextEditorService());
instantiationService.stub(INextEditorGroupsService, new TestEditorGroupsService());
instantiationService.stub(INextEditorService, new TestEditorService());
instantiationService.stub(ITelemetryService, NullTelemetryService);
instantiationService.stub(IModeService, ModeServiceImpl);
instantiationService.stub(IModelService, instantiationService.createInstance(ModelServiceImpl));
......
......@@ -14,7 +14,7 @@ import * as Platform from 'vs/platform/registry/common/platform';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { workbenchInstantiationService, TestNextEditorGroup } from 'vs/workbench/test/workbenchTestServices';
import { workbenchInstantiationService, TestEditorGroup } from 'vs/workbench/test/workbenchTestServices';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import URI from 'vs/base/common/uri';
......@@ -99,7 +99,7 @@ suite('Workbench base editor', () => {
assert.strictEqual(input, e.input);
assert.strictEqual(options, e.options);
const group = new TestNextEditorGroup(1);
const group = new TestEditorGroup(1);
e.setVisible(true, group);
assert(e.isVisible());
assert.equal(e.group, group);
......
......@@ -6,7 +6,7 @@
import * as assert from 'assert';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import URI from 'vs/base/common/uri';
import { workbenchInstantiationService, TestNextEditorService } from 'vs/workbench/test/workbenchTestServices';
import { workbenchInstantiationService, TestEditorService } from 'vs/workbench/test/workbenchTestServices';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
......@@ -33,7 +33,7 @@ suite('Editor - Range decorations', () => {
setup(() => {
instantiationService = <TestInstantiationService>workbenchInstantiationService();
instantiationService.stub(INextEditorService, new TestNextEditorService());
instantiationService.stub(INextEditorService, new TestEditorService());
instantiationService.stub(IModeService, ModeServiceImpl);
instantiationService.stub(IModelService, stubModelService(instantiationService));
text = 'LINE1' + '\n' + 'LINE2' + '\n' + 'LINE3' + '\n' + 'LINE4' + '\r\n' + 'LINE5';
......
......@@ -13,7 +13,7 @@ import { IEditorModel } from 'vs/platform/editor/common/editor';
import URI from 'vs/base/common/uri';
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { workbenchInstantiationService, TestNextEditorGroupsService, TestNextEditorGroup } from 'vs/workbench/test/workbenchTestServices';
import { workbenchInstantiationService, TestEditorGroupsService, TestEditorGroup } from 'vs/workbench/test/workbenchTestServices';
import { Schemas } from 'vs/base/common/network';
class ServiceAccessor {
......@@ -88,14 +88,14 @@ suite('Workbench editor', () => {
});
test('EditorViewStateMemento - basics', function () {
const testGroup0 = new TestNextEditorGroup(0);
const testGroup1 = new TestNextEditorGroup(1);
const testGroup4 = new TestNextEditorGroup(4);
const testGroup0 = new TestEditorGroup(0);
const testGroup1 = new TestEditorGroup(1);
const testGroup4 = new TestEditorGroup(4);
const groupService = new TestNextEditorGroupsService([
const groupService = new TestEditorGroupsService([
testGroup0,
testGroup1,
new TestNextEditorGroup(2)
new TestEditorGroup(2)
]);
interface TestViewState {
......@@ -156,7 +156,7 @@ suite('Workbench editor', () => {
});
test('EditorViewStateMemento - use with editor input', function () {
const testGroup0 = new TestNextEditorGroup(0);
const testGroup0 = new TestEditorGroup(0);
interface TestViewState {
line: number;
......@@ -179,7 +179,7 @@ suite('Workbench editor', () => {
}
const rawMemento = Object.create(null);
let memento = new EditorViewStateMemento<TestViewState>(new TestNextEditorGroupsService(), rawMemento, 'key', 3);
let memento = new EditorViewStateMemento<TestViewState>(new TestEditorGroupsService(), rawMemento, 'key', 3);
const testInputA = new TestEditorInput(URI.file('/A'));
......
......@@ -23,7 +23,7 @@ import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { TestFileService, TestNextEditorService } from 'vs/workbench/test/workbenchTestServices';
import { TestFileService, TestEditorService } from 'vs/workbench/test/workbenchTestServices';
import { TPromise } from 'vs/base/common/winjs.base';
import { IFileStat } from 'vs/platform/files/common/files';
import { ResourceTextEdit } from 'vs/editor/common/modes';
......@@ -81,7 +81,7 @@ suite('MainThreadEditors', () => {
onEditorGroupMoved = Event.None;
};
const bulkEditService = new BulkEditService(modelService, new TestNextEditorService(), null, fileService);
const bulkEditService = new BulkEditService(modelService, new TestEditorService(), null, fileService);
const rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(ExtHostContext.ExtHostDocuments, new class extends mock<ExtHostDocumentsShape>() {
......
......@@ -21,7 +21,7 @@ import { IQuickOpenRegistry, Extensions } from 'vs/workbench/browser/quickopen';
import { Registry } from 'vs/platform/registry/common/platform';
import { SearchService } from 'vs/workbench/services/search/node/searchService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { TestEnvironmentService, TestContextService, TestNextEditorService, TestNextEditorGroupsService } from 'vs/workbench/test/workbenchTestServices';
import { TestEnvironmentService, TestContextService, TestEditorService, TestEditorGroupsService } from 'vs/workbench/test/workbenchTestServices';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
......@@ -76,8 +76,8 @@ suite.skip('QuickOpen performance (integration)', () => {
[IConfigurationService, configurationService],
[IModelService, new ModelServiceImpl(null, configurationService)],
[IWorkspaceContextService, new TestContextService(testWorkspace(URI.file(testWorkspacePath)))],
[INextEditorService, new TestNextEditorService()],
[INextEditorGroupsService, new TestNextEditorGroupsService()],
[INextEditorService, new TestEditorService()],
[INextEditorGroupsService, new TestEditorGroupsService()],
[IEnvironmentService, TestEnvironmentService],
[IUntitledEditorService, createSyncDescriptor(UntitledEditorService)],
[ISearchService, createSyncDescriptor(SearchService)]
......
......@@ -19,7 +19,7 @@ import * as minimist from 'minimist';
import * as path from 'path';
import { SearchService } from 'vs/workbench/services/search/node/searchService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { TestEnvironmentService, TestContextService, TestNextEditorService, TestNextEditorGroupsService } from 'vs/workbench/test/workbenchTestServices';
import { TestEnvironmentService, TestContextService, TestEditorService, TestEditorGroupsService } from 'vs/workbench/test/workbenchTestServices';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
......@@ -64,8 +64,8 @@ suite.skip('TextSearch performance (integration)', () => {
[IConfigurationService, configurationService],
[IModelService, new ModelServiceImpl(null, configurationService)],
[IWorkspaceContextService, new TestContextService(testWorkspace(URI.file(testWorkspacePath)))],
[INextEditorService, new TestNextEditorService()],
[INextEditorGroupsService, new TestNextEditorGroupsService()],
[INextEditorService, new TestEditorService()],
[INextEditorGroupsService, new TestEditorGroupsService()],
[IEnvironmentService, TestEnvironmentService],
[IUntitledEditorService, createSyncDescriptor(UntitledEditorService)],
[ISearchService, createSyncDescriptor(SearchService)],
......
......@@ -14,7 +14,7 @@ import URI from 'vs/base/common/uri';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common/storageService';
import { ILegacyEditorGroup, ConfirmResult, IEditorOpeningEvent, IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInput, IEditor, IEditorCloseEvent } from 'vs/workbench/common/editor';
import { ConfirmResult, IEditorOpeningEvent, IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInput, IEditor, IEditorCloseEvent } from 'vs/workbench/common/editor';
import { Event, Emitter } from 'vs/base/common/event';
import Severity from 'vs/base/common/severity';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
......@@ -23,12 +23,11 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import { IPartService, Parts, Position as PartPosition, IDimension } from 'vs/workbench/services/part/common/partService';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IEditorOptions, Position, IResourceInput } from 'vs/platform/editor/common/editor';
import { IEditorOptions, IResourceInput } from 'vs/platform/editor/common/editor';
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent } from 'vs/platform/workspace/common/workspace';
import { ILifecycleService, ShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IEditorGroupService, GroupArrangement, GroupOrientation, IEditorTabOptions, IMoveOptions } from 'vs/workbench/services/group/common/groupService';
import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService';
import { FileOperationEvent, IFileService, IResolveContentOptions, FileOperationError, IFileStat, IResolveFileResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent, ICreateFileOptions, ITextSnapshot, IResourceEncodings } from 'vs/platform/files/common/files';
import { IModelService } from 'vs/editor/common/services/modelService';
......@@ -38,7 +37,7 @@ import { IRawTextContent, ITextFileService } from 'vs/workbench/services/textfil
import { parseArgs } from 'vs/platform/environment/node/argv';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IWorkbenchEditorService, ICloseEditorsFilter, NoOpEditorStacksModel } from 'vs/workbench/services/editor/common/editorService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IInstantiationService, ServicesAccessor, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
......@@ -255,9 +254,7 @@ export function workbenchInstantiationService(): IInstantiationService {
instantiationService.stub(ITextResourceConfigurationService, new TestTextResourceConfigurationService(configService));
instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IWorkbenchEditorService, new TestEditorService());
instantiationService.stub(IPartService, new TestPartService());
instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
instantiationService.stub(IModeService, ModeServiceImpl);
instantiationService.stub(IHistoryService, new TestHistoryService());
instantiationService.stub(IModelService, instantiationService.createInstance(ModelServiceImpl));
......@@ -277,8 +274,8 @@ export function workbenchInstantiationService(): IInstantiationService {
instantiationService.stub(IEnvironmentService, TestEnvironmentService);
instantiationService.stub(IThemeService, new TestThemeService());
instantiationService.stub(IHashService, new TestHashService());
instantiationService.stub(INextEditorGroupsService, new TestNextEditorGroupsService([new TestNextEditorGroup(0)]));
const editorService = new TestNextEditorService();
instantiationService.stub(INextEditorGroupsService, new TestEditorGroupsService([new TestEditorGroup(0)]));
const editorService = new TestEditorService();
instantiationService.stub(INextEditorService, editorService);
instantiationService.stub(ICodeEditorService, new TestCodeEditorService());
......@@ -497,213 +494,10 @@ export class TestStorageService implements IStorageService {
}
}
export class TestEditorGroupService implements IEditorGroupService {
public _serviceBrand: any;
private stacksModel;
private readonly _onEditorsChanged: Emitter<void>;
private readonly _onEditorOpening: Emitter<IEditorOpeningEvent>;
private readonly _onEditorOpenFail: Emitter<IEditorInput>;
private readonly _onEditorsMoved: Emitter<void>;
private readonly _onGroupOrientationChanged: Emitter<void>;
private readonly _onTabOptionsChanged: Emitter<IEditorTabOptions>;
constructor(callback?: (method: string) => void) {
this._onEditorsMoved = new Emitter<void>();
this._onEditorsChanged = new Emitter<void>();
this._onEditorOpening = new Emitter<IEditorOpeningEvent>();
this._onGroupOrientationChanged = new Emitter<void>();
this._onEditorOpenFail = new Emitter<IEditorInput>();
this._onTabOptionsChanged = new Emitter<IEditorTabOptions>();
let services = new ServiceCollection();
services.set(IStorageService, new TestStorageService());
services.set(IConfigurationService, new TestConfigurationService());
services.set(IWorkspaceContextService, new TestContextService());
const lifecycle = new TestLifecycleService();
services.set(ILifecycleService, lifecycle);
services.set(ITelemetryService, NullTelemetryService);
this.stacksModel = new NoOpEditorStacksModel();
}
public fireChange(): void {
this._onEditorsChanged.fire();
}
public get onEditorsChanged(): Event<void> {
return this._onEditorsChanged.event;
}
public get onEditorOpening(): Event<IEditorOpeningEvent> {
return this._onEditorOpening.event;
}
public get onEditorOpenFail(): Event<IEditorInput> {
return this._onEditorOpenFail.event;
}
public get onEditorGroupMoved(): Event<void> {
return this._onEditorsMoved.event;
}
public get onGroupOrientationChanged(): Event<void> {
return this._onGroupOrientationChanged.event;
}
public get onTabOptionsChanged(): Event<IEditorTabOptions> {
return this._onTabOptionsChanged.event;
}
public focusGroup(group: ILegacyEditorGroup): void;
public focusGroup(position: Position): void;
public focusGroup(arg1: any): void {
}
public activateGroup(group: ILegacyEditorGroup): void;
public activateGroup(position: Position): void;
public activateGroup(arg1: any): void {
}
public moveGroup(from: ILegacyEditorGroup, to: ILegacyEditorGroup): void;
public moveGroup(from: Position, to: Position): void;
public moveGroup(arg1: any, arg2: any): void {
}
public arrangeGroups(arrangement: GroupArrangement): void {
}
public setGroupOrientation(orientation: GroupOrientation): void {
}
public getGroupOrientation(): GroupOrientation {
return 'vertical';
}
public resizeGroup(position: Position, groupSizeChange: number): void {
}
public pinEditor(group: ILegacyEditorGroup, input: IEditorInput): void;
public pinEditor(position: Position, input: IEditorInput): void;
public pinEditor(arg1: any, input: IEditorInput): void {
}
public moveEditor(input: IEditorInput, from: ILegacyEditorGroup, to: ILegacyEditorGroup, moveOptions?: IMoveOptions): void;
public moveEditor(input: IEditorInput, from: Position, to: Position, moveOptions?: IMoveOptions): void;
public moveEditor(input: IEditorInput, from: any, to: any, moveOptions?: IMoveOptions): void {
}
public getStacksModel() {
return this.stacksModel;
}
public getTabOptions(): IEditorTabOptions {
return {};
}
public invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T {
return fn(null);
}
}
export class TestEditorService implements IWorkbenchEditorService {
public _serviceBrand: any;
public activeEditorInput: IEditorInput;
public activeEditorOptions: IEditorOptions;
public activeEditorPosition: Position;
public mockLineNumber: number;
public mockSelectedText: string;
private callback: (method: string) => void;
constructor(callback?: (method: string) => void) {
this.callback = callback || ((s: string) => { });
this.mockLineNumber = 15;
this.mockSelectedText = 'selected text';
}
public openEditors(inputs: any[]): Promise {
return TPromise.as([]);
}
public replaceEditors(editors: any[]): TPromise<IEditor[]> {
return TPromise.as([]);
}
public closeEditors(positions?: Position[]): TPromise<void>;
public closeEditors(position: Position, filter?: ICloseEditorsFilter): TPromise<void>;
public closeEditors(position: Position, editors: IEditorInput[]): TPromise<void>;
public closeEditors(editors: { positionOne?: ICloseEditorsFilter, positionTwo?: ICloseEditorsFilter, positionThree?: ICloseEditorsFilter }): TPromise<void>;
public closeEditors(editors: { positionOne?: IEditorInput[], positionTwo?: IEditorInput[], positionThree?: IEditorInput[] }): TPromise<void>;
public closeEditors(positionOrEditors: any, filterOrEditors?: any): TPromise<void> {
return TPromise.as(null);
}
public getActiveEditor(): IEditor {
this.callback('getActiveEditor');
return {
input: null,
options: null,
group: null,
getId: () => { return null; },
getControl: () => {
return {
getSelection: () => { return { positionLineNumber: this.mockLineNumber }; },
getModel: () => { return { getValueInRange: () => this.mockSelectedText }; }
};
},
focus: () => { },
isVisible: () => { return true; }
};
}
public getActiveEditorInput(): IEditorInput {
this.callback('getActiveEditorInput');
return this.activeEditorInput;
}
public getVisibleEditors(): IEditor[] {
this.callback('getVisibleEditors');
return [];
}
public openEditor(input: any, options?: any, position?: any): Promise {
this.callback('openEditor');
this.activeEditorInput = input;
this.activeEditorOptions = options;
this.activeEditorPosition = position;
return TPromise.as(null);
}
public closeEditor(position: Position, input: IEditorInput): TPromise<void> {
this.callback('closeEditor');
return TPromise.as(null);
}
public createInput(input: IResourceInput): IEditorInput {
return null;
}
}
export class TestNextEditorGroupsService implements INextEditorGroupsService {
export class TestEditorGroupsService implements INextEditorGroupsService {
_serviceBrand: ServiceIdentifier<any>;
constructor(public groups: TestNextEditorGroup[] = []) { }
constructor(public groups: TestEditorGroup[] = []) { }
onDidActiveGroupChange: Event<IEditorGroup> = Event.None;
onDidAddGroup: Event<IEditorGroup> = Event.None;
......@@ -778,7 +572,7 @@ export class TestNextEditorGroupsService implements INextEditorGroupsService {
}
}
export class TestNextEditorGroup implements IEditorGroup {
export class TestEditorGroup implements IEditorGroup {
constructor(public id: number) { }
......@@ -857,7 +651,7 @@ export class TestNextEditorGroup implements IEditorGroup {
}
}
export class TestNextEditorService implements INextEditorService {
export class TestEditorService implements INextEditorService {
_serviceBrand: ServiceIdentifier<any>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册