Skip to content

Commit 0249198

Browse files
tninjaKang TuCopilot
authored
Chore: add clipboard context support for error investigation (#37)
* Chore: add clipboard context support for error investigation * Update ai-code-discussion.el Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Kang Tu <kang_tu@apple.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ba75072 commit 0249198

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

ai-code-discussion.el

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,22 @@ Returns a list of relative paths from the git repository root."
114114
;;;###autoload
115115
(defun ai-code-investigate-exception (arg)
116116
"Generate prompt to investigate exceptions or errors in code.
117-
With a prefix argument (C-u), or if not in a programming mode buffer,
118-
prompt for investigation without adding any context.
117+
With a prefix argument (C-u), use context from clipboard as the error to investigate.
119118
If a *compilation* buffer is visible in the current window, use its full content as context.
120119
If a region is selected, investigate that specific error or exception.
121120
If cursor is in a function, investigate exceptions in that function.
122121
Otherwise, investigate general exception handling in the file.
123122
Inserts the prompt into the AI prompt file and optionally sends to AI.
124123
Argument ARG is the prefix argument."
125124
(interactive "P")
126-
(let* ((compilation-buffer (get-buffer "*compilation*"))
125+
(let* ((clipboard-content (when arg
126+
(condition-case nil
127+
(current-kill 0)
128+
(error nil))))
129+
(compilation-buffer (get-buffer "*compilation*"))
127130
(compilation-content (when (and compilation-buffer
128-
(get-buffer-window compilation-buffer))
131+
(get-buffer-window compilation-buffer)
132+
(not arg))
129133
(with-current-buffer compilation-buffer
130134
(buffer-substring-no-properties (point-min) (point-max)))))
131135
(region-text (when (region-active-p)
@@ -139,13 +143,17 @@ Argument ARG is the prefix argument."
139143
(if full-buffer-context
140144
(concat "\n\nContext:\n" full-buffer-context)
141145
(concat
146+
(when clipboard-content
147+
(concat "\n\nClipboard context (error/exception):\n" clipboard-content))
142148
(when compilation-content
143149
(concat "\n\nCompilation output:\n" compilation-content))
144-
(when (and region-text (not compilation-content))
150+
(when (and region-text (not compilation-content) (not clipboard-content))
145151
(concat "\n\nSelected code:\n" region-text)))))
146152
(default-question "How to fix the error in this code? Please analyze the error, explain the root cause, and provide the corrected code to resolve the issue: ")
147153
(prompt-label
148154
(cond
155+
(clipboard-content
156+
"Investigate error from clipboard: ")
149157
(compilation-content
150158
"Investigate compilation error: ")
151159
(full-buffer-context

ai-code-interface.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Shows the current backend label to the right."
166166
]
167167
["Other Tools"
168168
("." "Init projectile and tags" ai-code-init-project)
169-
("e" "Debug exception (C-u: global)" ai-code-investigate-exception)
169+
("e" "Debug exception (C-u: clipboard)" ai-code-investigate-exception)
170170
("f" "Fix Flycheck errors in scope" ai-code-flycheck-fix-errors-in-scope)
171171
("k" "Copy Cur File Name (C-u: full)" ai-code-copy-buffer-file-name-to-clipboard)
172172
("o" "Open Clipboard file dir" ai-code-open-clipboard-file-path-as-dired)

0 commit comments

Comments
 (0)