|
| 1 | +import Dependencies |
| 2 | +import Foundation |
| 3 | +import Preferences |
| 4 | +import SuggestionBasic |
| 5 | +import Toast |
| 6 | +import XcodeInspector |
| 7 | + |
| 8 | +/// Provides an interface to handle commands. |
| 9 | +public protocol CommandHandler { |
| 10 | + // MARK: Suggestion |
| 11 | + |
| 12 | + func presentSuggestions(_ suggestions: [CodeSuggestion]) async |
| 13 | + func presentPreviousSuggestion() async |
| 14 | + func presentNextSuggestion() async |
| 15 | + func rejectSuggestions() async |
| 16 | + func acceptSuggestion() async |
| 17 | + func dismissSuggestion() async |
| 18 | + func generateRealtimeSuggestions(sourceEditor: SourceEditor?) async |
| 19 | + |
| 20 | + // MARK: Chat |
| 21 | + |
| 22 | + func openChat(forceDetach: Bool) |
| 23 | + func sendChatMessage(_ message: String) async |
| 24 | + |
| 25 | + // MARK: Prompt to Code |
| 26 | + |
| 27 | + func acceptPromptToCode() async |
| 28 | + |
| 29 | + // MARK: Custom Command |
| 30 | + |
| 31 | + func handleCustomCommand(_ command: CustomCommand) async |
| 32 | + |
| 33 | + // MARK: Toast |
| 34 | + |
| 35 | + func toast(_ string: String, as type: ToastType) |
| 36 | +} |
| 37 | + |
| 38 | +public struct CommandHandlerDependencyKey: DependencyKey { |
| 39 | + public static var liveValue: CommandHandler = NoopCommandHandler() |
| 40 | +} |
| 41 | + |
| 42 | +public extension DependencyValues { |
| 43 | + var commandHandler: CommandHandler { |
| 44 | + get { self[CommandHandlerDependencyKey.self] } |
| 45 | + set { self[CommandHandlerDependencyKey.self] = newValue } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +struct NoopCommandHandler: CommandHandler { |
| 50 | + static let shared: CommandHandler = NoopCommandHandler() |
| 51 | + |
| 52 | + func presentSuggestions(_: [CodeSuggestion]) async {} |
| 53 | + func presentPreviousSuggestion() async {} |
| 54 | + func presentNextSuggestion() async {} |
| 55 | + func rejectSuggestions() async {} |
| 56 | + func acceptSuggestion() async {} |
| 57 | + func dismissSuggestion() async {} |
| 58 | + func generateRealtimeSuggestions(sourceEditor: SourceEditor?) async {} |
| 59 | + func openChat(forceDetach: Bool) {} |
| 60 | + func sendChatMessage(_: String) async {} |
| 61 | + func acceptPromptToCode() async {} |
| 62 | + func handleCustomCommand(_: CustomCommand) async {} |
| 63 | + func toast(_: String, as: ToastType) {} |
| 64 | +} |
| 65 | + |
0 commit comments