2020(declare-function ai-code-read-string " ai-code-input" )
2121(declare-function ai-code--insert-prompt " ai-code-prompt-mode" )
2222(declare-function ai-code--get-clipboard-text " ai-code-interface" )
23+ (declare-function ai-code--get-git-relative-paths " ai-code-discussion" )
2324
2425(defun ai-code--is-comment-line (line )
2526 " Check if LINE is a comment line based on current buffer's comment syntax.
@@ -99,6 +100,12 @@ Argument ARG is the prefix argument."
99100 (buffer-substring-no-properties (region-beginning ) (region-end ))))
100101 (region-start-line (when region-active
101102 (line-number-at-pos (region-beginning ))))
103+ (region-end-line (when region-active
104+ (line-number-at-pos (region-end ))))
105+ (git-relative-path (when (and region-active buffer-file-name)
106+ (car (ai-code--get-git-relative-paths (list buffer-file-name)))))
107+ (region-location-info (when (and region-active git-relative-path region-start-line region-end-line)
108+ (format " %s #L%d -L%d " git-relative-path region-start-line region-end-line)))
102109 (prompt-label
103110 (cond
104111 ((and clipboard-context
@@ -123,13 +130,21 @@ Argument ARG is the prefix argument."
123130 (final-prompt
124131 (concat initial-prompt
125132 (when region-text
126- (format " \n Code from line %d :\n %s " region-start-line region-text))
133+ (concat " \n Selected region:\n "
134+ (cond
135+ (region-location-info
136+ (concat region-location-info " \n " ))
137+ (region-start-line
138+ (format " Start line: %d \n " region-start-line)))
139+ region-text))
127140 (when function-name (format " \n Function: %s " function-name))
128141 files-context-string
129142 (when (and clipboard-context
130143 (string-match-p " \\ S-" clipboard-context))
131144 (concat " \n\n Clipboard context:\n " clipboard-context))
132- " \n Note: Please make the code change described above." )))
145+ (if region-text
146+ " \n Note: Please apply the code change to the selected region specified above."
147+ " \n Note: Please make the code change described above." ))))
133148 (ai-code--insert-prompt final-prompt)))
134149
135150;;;### autoload
0 commit comments