Skip to content

Commit 3d1ee47

Browse files
committed
Add new command CustomCommand
1 parent 41f8ddc commit 3d1ee47

File tree

11 files changed

+196
-127
lines changed

11 files changed

+196
-127
lines changed

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
C861E6152994F6080056CB02 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C861E6142994F6080056CB02 /* Assets.xcassets */; };
3838
C861E61E2994F6150056CB02 /* Service in Frameworks */ = {isa = PBXBuildFile; productRef = C861E61D2994F6150056CB02 /* Service */; };
3939
C861E6202994F63A0056CB02 /* ServiceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C861E61F2994F6390056CB02 /* ServiceDelegate.swift */; };
40+
C8758E7029F04BFF00D29C1C /* CustomCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8758E6F29F04BFF00D29C1C /* CustomCommand.swift */; };
41+
C8758E7229F04CF100D29C1C /* SeparatorCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8758E7129F04CF100D29C1C /* SeparatorCommand.swift */; };
4042
C87B03A5293B261200C77EAE /* AcceptSuggestionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C87B03A4293B261200C77EAE /* AcceptSuggestionCommand.swift */; };
4143
C87B03A7293B261900C77EAE /* RejectSuggestionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C87B03A6293B261900C77EAE /* RejectSuggestionCommand.swift */; };
4244
C87B03A9293B262600C77EAE /* NextSuggestionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C87B03A8293B262600C77EAE /* NextSuggestionCommand.swift */; };
@@ -51,7 +53,6 @@
5153
C8DCF00029CE11D500FDDDD7 /* ChatWithSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8DCEFFF29CE11D500FDDDD7 /* ChatWithSelection.swift */; };
5254
C8EE079D29CC21300043B6D9 /* AccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8EE079C29CC21300043B6D9 /* AccountView.swift */; };
5355
C8EE079F29CC25C20043B6D9 /* OpenAIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8EE079E29CC25C20043B6D9 /* OpenAIView.swift */; };
54-
C8EE07A129CC9ED30043B6D9 /* ExplainSelectionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8EE07A029CC9ED30043B6D9 /* ExplainSelectionCommand.swift */; };
5556
/* End PBXBuildFile section */
5657

5758
/* Begin PBXContainerItemProxy section */
@@ -187,6 +188,8 @@
187188
C861E6142994F6080056CB02 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
188189
C861E6192994F6080056CB02 /* ExtensionService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ExtensionService.entitlements; sourceTree = "<group>"; };
189190
C861E61F2994F6390056CB02 /* ServiceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceDelegate.swift; sourceTree = "<group>"; };
191+
C8758E6F29F04BFF00D29C1C /* CustomCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCommand.swift; sourceTree = "<group>"; };
192+
C8758E7129F04CF100D29C1C /* SeparatorCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCommand.swift; sourceTree = "<group>"; };
190193
C87B03A3293B24AB00C77EAE /* Copilot-for-Xcode-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "Copilot-for-Xcode-Info.plist"; sourceTree = SOURCE_ROOT; };
191194
C87B03A4293B261200C77EAE /* AcceptSuggestionCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcceptSuggestionCommand.swift; sourceTree = "<group>"; };
192195
C87B03A6293B261900C77EAE /* RejectSuggestionCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RejectSuggestionCommand.swift; sourceTree = "<group>"; };
@@ -199,7 +202,6 @@
199202
C8DCEFFF29CE11D500FDDDD7 /* ChatWithSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatWithSelection.swift; sourceTree = "<group>"; };
200203
C8EE079C29CC21300043B6D9 /* AccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountView.swift; sourceTree = "<group>"; };
201204
C8EE079E29CC25C20043B6D9 /* OpenAIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenAIView.swift; sourceTree = "<group>"; };
202-
C8EE07A029CC9ED30043B6D9 /* ExplainSelectionCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExplainSelectionCommand.swift; sourceTree = "<group>"; };
203205
/* End PBXFileReference section */
204206

