All files / src/scope status-cache.ts

58.33% Statements 21/36
66.66% Branches 2/3
40% Functions 2/5
58.33% Lines 21/36

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 371x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x             1x 1x 11x 11x         11x 1x 1x     1x  
import * as vscode from 'vscode';
 
export interface ReviewStatus {
  issueCount: number;
  timestamp: number;
}
 
export class ReviewStatusCache {
  private cache = new Map<string, ReviewStatus>();
 
  get(uri: vscode.Uri, methodName: string): ReviewStatus | null {
    const key = this.buildKey(uri, methodName);
    return this.cache.get(key) ?? null;
  }
 
  set(uri: vscode.Uri, methodName: string, issueCount: number): void {
    const key = this.buildKey(uri, methodName);
    this.cache.set(key, {
      issueCount,
      timestamp: Date.now(),
    });
  }
 
  clearDocument(uri: vscode.Uri): void {
    const prefix = uri.toString() + '::';
    for (const key of this.cache.keys()) {
      if (key.startsWith(prefix)) {
        this.cache.delete(key);
      }
    }
  }
 
  private buildKey(uri: vscode.Uri, methodName: string): string {
    return uri.toString() + '::' + methodName;
  }
}