import JSONRPC import Combine import Workspace import XcodeInspector import Foundation import ConversationServiceProvider import LanguageServerProtocol public protocol WatchedFilesHandler { func handleWatchedFiles(_ request: WatchedFilesRequest, workspaceURL: URL, completion: @escaping (AnyJSONRPCResponse) -> Void, service: GitHubCopilotService?) } public final class WatchedFilesHandlerImpl: WatchedFilesHandler { public static let shared = WatchedFilesHandlerImpl() public func handleWatchedFiles(_ request: WatchedFilesRequest, workspaceURL: URL, completion: @escaping (AnyJSONRPCResponse) -> Void, service: GitHubCopilotService?) { guard let params = request.params, params.workspaceFolder.uri != "/" else { return } let projectURL = WorkspaceXcodeWindowInspector.extractProjectURL(workspaceURL: workspaceURL, documentURL: nil) ?? workspaceURL let files = WorkspaceFile.getWatchedFiles( workspaceURL: workspaceURL, projectURL: projectURL, excludeGitIgnoredFiles: params.excludeGitignoredFiles, excludeIDEIgnoredFiles: params.excludeIDEIgnoredFiles ) WorkspaceFileIndex.shared.setFiles(files, for: workspaceURL) let fileUris = files.prefix(10000).map { $0.url.absoluteString } // Set max number of indexing file to 10000 let batchSize = BatchingFileChangeWatcher.maxEventPublishSize Task { var sentCount = 0 if params.partialResultToken != nil && fileUris.count > batchSize { for startIndex in stride(from: 0, to: fileUris.count, by: batchSize) { let endIndex = min(startIndex + batchSize, fileUris.count) let partialResult = Array(fileUris[startIndex.. ProgressParams? { let copilotProgress = CopilotProgressParams(token: token, value: value) if let jsonData = try? JSONEncoder().encode(copilotProgress), let progressParams = try? JSONDecoder().decode(ProgressParams.self, from: jsonData) { return progressParams } return nil } }