All files / src/fix fixPending.ts

70.12% Statements 54/77
75% Branches 3/4
27.27% Functions 3/11
70.12% Lines 54/77

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 781x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 22x 22x 22x 1x 1x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x     1x 1x               1x 1x     1x 1x     1x 1x     1x 1x 11x 11x     11x 11x 1x  
import * as vscode from 'vscode';
import type { AppliedFix } from './fixEngine';
 
export interface PendingFix {
  key: string;
  ruleId: string;
  line: number;
  filePath: string;
  source: 'linter' | 'custom' | 'ai';
  originalText: string;
  newText: string;
  appliedFixes: AppliedFix[];
  diffUri?: vscode.Uri;
}
 
export interface PendingBatch {
  filePath: string;
  source: 'linter' | 'custom' | 'ai';
  originalText: string;
  newText: string;
  results: { ruleId: string; line: number; appliedFixes: AppliedFix[] }[];
  diffUri?: vscode.Uri;
}
 
function fileKey(filePath: string): string {
  return `file:${filePath}`;
}
 
export class FixPendingStore {
  private singles = new Map<string, PendingFix>();
  private batches = new Map<string, PendingBatch>();
 
  setSingle(fix: PendingFix): void {
    this.singles.set(fileKey(fix.filePath) + '|' + fix.key, fix);
  }
 
  getSingle(filePath: string, key: string): PendingFix | undefined {
    return this.singles.get(fileKey(filePath) + '|' + key);
  }
 
  hasSingle(filePath: string, key: string): boolean {
    return this.singles.has(fileKey(filePath) + '|' + key);
  }
 
  deleteSingle(filePath: string, key: string): void {
    this.singles.delete(fileKey(filePath) + '|' + key);
  }
 
  singleKeys(filePath: string): string[] {
    const prefix = fileKey(filePath) + '|';
    const keys: string[] = [];
    for (const k of this.singles.keys()) {
      if (k.startsWith(prefix)) { keys.push(k.slice(prefix.length)); }
    }
    return keys;
  }
 
  setBatch(batch: PendingBatch): void {
    this.batches.set(fileKey(batch.filePath), batch);
  }
 
  getBatch(filePath: string): PendingBatch | undefined {
    return this.batches.get(fileKey(filePath));
  }
 
  deleteBatch(filePath: string): void {
    this.batches.delete(fileKey(filePath));
  }
 
  clear(filePath: string): void {
    const prefix = fileKey(filePath) + '|';
    for (const k of this.singles.keys()) {
      if (k.startsWith(prefix)) { this.singles.delete(k); }
    }
    this.batches.delete(fileKey(filePath));
  }
}