205207
/* Begin PBXFrameworksBuildPhase section */
@@ -253,6 +255,7 @@
253255
isa = PBXGroup;
254256
children = (
255257
C81458932939EFDC00135263 /* SourceEditorExtension.swift */,
258+
C8758E7129F04CF100D29C1C /* SeparatorCommand.swift */,
256259
C8520300293C4D9000460097 /* Helpers.swift */,
257260
C81458952939EFDC00135263 /* GetSuggestionsCommand.swift */,
258261
C87B03A4293B261200C77EAE /* AcceptSuggestionCommand.swift */,
@@ -262,7 +265,7 @@
262265
C8009BFE2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift */,
263266
C8009C022941C576007AA7E8 /* RealtimeSuggestionCommand.swift */,
264267
C800DBB0294C624D00B04CAC /* PrefetchSuggestionsCommand.swift */,
265-
C8EE07A029CC9ED30043B6D9 /* ExplainSelectionCommand.swift */,
268+
C8758E6F29F04BFF00D29C1C /* CustomCommand.swift */,
266269
C8DCEFFF29CE11D500FDDDD7 /* ChatWithSelection.swift */,
267270
C861A6A229E5503F005C41A3 /* PromptToCodeCommand.swift */,
268271
C81458972939EFDC00135263 /* Info.plist */,
@@ -530,14 +533,15 @@
530533
files = (
531534
C8DCF00029CE11D500FDDDD7 /* ChatWithSelection.swift in Sources */,
532535
C81458942939EFDC00135263 /* SourceEditorExtension.swift in Sources */,
536+
C8758E7029F04BFF00D29C1C /* CustomCommand.swift in Sources */,
537+
C8758E7229F04CF100D29C1C /* SeparatorCommand.swift in Sources */,
533538
C861A6A329E5503F005C41A3 /* PromptToCodeCommand.swift in Sources */,
534539
C8520301293C4D9000460097 /* Helpers.swift in Sources */,
535540
C8009BFF2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift in Sources */,
536541
C87B03A5293B261200C77EAE /* AcceptSuggestionCommand.swift in Sources */,
537542
C87B03A9293B262600C77EAE /* NextSuggestionCommand.swift in Sources */,
538543
C87B03AB293B262E00C77EAE /* PreviousSuggestionCommand.swift in Sources */,
539544
C87B03A7293B261900C77EAE /* RejectSuggestionCommand.swift in Sources */,
540-
C8EE07A129CC9ED30043B6D9 /* ExplainSelectionCommand.swift in Sources */,
541545
C8009C032941C576007AA7E8 /* RealtimeSuggestionCommand.swift in Sources */,
542546
C800DBB1294C624D00B04CAC /* PrefetchSuggestionsCommand.swift in Sources */,
543547
C81458962939EFDC00135263 /* GetSuggestionsCommand.swift in Sources */,

Core/Sources/Client/AsyncXPCService.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CopilotModel
22
import Foundation
3-
import XPCShared
43
import Logger
4+
import XPCShared
55

66
public struct AsyncXPCService {
77
public var connection: NSXPCConnection { service.connection }
@@ -181,27 +181,30 @@ public struct AsyncXPCService {
181181
}
182182
}
183183

184-
public func explainSelection(editorContent: EditorContent) async throws -> UpdatedContent? {
184+
public func chatWithSelection(editorContent: EditorContent) async throws -> UpdatedContent? {
185185
try await suggestionRequest(
186186
connection,
187187
editorContent,
188-
{ $0.explainSelection }
188+
{ $0.chatWithSelection }
189189
)
190190
}
191191

192-
public func chatWithSelection(editorContent: EditorContent) async throws -> UpdatedContent? {
192+
public func promptToCode(editorContent: EditorContent) async throws -> UpdatedContent? {
193193
try await suggestionRequest(
194194
connection,
195195
editorContent,
196-
{ $0.chatWithSelection }
196+
{ $0.promptToCode }
197197
)
198198
}
199199

200-
public func promptToCode(editorContent: EditorContent) async throws -> UpdatedContent? {
200+
public func customCommand(
201+
name: String,
202+
editorContent: EditorContent
203+
) async throws -> UpdatedContent? {
201204
try await suggestionRequest(
202205
connection,
203206
editorContent,
204-
{ $0.promptToCode }
207+
{ service in { service.customCommand(name: name, editorContent: $0, withReply: $1) } }
205208
)
206209
}
207210
}

Core/Sources/Preferences/CustomCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public struct CustomCommand: Codable {
44
public enum Feature: Codable {
55
case promptToCode(prompt: String, continuousMode: Bool)
66
case chatWithSelection(prompt: String)
7-
case customChat(systemPrompt: String?, prompt: String)
7+
case customChat(systemPrompt: String?, prompt: String?)
88
}
99

1010
public var name: String

Core/Sources/Service/SuggestionCommandHandler/CommentBaseCommandHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ struct CommentBaseCommandHandler: SuggestionCommandHandler {
175175
return nil
176176
}
177177

178-
func explainSelection(editor: EditorContent) async throws -> UpdatedContent? {
178+
func chatWithSelection(editor: EditorContent) async throws -> UpdatedContent? {
179179
throw NotSupportedInCommentMode()
180180
}
181181

182-
func chatWithSelection(editor: EditorContent) async throws -> UpdatedContent? {
182+
func promptToCode(editor: XPCShared.EditorContent) async throws -> XPCShared.UpdatedContent? {
183183
throw NotSupportedInCommentMode()
184184
}
185185

186-
func promptToCode(editor: XPCShared.EditorContent) async throws -> XPCShared.UpdatedContent? {
186+
func customCommand(name: String, editor: EditorContent) async throws -> UpdatedContent? {
187187
throw NotSupportedInCommentMode()
188188
}
189189
}

Core/Sources/Service/SuggestionCommandHandler/SuggestionCommandHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ protocol SuggestionCommandHandler {
1717
@ServiceActor
1818
func generateRealtimeSuggestions(editor: EditorContent) async throws -> UpdatedContent?
1919
@ServiceActor
20-
func explainSelection(editor: EditorContent) async throws -> UpdatedContent?
21-
@ServiceActor
2220
func chatWithSelection(editor: EditorContent) async throws -> UpdatedContent?
2321
@ServiceActor
2422
func promptToCode(editor: EditorContent) async throws -> UpdatedContent?
23+
@ServiceActor
24+
func customCommand(name: String, editor: EditorContent) async throws -> UpdatedContent?
2525
}

0 commit comments

Comments
 (0)