Skip to content

Commit 7701377

Browse files
committed
Update custom prompt to code to support templates
1 parent 2d864ea commit 7701377

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

Core/Sources/ChatService/CustomCommandTemplateProcessor.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import Foundation
33
import SuggestionModel
44
import XcodeInspector
55

6-
struct CustomCommandTemplateProcessor {
7-
func process(_ text: String) -> String {
6+
public struct CustomCommandTemplateProcessor {
7+
public init() {}
8+
9+
public func process(_ text: String) -> String {
810
let info = getEditorInformation()
911
let editorContent = info.editorContent
1012
let updatedText = text

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +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 |
319+
| `{{clipboard}}` | The content in clipboard. |
320320

321321
## Plus Features
322322

0 commit comments

Comments
 (0)