Skip to content

Commit 96a6a0a

Browse files
committed
Update CustomCommandTemplateProcessor to support more parameters
1 parent 2e0b92b commit 96a6a0a

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

Core/Sources/Service/CustomCommandTemplateProcessor.swift

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@ import XcodeInspector
55
struct CustomCommandTemplateProcessor {
66
func process(_ text: String) -> String {
77
let info = getEditorInformation()
8-
if let editorContent = info.editorContent {
9-
let updatedText = text.replacingOccurrences(of: "{{selected_code}}", with: """
10-
```\(info.language.rawValue)
11-
\(editorContent.selectedContent.trimmingCharacters(in: ["\n"]))
12-
```
8+
let editorContent = info.editorContent
9+
let updatedText = text
10+
.replacingOccurrences(of: "{{selected_code}}", with: """
11+
\(editorContent?.selectedContent.trimmingCharacters(in: .whitespacesAndNewlines) ?? "")
1312
""")
14-
return updatedText
15-
} else {
16-
let updatedText = text.replacingOccurrences(of: "{{selected_code}}", with: "")
17-
return updatedText
18-
}
13+
.replacingOccurrences(
14+
of: "{{active_editor_language}}",
15+
with: info.language.rawValue
16+
)
17+
.replacingOccurrences(
18+
of: "{{active_editor_file_url}}",
19+
with: info.documentURL?.path ?? ""
20+
)
21+
.replacingOccurrences(
22+
of: "{{active_editor_file_name}}",
23+
with: info.documentURL?.lastPathComponent ?? ""
24+
)
25+
return updatedText
1926
}
2027

2128
struct EditorInformation {
2229
let editorContent: SourceEditor.Content?
2330
let language: CodeLanguage
31+
let documentURL: URL?
2432
}
2533

2634
func getEditorInformation() -> EditorInformation {
@@ -30,7 +38,8 @@ struct CustomCommandTemplateProcessor {
3038

3139
return .init(
3240
editorContent: editorContent,
33-
language: language
41+
language: language,
42+
documentURL: documentURL
3443
)
3544
}
3645
}

Tool/Sources/Preferences/Keys.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ public extension UserDefaultPreferenceKeys {
289289
feature: .chatWithSelection(
290290
extraSystemPrompt: "",
291291
prompt: """
292+
```{{active_editor_language}}
292293
{{selected_code}}
294+
```
293295
""",
294296
useExtraSystemPrompt: true
295297
)

0 commit comments

Comments
 (0)