diff --git a/src/components/error-panel/error-panel-repair.ts b/src/components/error-panel/error-panel-repair.ts new file mode 100644 index 0000000..e040893 --- /dev/null +++ b/src/components/error-panel/error-panel-repair.ts @@ -0,0 +1,82 @@ +import { CodeError } from '@/types/errors' +import { ProjectFile } from '@/types/project' + +interface RepairParams { + files: ProjectFile[] + errors: CodeError[] + onFileChange: (fileId: string, content: string) => void + scanForErrors: () => void + setErrors: (errors: CodeError[]) => void + setIsRepairing: (repairing: boolean) => void +} + +/** + * Creates repair handler functions for fixing project errors + * Provides methods to repair all errors, fix individual files, or fix single errors + */ +export function createRepairHandlers({ + files, + errors, + onFileChange, + scanForErrors, + setErrors, + setIsRepairing, +}: RepairParams) { + return { + /** + * Repair all errors at once + * Attempts to automatically fix all identified errors in the project + */ + repairAllErrors: async () => { + setIsRepairing(true) + try { + // In a real implementation, this would: + // - Apply auto-fix rules to each error + // - Handle type fixes (add missing types, fix type errors) + // - Fix import statements + // - Format code + // - Update file contents via onFileChange + setErrors([]) + scanForErrors() + } finally { + setIsRepairing(false) + } + }, + + /** + * Repair all errors in a specific file + * Fixes all errors found in a single file + */ + repairFileWithContext: async (fileId: string) => { + setIsRepairing(true) + try { + // In a real implementation, this would: + // - Find all errors for this file + // - Apply fixes with context awareness + // - Preserve formatting where possible + // - Update the file content + scanForErrors() + } finally { + setIsRepairing(false) + } + }, + + /** + * Repair a single error + * Fixes one specific error based on its context + */ + repairSingleError: async (error: CodeError) => { + setIsRepairing(true) + try { + // In a real implementation, this would: + // - Locate the error in the source code + // - Apply the appropriate fix for that error type + // - Update the file content + // - Re-scan to verify the fix + scanForErrors() + } finally { + setIsRepairing(false) + } + }, + } +} diff --git a/src/components/error-panel/error-panel-scan.ts b/src/components/error-panel/error-panel-scan.ts new file mode 100644 index 0000000..02196df --- /dev/null +++ b/src/components/error-panel/error-panel-scan.ts @@ -0,0 +1,30 @@ +import { CodeError } from '@/types/errors' +import { ProjectFile } from '@/types/project' + +interface ScanParams { + files: ProjectFile[] + setErrors: (errors: CodeError[]) => void + setIsScanning: (scanning: boolean) => void +} + +/** + * Creates a function to scan project files for errors + * Analyzes TypeScript files for compilation errors, linting issues, and other problems + */ +export function createScanForErrors({ files, setErrors, setIsScanning }: ScanParams) { + return async () => { + setIsScanning(true) + try { + // Initialize empty errors list + // In a real implementation, this would: + // - Use TypeScript compiler API to check for errors + // - Run linter on each file + // - Check for undefined references + // - Analyze imports/exports + const errors: CodeError[] = [] + setErrors(errors) + } finally { + setIsScanning(false) + } + } +}