import ts, { type CompilerOptions } from 'typescript';
import type { PerformanceTracker } from "./performanceTracking.mjs";
export interface TypesMetaOptions {
  /**
   * Any additional options passed from the factory call
   */
  [key: string]: any;
}
/**
 * In-memory language service host that manages TypeScript files dynamically.
 *
 * Root files are replaced (not accumulated) on each call via `setRootFiles()`,
 * so the TypeScript program only contains the dependencies of the component
 * currently being analyzed. The file content cache (`files`) persists across
 * calls, allowing the DocumentRegistry to reuse parsed SourceFiles.
 *
 * Implements `getProjectVersion()` so the language service can skip per-file
 * version checks when nothing has changed.
 *
 * Uses filesystem watchers (one per directory) to detect changes efficiently
 * during development, instead of re-reading every tracked file from disk.
 */
declare class InMemoryLanguageServiceHost implements ts.LanguageServiceHost {
  /**
   * Content and version cache for ALL files (entrypoints + transitive dependencies).
   * Used by getScriptVersion and getScriptSnapshot to serve cached data.
   * Persists across calls so the DocumentRegistry can reuse parsed SourceFiles.
   */
  private files;
  /**
   * Current entrypoints for this call. Replaced (not accumulated) on each
   * `createOptimizedProgram` invocation so the program only contains the
   * dependencies of the component currently being analyzed.
   */
  private rootFiles;
  /**
   * Monotonically increasing version string returned by `getProjectVersion()`.
   * TypeScript's language service checks this first — if unchanged it skips
   * per-file version checks entirely, avoiding O(n) `getScriptVersion` calls.
   */
  private projectVersion;
  private options;
  private projectPath;
  private getVersionCallCount;
  private getSnapshotCallCount;
  /** Set of file paths that have been flagged as changed by fs watchers */
  private changedFiles;
  /** Active directory watchers, keyed by directory path */
  private dirWatchers;
  /** Directories where watcher setup failed — these need polling fallback */
  private unwatchedDirs;
  constructor(projectPath: string, options: ts.CompilerOptions);
  resetCallCounts(): void;
  getCallCounts(): {
    version: number;
    snapshot: number;
  };
  /**
   * Ensures a directory watcher exists for the given file's parent directory.
   * When any file in that directory changes, all tracked files in that directory
   * are added to the changedFiles set.
   *
   * If watcher setup fails, the directory is added to `unwatchedDirs` so
   * `updateChangedFiles` can fall back to polling for files in that directory.
   */
  private ensureWatcher;
  /**
   * Replaces the current root files with the given entrypoints.
   * Only bumps the project version when entrypoints or their contents change,
   * so the language service can skip per-file version checks on unchanged calls.
   */
  setRootFiles(entrypoints: string[]): void;
  /**
   * Checks whether the given entrypoints match the current root files (same order).
   */
  private rootFilesMatch;
  getProjectVersion(): string;
  getScriptFileNames(): string[];
  getScriptVersion(fileName: string): string;
  getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined;
  getCurrentDirectory(): string;
  getCompilationSettings(): ts.CompilerOptions;
  getDefaultLibFileName(options: ts.CompilerOptions): string;
  fileExists(fileName: string): boolean;
  readFile(fileName: string): string | undefined;
  resolveModuleNames(moduleNames: string[], containingFile: string): (ts.ResolvedModule | undefined)[];
  /**
   * Updates files that have changed since the last call.
   *
   * For directories with active watchers, only re-reads files the OS flagged.
   * For directories where watchers failed, polls all tracked files in those
   * directories to detect changes (fallback behavior).
   */
  updateChangedFiles(): {
    updated: string[];
    unchanged: number;
  };
  /**
   * Closes all directory watchers. Call when the language service is no longer needed.
   */
  closeWatchers(): void;
}
/**
 * Singleton instance that manages a TypeScript language service across multiple calls
 */
interface LanguageServiceInstance {
  host: InMemoryLanguageServiceHost;
  service: ts.LanguageService;
  projectPath: string;
  compilerOptions: ts.CompilerOptions;
}
declare global {
  var typesMetaLanguageService: LanguageServiceInstance | undefined;
}
/**
 * Creates an optimized TypeScript program for component analysis using a global language service.
 *
 * This function uses a singleton language service that persists across calls:
 * - Reuses the same language service and DocumentRegistry across calls
 * - Sets root files to only the current entrypoints (not accumulated)
 * - Caches file contents so the DocumentRegistry can reuse parsed SourceFiles
 * - Components with heavy dependencies (e.g. date-fns) don't slow down other components
 *
 * @param projectPath - Path to the project directory
 * @param compilerOptions - TypeScript compiler options
 * @param entrypoints - Array of TypeScript files to analyze
 * @param options - Additional configuration options
 * @param tracker - Performance tracker for measurements
 * @param functionName - Name for performance markers
 * @param context - Context for performance markers
 * @returns Optimized TypeScript program
 */
export declare function createOptimizedProgram(projectPath: string, compilerOptions: CompilerOptions, entrypoints: string[], _options?: TypesMetaOptions, tracker?: PerformanceTracker, functionName?: string, context?: string[]): ts.Program;
export {};