Skip to content

Commit f51079a

Browse files
committed
Make chat tab definition in extensions more flexible
1 parent 5551e1f commit f51079a

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

Tool/Sources/BuiltinExtension/BuiltinExtension.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public protocol BuiltinExtension: CopilotForXcodeExtensionCapability {
1111
var extensionIdentifier: String { get }
1212

1313
/// All chat builders provided by this extension.
14-
var chatTabTypes: [any ChatTab.Type] { get }
14+
var chatTabTypes: [any CustomChatTab] { get }
1515

1616
/// It's usually called when the app is about to quit,
1717
/// you should clean up all the resources here.
@@ -22,7 +22,7 @@ public protocol BuiltinExtension: CopilotForXcodeExtensionCapability {
2222

2323
public extension BuiltinExtension {
2424
var suggestionServiceId: BuiltInSuggestionFeatureProvider? { nil }
25-
var chatTabTypes: [any ChatTab.Type] { [] }
25+
var chatTabTypes: [any CustomChatTab] { [] }
2626
}
2727

2828
// MAKR: - ChatService
@@ -42,7 +42,7 @@ public protocol BuiltinExtensionChatServiceType: ChatServiceType {
4242
public struct RetrievedContent {
4343
public var document: ChatMessage.Reference
4444
public var priority: Int
45-
45+
4646
public init(document: ChatMessage.Reference, priority: Int) {
4747
self.document = document
4848
self.priority = priority
@@ -63,3 +63,29 @@ public enum ChatServiceMemoryMutation: Codable {
6363
case streamIntoMessage(id: String, role: Message.Role?, text: String?)
6464
}
6565

66+
public protocol CustomChatTab {
67+
var name: String { get }
68+
var isDefaultChatTabReplacement: Bool { get }
69+
var canHandleOpenChatCommand: Bool { get }
70+
func chatBuilders() -> [ChatTabBuilder]
71+
func defaultChatBuilder() -> ChatTabBuilder
72+
func restore(from data: Data) async throws -> any ChatTabBuilder
73+
}
74+
75+
public struct TypedCustomChatTab: CustomChatTab {
76+
public let type: ChatTab.Type
77+
78+
public init(of type: ChatTab.Type) {
79+
self.type = type
80+
}
81+
82+
public var name: String { type.name }
83+
public var isDefaultChatTabReplacement: Bool { type.isDefaultChatTabReplacement }
84+
public var canHandleOpenChatCommand: Bool { type.canHandleOpenChatCommand }
85+
public func chatBuilders() -> [ChatTabBuilder] { type.chatBuilders() }
86+
public func defaultChatBuilder() -> ChatTabBuilder { type.defaultChatBuilder() }
87+
public func restore(from data: Data) async throws -> any ChatTabBuilder {
88+
try await type.restore(from: data)
89+
}
90+
}
91+

Tool/Sources/CodeiumService/CodeiumExtension.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import Workspace
1313

1414
public final class CodeiumExtension: BuiltinExtension {
1515
public var extensionIdentifier: String { "com.codeium" }
16-
16+
1717
public var suggestionServiceId: Preferences.BuiltInSuggestionFeatureProvider { .codeium }
1818

1919
public let suggestionService: CodeiumSuggestionService
20-
21-
public var chatTabTypes: [any ChatTab.Type] {
22-
[CodeiumChatTab.self]
20+
21+
public var chatTabTypes: [any CustomChatTab] {
22+
[TypedCustomChatTab(of: CodeiumChatTab.self)]
2323
}
2424

2525
private var extensionUsage = ExtensionUsage(

0 commit comments

Comments
 (0)