From 5684f95c8efa5508a925ecd99733adfe3ee53f92 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 31 May 2026 14:37:01 -0700 Subject: [PATCH] Colocate circular list types in CircularList.ts The import/no-cycle refactor had moved IInsertEvent, IDeleteEvent, and ICircularList into Types.ts, with CircularList.ts re-exporting the event types from there. That split the list abstraction from its implementation and pulled Types into the circular-list dependency graph. Define IInsertEvent, IDeleteEvent, and ICircularList in CircularList.ts alongside the CircularList class. CircularList.ts now depends only on Lifecycle and Event, not Types.ts. Remove those definitions from Types.ts (and the unused Emitter import). Update callers to import list types from CircularList: - buffer/Types.ts (IBuffer.lines) - DecorationService.ts (buffer line insert/delete handlers) - browser TestUtils.test.ts (mock buffer lines) Types.ts no longer imports or re-exports circular-list types, preserving the acyclic Types -> buffer/CircularList boundary. Co-authored-by: Cursor --- src/browser/TestUtils.test.ts | 3 +- src/common/CircularList.ts | 35 ++++++++++++++++++++++-- src/common/Types.ts | 34 +---------------------- src/common/buffer/Types.ts | 3 +- src/common/services/DecorationService.ts | 4 +-- 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/browser/TestUtils.test.ts b/src/browser/TestUtils.test.ts index d99c7244b..7b3464595 100644 --- a/src/browser/TestUtils.test.ts +++ b/src/browser/TestUtils.test.ts @@ -8,7 +8,8 @@ import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IMouseS import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from './renderer/shared/Types'; import { IColorSet, ITerminal, ILinkifier2, IBrowser, IViewport, ICompositionHelper, CharacterJoinerHandler, IBufferRange, ReadonlyColorSet, IBufferElementProvider } from './Types'; import { IAttributeData, IBuffer, IBufferLine, IBufferSet, ICellData } from '../common/buffer/Types'; -import { ICircularList, XtermListener, ICharset, ITerminalOptions, ColorIndex } from '../common/Types'; +import { ICircularList } from '../common/CircularList'; +import { XtermListener, ICharset, ITerminalOptions, ColorIndex } from '../common/Types'; import { Buffer } from '../common/buffer/Buffer'; import * as Browser from '../common/Platform'; import { CoreBrowserTerminal } from './CoreBrowserTerminal'; diff --git a/src/common/CircularList.ts b/src/common/CircularList.ts index 21dd081da..b773391f9 100644 --- a/src/common/CircularList.ts +++ b/src/common/CircularList.ts @@ -3,11 +3,40 @@ * @license MIT */ -import { ICircularList, IDeleteEvent, IInsertEvent } from './Types'; import { Disposable } from './Lifecycle'; -import { Emitter } from './Event'; +import { Emitter, type IEvent } from './Event'; -export type { IDeleteEvent, IInsertEvent } from './Types'; +export interface IInsertEvent { + index: number; + amount: number; +} + +export interface IDeleteEvent { + index: number; + amount: number; +} + +export interface ICircularList { + length: number; + maxLength: number; + isFull: boolean; + + onDeleteEmitter: Emitter; + onDelete: IEvent; + onInsertEmitter: Emitter; + onInsert: IEvent; + onTrimEmitter: Emitter; + onTrim: IEvent; + + get(index: number): T | undefined; + set(index: number, value: T): void; + push(value: T): void; + recycle(): T; + pop(): T | undefined; + splice(start: number, deleteCount: number, ...items: T[]): void; + trimStart(count: number): void; + shiftElements(start: number, count: number, offset: number): void; +} /** * Represents a circular list; a list with a maximum size that wraps around when push is called, diff --git a/src/common/Types.ts b/src/common/Types.ts index c2416c6c9..9e1481fd3 100644 --- a/src/common/Types.ts +++ b/src/common/Types.ts @@ -4,17 +4,7 @@ */ import { IFunctionIdentifier, ITerminalOptions as IPublicTerminalOptions } from '@xterm/xterm'; -import type { Emitter, IEvent } from './Event'; - -export interface IInsertEvent { - index: number; - amount: number; -} - -export interface IDeleteEvent { - index: number; - amount: number; -} +import type { IEvent } from './Event'; /** sequence params serialized to js arrays */ export type ParamsArray = (number | number[])[]; @@ -78,28 +68,6 @@ export interface IScrollEvent { position: number; } -export interface ICircularList { - length: number; - maxLength: number; - isFull: boolean; - - onDeleteEmitter: Emitter; - onDelete: IEvent; - onInsertEmitter: Emitter; - onInsert: IEvent; - onTrimEmitter: Emitter; - onTrim: IEvent; - - get(index: number): T | undefined; - set(index: number, value: T): void; - push(value: T): void; - recycle(): T; - pop(): T | undefined; - splice(start: number, deleteCount: number, ...items: T[]): void; - trimStart(count: number): void; - shiftElements(start: number, count: number, offset: number): void; -} - export const enum KeyboardResultType { SEND_KEY, SELECT_ALL, diff --git a/src/common/buffer/Types.ts b/src/common/buffer/Types.ts index 174defb9b..994ca0f43 100644 --- a/src/common/buffer/Types.ts +++ b/src/common/buffer/Types.ts @@ -4,7 +4,8 @@ */ import type { IEvent } from '../Event'; -import type { ICircularList, ICharset } from '../Types'; +import type { ICircularList } from '../CircularList'; +import type { ICharset } from '../Types'; import type { IDisposable } from '../Lifecycle'; import type { UnderlineStyle } from './Constants'; diff --git a/src/common/services/DecorationService.ts b/src/common/services/DecorationService.ts index 5c2a1d33a..ea9b7fb14 100644 --- a/src/common/services/DecorationService.ts +++ b/src/common/services/DecorationService.ts @@ -3,13 +3,13 @@ * @license MIT */ -import type { IDeleteEvent, IInsertEvent } from '../CircularList'; +import type { ICircularList, IDeleteEvent, IInsertEvent } from '../CircularList'; import { MicrotaskTimer } from '../Async'; import { css } from '../Color'; import { Disposable, DisposableStore, MutableDisposable, toDisposable } from '../Lifecycle'; import { IBufferService, IDecorationService, IInternalDecoration, ILogService } from './Services'; import { SortedList } from '../SortedList'; -import { IColor, ICircularList } from '../Types'; +import { IColor } from '../Types'; import { IDecoration, IDecorationOptions, IMarker } from '@xterm/xterm'; import { Emitter } from '../Event';