Fix most lint and tests

This commit is contained in:
Daniel Imms
2019-07-13 23:44:08 -07:00
parent 9315b50897
commit 358a707835
6 changed files with 64 additions and 60 deletions
+24 -22
View File
@@ -15,6 +15,8 @@ import { AttributeData } from 'common/buffer/AttributeData';
import { Params } from 'common/parser/Params'; import { Params } from 'common/parser/Params';
import { MockCoreService, MockBufferService, MockDirtyRowService, MockOptionsService, MockLogService } from 'common/TestUtils.test'; import { MockCoreService, MockBufferService, MockDirtyRowService, MockOptionsService, MockLogService } from 'common/TestUtils.test';
import { IBufferService } from 'common/services/Services'; import { IBufferService } from 'common/services/Services';
import { DEFAULT_OPTIONS } from '../out/common/services/OptionsService';
import { clone } from '../out/common/Clone';
function getCursor(term: TestTerminal): number[] { function getCursor(term: TestTerminal): number[] {
return [ return [
@@ -49,43 +51,43 @@ describe('InputHandler', () => {
}); });
describe('setCursorStyle', () => { describe('setCursorStyle', () => {
it('should call Terminal.setOption with correct params', () => { it('should call Terminal.setOption with correct params', () => {
const terminal = new MockInputHandlingTerminal(); const optionsService = new MockOptionsService();
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), new MockOptionsService()); const inputHandler = new InputHandler(new MockInputHandlingTerminal(), new MockBufferService(80, 30), new MockCoreService(), new MockDirtyRowService(), new MockLogService(), optionsService);
const collect = ' '; const collect = ' ';
inputHandler.setCursorStyle(Params.fromArray([0]), collect); inputHandler.setCursorStyle(Params.fromArray([0]), collect);
assert.equal(terminal.options['cursorStyle'], 'block'); assert.equal(optionsService.options['cursorStyle'], 'block');
assert.equal(terminal.options['cursorBlink'], true); assert.equal(optionsService.options['cursorBlink'], true);
terminal.options = {}; optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([1]), collect); inputHandler.setCursorStyle(Params.fromArray([1]), collect);
assert.equal(terminal.options['cursorStyle'], 'block'); assert.equal(optionsService.options['cursorStyle'], 'block');
assert.equal(terminal.options['cursorBlink'], true); assert.equal(optionsService.options['cursorBlink'], true);
terminal.options = {}; optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([2]), collect); inputHandler.setCursorStyle(Params.fromArray([2]), collect);
assert.equal(terminal.options['cursorStyle'], 'block'); assert.equal(optionsService.options['cursorStyle'], 'block');
assert.equal(terminal.options['cursorBlink'], false); assert.equal(optionsService.options['cursorBlink'], false);
terminal.options = {}; optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([3]), collect); inputHandler.setCursorStyle(Params.fromArray([3]), collect);
assert.equal(terminal.options['cursorStyle'], 'underline'); assert.equal(optionsService.options['cursorStyle'], 'underline');
assert.equal(terminal.options['cursorBlink'], true); assert.equal(optionsService.options['cursorBlink'], true);
terminal.options = {}; optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([4]), collect); inputHandler.setCursorStyle(Params.fromArray([4]), collect);
assert.equal(terminal.options['cursorStyle'], 'underline'); assert.equal(optionsService.options['cursorStyle'], 'underline');
assert.equal(terminal.options['cursorBlink'], false); assert.equal(optionsService.options['cursorBlink'], false);
terminal.options = {}; optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([5]), collect); inputHandler.setCursorStyle(Params.fromArray([5]), collect);
assert.equal(terminal.options['cursorStyle'], 'bar'); assert.equal(optionsService.options['cursorStyle'], 'bar');
assert.equal(terminal.options['cursorBlink'], true); assert.equal(optionsService.options['cursorBlink'], true);
terminal.options = {}; optionsService.options = clone(DEFAULT_OPTIONS);
inputHandler.setCursorStyle(Params.fromArray([6]), collect); inputHandler.setCursorStyle(Params.fromArray([6]), collect);
assert.equal(terminal.options['cursorStyle'], 'bar'); assert.equal(optionsService.options['cursorStyle'], 'bar');
assert.equal(terminal.options['cursorBlink'], false); assert.equal(optionsService.options['cursorBlink'], false);
}); });
}); });
describe('setMode', () => { describe('setMode', () => {
+1 -1
View File
@@ -590,7 +590,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._compositionView = document.createElement('div'); this._compositionView = document.createElement('div');
this._compositionView.classList.add('composition-view'); this._compositionView.classList.add('composition-view');
this._compositionHelper = new CompositionHelper(this.textarea, this._compositionView, this._bufferService, this.optionsService, this._charSizeService, this._coreService); this._compositionHelper = this._instantiationService.createInstance(CompositionHelper, this.textarea, this._compositionView);
this._helperContainer.appendChild(this._compositionView); this._helperContainer.appendChild(this._compositionView);
// Performance: Add viewport and helper elements from the fragment // Performance: Add viewport and helper elements from the fragment
+16 -16
View File
@@ -55,23 +55,23 @@ export class InstantiationService implements IInstantiationService {
public createInstance<T>(ctor: any, ...args: any[]): any { public createInstance<T>(ctor: any, ...args: any[]): any {
const serviceDependencies = getServiceDependencies(ctor).sort((a, b) => a.index - b.index); const serviceDependencies = getServiceDependencies(ctor).sort((a, b) => a.index - b.index);
let serviceArgs: any[] = []; const serviceArgs: any[] = [];
for (const dependency of serviceDependencies) { for (const dependency of serviceDependencies) {
let service = this._services.get(dependency.id); const service = this._services.get(dependency.id);
if (!service) { if (!service) {
throw new Error(`[createInstance] ${ctor.name} depends on UNKNOWN service ${dependency.id}.`); throw new Error(`[createInstance] ${ctor.name} depends on UNKNOWN service ${dependency.id}.`);
} }
serviceArgs.push(service); serviceArgs.push(service);
}
let firstServiceArgPos = serviceDependencies.length > 0 ? serviceDependencies[0].index : args.length;
// check for argument mismatches, adjust static args if needed
if (args.length !== firstServiceArgPos) {
throw new Error(`[createInstance] First service dependency of ${ctor.name} at position ${firstServiceArgPos + 1} conflicts with ${args.length} static arguments`);
} }
// now create the instance const firstServiceArgPos = serviceDependencies.length > 0 ? serviceDependencies[0].index : args.length;
return <T>new ctor(...[...args, ...serviceArgs]);
// check for argument mismatches, adjust static args if needed
if (args.length !== firstServiceArgPos) {
throw new Error(`[createInstance] First service dependency of ${ctor.name} at position ${firstServiceArgPos + 1} conflicts with ${args.length} static arguments`);
}
// now create the instance
return <T>new ctor(...[...args, ...serviceArgs]);
} }
} }
+19 -19
View File
@@ -42,7 +42,7 @@ export interface ICoreService {
* - Scroll to the bottom of the buffer.s * - Scroll to the bottom of the buffer.s
* - Fire the `onUserInput` event (so selection can be cleared). * - Fire the `onUserInput` event (so selection can be cleared).
*/ */
triggerDataEvent(data: string, wasUserInput?: boolean): void; triggerDataEvent(data: string, wasUserInput?: boolean): void;
} }
export const IDirtyRowService = createDecorator<IDirtyRowService>('DirtyRowService'); export const IDirtyRowService = createDecorator<IDirtyRowService>('DirtyRowService');
@@ -64,54 +64,54 @@ export interface IServiceIdentifier<T> {
} }
export interface IConstructorSignature0<T> { export interface IConstructorSignature0<T> {
new(...services: { _serviceBrand: any; }[]): T; new(...services: { _serviceBrand: any; }[]): T;
} }
export interface IConstructorSignature1<A1, T> { export interface IConstructorSignature1<A1, T> {
new(first: A1, ...services: { _serviceBrand: any; }[]): T; new(first: A1, ...services: { _serviceBrand: any; }[]): T;
} }
export interface IConstructorSignature2<A1, A2, T> { export interface IConstructorSignature2<A1, A2, T> {
new(first: A1, second: A2, ...services: { _serviceBrand: any; }[]): T; new(first: A1, second: A2, ...services: { _serviceBrand: any; }[]): T;
} }
export interface IConstructorSignature3<A1, A2, A3, T> { export interface IConstructorSignature3<A1, A2, A3, T> {
new(first: A1, second: A2, third: A3, ...services: { _serviceBrand: any; }[]): T; new(first: A1, second: A2, third: A3, ...services: { _serviceBrand: any; }[]): T;
} }
export interface IConstructorSignature4<A1, A2, A3, A4, T> { export interface IConstructorSignature4<A1, A2, A3, A4, T> {
new(first: A1, second: A2, third: A3, fourth: A4, ...services: { _serviceBrand: any; }[]): T; new(first: A1, second: A2, third: A3, fourth: A4, ...services: { _serviceBrand: any; }[]): T;
} }
export interface IConstructorSignature5<A1, A2, A3, A4, A5, T> { export interface IConstructorSignature5<A1, A2, A3, A4, A5, T> {
new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, ...services: { _serviceBrand: any; }[]): T; new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, ...services: { _serviceBrand: any; }[]): T;
} }
export interface IConstructorSignature6<A1, A2, A3, A4, A5, A6, T> { export interface IConstructorSignature6<A1, A2, A3, A4, A5, A6, T> {
new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, ...services: { _serviceBrand: any; }[]): T; new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, ...services: { _serviceBrand: any; }[]): T;
} }
export interface IConstructorSignature7<A1, A2, A3, A4, A5, A6, A7, T> { export interface IConstructorSignature7<A1, A2, A3, A4, A5, A6, A7, T> {
new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, ...services: { _serviceBrand: any; }[]): T; new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, ...services: { _serviceBrand: any; }[]): T;
} }
export interface IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T> { export interface IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T> {
new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8, ...services: { _serviceBrand: any; }[]): T; new(first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8, ...services: { _serviceBrand: any; }[]): T;
} }
export const IInstantiationService = createDecorator<IInstantiationService>('InstantiationService'); export const IInstantiationService = createDecorator<IInstantiationService>('InstantiationService');
export interface IInstantiationService { export interface IInstantiationService {
setService<T>(id: IServiceIdentifier<T>, instance: T): void; setService<T>(id: IServiceIdentifier<T>, instance: T): void;
createInstance<T>(ctor: IConstructorSignature0<T>): T; createInstance<T>(ctor: IConstructorSignature0<T>): T;
createInstance<A1, T>(ctor: IConstructorSignature1<A1, T>, first: A1): T; createInstance<A1, T>(ctor: IConstructorSignature1<A1, T>, first: A1): T;
createInstance<A1, A2, T>(ctor: IConstructorSignature2<A1, A2, T>, first: A1, second: A2): T; createInstance<A1, A2, T>(ctor: IConstructorSignature2<A1, A2, T>, first: A1, second: A2): T;
createInstance<A1, A2, A3, T>(ctor: IConstructorSignature3<A1, A2, A3, T>, first: A1, second: A2, third: A3): T; createInstance<A1, A2, A3, T>(ctor: IConstructorSignature3<A1, A2, A3, T>, first: A1, second: A2, third: A3): T;
createInstance<A1, A2, A3, A4, T>(ctor: IConstructorSignature4<A1, A2, A3, A4, T>, first: A1, second: A2, third: A3, fourth: A4): T; createInstance<A1, A2, A3, A4, T>(ctor: IConstructorSignature4<A1, A2, A3, A4, T>, first: A1, second: A2, third: A3, fourth: A4): T;
createInstance<A1, A2, A3, A4, A5, T>(ctor: IConstructorSignature5<A1, A2, A3, A4, A5, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5): T; createInstance<A1, A2, A3, A4, A5, T>(ctor: IConstructorSignature5<A1, A2, A3, A4, A5, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5): T;
createInstance<A1, A2, A3, A4, A5, A6, T>(ctor: IConstructorSignature6<A1, A2, A3, A4, A5, A6, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6): T; createInstance<A1, A2, A3, A4, A5, A6, T>(ctor: IConstructorSignature6<A1, A2, A3, A4, A5, A6, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6): T;
createInstance<A1, A2, A3, A4, A5, A6, A7, T>(ctor: IConstructorSignature7<A1, A2, A3, A4, A5, A6, A7, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7): T; createInstance<A1, A2, A3, A4, A5, A6, A7, T>(ctor: IConstructorSignature7<A1, A2, A3, A4, A5, A6, A7, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7): T;
createInstance<A1, A2, A3, A4, A5, A6, A7, A8, T>(ctor: IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8): T; createInstance<A1, A2, A3, A4, A5, A6, A7, A8, T>(ctor: IConstructorSignature8<A1, A2, A3, A4, A5, A6, A7, A8, T>, first: A1, second: A2, third: A3, fourth: A4, fifth: A5, sixth: A6, seventh: A7, eigth: A8): T;
} }
export const ILogService = createDecorator<ILogService>('LogService'); export const ILogService = createDecorator<ILogService>('LogService');
+2 -2
View File
@@ -26,12 +26,12 @@ export class Renderer extends Disposable implements IRenderer {
constructor( constructor(
private _colors: IColorSet, private _colors: IColorSet,
private readonly _terminal: ITerminal, private readonly _terminal: ITerminal,
readonly _bufferService: IBufferService, readonly bufferService: IBufferService,
private readonly _charSizeService: ICharSizeService private readonly _charSizeService: ICharSizeService
) { ) {
super(); super();
const allowTransparency = this._terminal.options.allowTransparency; const allowTransparency = this._terminal.options.allowTransparency;
this._characterJoinerRegistry = new CharacterJoinerRegistry(this._bufferService); this._characterJoinerRegistry = new CharacterJoinerRegistry(bufferService);
this._renderLayers = [ this._renderLayers = [
new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency), new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency),
+2
View File
@@ -94,6 +94,8 @@
{"type": "member", "modifiers": ["private"], "format": "camelCase", "leadingUnderscore": "require"}, {"type": "member", "modifiers": ["private"], "format": "camelCase", "leadingUnderscore": "require"},
{"type": "variable", "modifiers": ["const"], "format": ["camelCase", "UPPER_CASE"]}, {"type": "variable", "modifiers": ["const"], "format": ["camelCase", "UPPER_CASE"]},
{"type": "variable", "modifiers": ["const", "export"], "filter": "^I.+Service$", "format": "PascalCase", "prefix": "I"}, {"type": "variable", "modifiers": ["const", "export"], "filter": "^I.+Service$", "format": "PascalCase", "prefix": "I"},
{"type": "member", "filter": "^_serviceBrand$", "leadingUnderscore": "require"},
{"type": "property", "filter": "^_serviceBrand$", "leadingUnderscore": "require"},
{"type": "interface", "prefix": "I"} {"type": "interface", "prefix": "I"}
], ],
"no-else-after-return": { "no-else-after-return": {