Skip to content

Commit f71eb47

Browse files
committed
Merge branch 'feature/custom-command-template-clipboard' into develop
2 parents 0a28d58 + 7701377 commit f71eb47

4 files changed

Lines changed: 29 additions & 15 deletions

File tree

Core/Sources/ChatService/CustomCommandTemplateProcessor.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import AppKit
12
import Foundation
23
import SuggestionModel
34
import XcodeInspector
45

5-
struct CustomCommandTemplateProcessor {
6-
func process(_ text: String) -> String {
6+
public struct CustomCommandTemplateProcessor {
7+
public init() {}
8+
9+
public func process(_ text: String) -> String {
710
let info = getEditorInformation()
811
let editorContent = info.editorContent
912
let updatedText = text
@@ -22,6 +25,10 @@ struct CustomCommandTemplateProcessor {
2225
of: "{{active_editor_file_name}}",
2326
with: info.documentURL?.lastPathComponent ?? ""
2427
)
28+
.replacingOccurrences(
29+
of: "{{clipboard}}",
30+
with: NSPasteboard.general.string(forType: .string) ?? ""
31+
)
2532
return updatedText
2633
}
2734

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ extension PseudoCommandHandler {
337337

338338
@WorkspaceActor
339339
func getEditorContent(sourceEditor: SourceEditor?) async -> EditorContent? {
340-
guard let filespace = await getFilespace(), let sourceEditor else { return nil }
340+
guard let filespace = await getFilespace(),
341+
let sourceEditor = sourceEditor ?? XcodeInspector.shared.focusedEditor
342+
else { return nil }
341343
let content = sourceEditor.content
342344
let uti = filespace.codeMetadata.uti ?? ""
343345
let tabSize = filespace.codeMetadata.tabSize ?? 4

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ extension WindowBaseCommandHandler {
409409
}() as (String, CursorRange)
410410

411411
let viewStore = Service.shared.guiController.viewStore
412+
413+
let customCommandTemplateProcessor = CustomCommandTemplateProcessor()
414+
let newExtraSystemPrompt = extraSystemPrompt.map(customCommandTemplateProcessor.process)
415+
let newPrompt = prompt.map(customCommandTemplateProcessor.process)
412416

413417
_ = await Task { @MainActor in
414418
// if there is already a prompt to code presenting, we should not present another one
@@ -423,8 +427,8 @@ extension WindowBaseCommandHandler {
423427
allCode: editor.content,
424428
isContinuous: isContinuous,
425429
commandName: name,
426-
defaultPrompt: prompt ?? "",
427-
extraSystemPrompt: extraSystemPrompt,
430+
defaultPrompt: newPrompt ?? "",
431+
extraSystemPrompt: newExtraSystemPrompt,
428432
generateDescriptionRequirement: generateDescription
429433
))))
430434
}.result

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Copilot for Xcode is an Xcode Source Editor Extension that provides GitHub Copil
2525
- [Granting Permissions to the App](#granting-permissions-to-the-app)
2626
- [Setting Up Key Bindings](#setting-up-key-bindings)
2727
- [Setting Up Suggestion Feature](#setting-up-suggestion-feature)
28-
- [Setting Up GitHub Copilot](#setting-up-github-copilot)
29-
- [Setting Up Codeium](#setting-up-codeium)
28+
- [Setting Up GitHub Copilot](#setting-up-github-copilot)
29+
- [Setting Up Codeium](#setting-up-codeium)
3030
- [Setting Up Chat Feature](#setting-up-chat-feature)
3131
- [Managing `CopilotForXcodeExtensionService.app`](#managing-copilotforxcodeextensionserviceapp)
3232
- [Update](#update)
@@ -129,11 +129,11 @@ Another convenient method to access commands is by using the `⇧⌘/` shortcut
129129
1. In the host app, navigate to "Service - GitHub Copilot" to access your GitHub Copilot account settings.
130130
2. Click on "Install" to install the language server.
131131
3. Optionally, set up the path to Node. The default value is simply `node`. Copilot for Xcode.app will attempt to locate Node from the following directories: `/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`.
132-
133-
If your Node installation is located elsewhere, you can run `which node` from the terminal to obtain the correct path.
134-
135-
If you are using a node version manager that provides a shim executable, you will need to find the path to the actual executable. Please refer to the FAQ for more information.
136-
132+
133+
If your Node installation is located elsewhere, you can run `which node` from the terminal to obtain the correct path.
134+
135+
If you are using a node version manager that provides a shim executable, you will need to find the path to the actual executable. Please refer to the FAQ for more information.
136+
137137
4. Click on "Sign In", and you will be redirected to a verification website provided by GitHub. A user code will be copied to your clipboard.
138138
5. After signing in, return to the app and click on "Confirm Sign-in" to complete the process.
139139
6. Go to "Feature - Suggestion" and update the feature provider to "GitHub Copilot".
@@ -235,7 +235,7 @@ You can detach the chat panel by simply dragging it away. Once detached, the cha
235235
| :------: | --------------------------------------------------------------------------------------------------- |
236236
| `⌘W` | Close the chat tab. |
237237
| `⌘M` | Minimize the chat, you can bring it back with any chat commands or by clicking the circular widget. |
238-
| `⇧↩︎` | Add new line. |
238+
| `⇧↩︎` | Add new line. |
239239
| `⇧⌘]` | Move to next tab |
240240
| `⇧⌘[` | Move to previous tab |
241241

@@ -297,7 +297,7 @@ This feature is recommended when you need to update a specific piece of code. So
297297
#### Commands
298298

299299
- Prompt to Code: Open a prompt to code window, where you can use natural language to write or edit selected code.
300-
- Accept Prompt to Code: Accept the result of prompt to code.
300+
- Accept Prompt to Code: Accept the result of prompt to code.
301301

302302
### Custom Commands
303303

@@ -308,14 +308,15 @@ You can create custom commands that run Chat and Prompt to Code with personalize
308308
- Custom Chat: Open the chat window and immediately send a message, if provided. You can overwrite the entire system prompt through the system prompt field.
309309
- Single Round Dialog: Send a message to a temporary chat. Useful when you want to run a terminal command with `/run`.
310310

311-
For Send Message, Single Round Dialog and Custom Chat commands, you can use the following template arguments:
311+
You can use the following template arguments in custom commands:
312312

313313
| Argument | Description |
314314
| ----------------------------- | ---------------------------------------------- |
315315
| `{{selected_code}}` | The currently selected code in the editor. |
316316
| `{{active_editor_language}}` | The programming language of the active editor. |
317317
| `{{active_editor_file_url}}` | The URL of the active file in the editor. |
318318
| `{{active_editor_file_name}}` | The name of the active file in the editor. |
319+
| `{{clipboard}}` | The content in clipboard. |
319320

320321
## Plus Features
321322

0 commit comments

Comments
 (0)