|
| 1 | + |
| 2 | +// @ts-nocheck |
| 3 | +// Mocked Uri interface |
| 4 | +export interface Uri { |
| 5 | + scheme: string; |
| 6 | + path: string; |
| 7 | +} |
| 8 | + |
| 9 | +// Mocked Position class |
| 10 | +export class Position { |
| 11 | + constructor(public line: number, public character: number) { } |
| 12 | + |
| 13 | + isBefore(other: Position): boolean { |
| 14 | + return this.line < other.line || (this.line === other.line && this.character < other.character); |
| 15 | + } |
| 16 | + |
| 17 | + // Mocked methods |
| 18 | + isBeforeOrEqual = jest.fn((other: Position) => this.isBefore(other) || this.isEqual(other)); |
| 19 | + isAfter = jest.fn((other: Position) => !this.isBeforeOrEqual(other)); |
| 20 | + isAfterOrEqual = jest.fn((other: Position) => this.isAfter(other) || this.isEqual(other)); |
| 21 | + isEqual = jest.fn((other: Position) => this.line === other.line && this.character === other.character); |
| 22 | + compareTo = jest.fn((other: Position) => { |
| 23 | + if (this.isBefore(other)) return -1; |
| 24 | + if (this.isAfter(other)) return 1; |
| 25 | + return 0; |
| 26 | + }); |
| 27 | + translate = jest.fn((lineDelta?: number, characterDelta?: number) => { |
| 28 | + const line = typeof lineDelta === 'number' ? this.line + lineDelta : this.line; |
| 29 | + const character = typeof characterDelta === 'number' ? this.character + characterDelta : this.character; |
| 30 | + return new Position(line, character); |
| 31 | + }); |
| 32 | + with = jest.fn((line?: number, character?: number) => new Position(line ?? this.line, character ?? this.character)); |
| 33 | +} |
| 34 | + |
| 35 | +// Mocked Range class |
| 36 | +export class Range { |
| 37 | + constructor(public start: Position, public end: Position) { } |
| 38 | + |
| 39 | + isEmpty = jest.fn(() => this.start.isEqual(this.end)); |
| 40 | + isSingleLine = jest.fn(() => this.start.line === this.end.line); |
| 41 | + contains = jest.fn((positionOrRange: Position | Range) => { |
| 42 | + if (positionOrRange instanceof Position) { |
| 43 | + return ( |
| 44 | + (positionOrRange.isAfterOrEqual(this.start) && positionOrRange.isBefore(this.end)) || |
| 45 | + positionOrRange.isEqual(this.start) || |
| 46 | + positionOrRange.isEqual(this.end) |
| 47 | + ); |
| 48 | + } |
| 49 | + return ( |
| 50 | + this.contains(positionOrRange.start) || |
| 51 | + this.contains(positionOrRange.end) || |
| 52 | + (positionOrRange.start.isBeforeOrEqual(this.start) && positionOrRange.end.isAfterOrEqual(this.end)) |
| 53 | + ); |
| 54 | + }); |
| 55 | + isEqual = jest.fn((other: Range) => this.start.isEqual(other.start) && this.end.isEqual(other.end)); |
| 56 | + intersection = jest.fn((range: Range) => { |
| 57 | + const start = this.start.isBefore(range.start) ? range.start : this.start; |
| 58 | + const end = this.end.isAfter(range.end) ? range.end : this.end; |
| 59 | + return start.isBefore(end) ? new Range(start, end) : undefined; |
| 60 | + }); |
| 61 | + union = jest.fn((other: Range) => { |
| 62 | + const start = this.start.isBefore(other.start) ? this.start : other.start; |
| 63 | + const end = this.end.isAfter(other.end) ? this.end : other.end; |
| 64 | + return new Range(start, end); |
| 65 | + }); |
| 66 | + with = jest.fn((start?: Position, end?: Position) => new Range(start ?? this.start, end ?? this.end)); |
| 67 | +} |
| 68 | + |
| 69 | +// Mocked TextDocument interface |
| 70 | +export interface TextDocument { |
| 71 | + uri: Uri; |
| 72 | + fileName: string; |
| 73 | + languageId: string; |
| 74 | + version: number; |
| 75 | + isDirty: boolean; |
| 76 | + isClosed: boolean; |
| 77 | + |
| 78 | + // Implement other properties and methods |
| 79 | +} |
| 80 | + |
| 81 | +export class ExtensionContextMock { |
| 82 | + // Add any necessary properties and methods here for your tests |
| 83 | + subscriptions: { dispose: jest.Mock }[] = []; |
| 84 | + |
| 85 | + // Mock method to subscribe to events |
| 86 | + subscribe(subscription: { dispose: jest.Mock }): void { |
| 87 | + this.subscriptions.push(subscription); |
| 88 | + } |
| 89 | + |
| 90 | + // Mock method to trigger disposal of subscriptions |
| 91 | + dispose(): void { |
| 92 | + this.subscriptions.forEach(sub => sub.dispose()); |
| 93 | + this.subscriptions = []; |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +// Mocked vscode module |
| 98 | +const vscode = { |
| 99 | + version: '1.0.0', |
| 100 | + Position, |
| 101 | + Range, |
| 102 | + Uri: { scheme: '', path: '' }, |
| 103 | + window: { |
| 104 | + activeTextEditor: { |
| 105 | + document: null as TextDocument | null, |
| 106 | + }, |
| 107 | + }, |
| 108 | + commands: { |
| 109 | + executeCommand: jest.fn(), |
| 110 | + }, |
| 111 | + languages: { |
| 112 | + getTextDocument: jest.fn(), |
| 113 | + }, |
| 114 | + env: { |
| 115 | + isTelemetryEnabled: true, |
| 116 | + machineId: '123456789', |
| 117 | + }, |
| 118 | +}; |
| 119 | + |
| 120 | +vscode.ExtensionContext = ExtensionContextMock; |
| 121 | + |
| 122 | +export default vscode; |
0 commit comments