copilot.el icon indicating copy to clipboard operation
copilot.el copied to clipboard

How to prevent copilot from trying to write comments

Open asmeurer opened this issue 1 year ago • 1 comments

I use the following to prevent copilot from trying to complete inside of comments:

(defun my-copilot-disable-predicates ()
  "Disable Copilot display when the cursor is in a string or comment."
  (or (nth 3 (syntax-ppss)) ;; check if cursor is in a string
      (nth 4 (syntax-ppss)))) ;; check if cursor is in a comment

;; Don't show copilot completions in strings or comments unless manually
;; triggered with C-Enter.
(add-hook 'copilot-disable-predicates #'my-copilot-disable-predicates)

This works if the cursor is already in a comment or string. But sometimes, copilot will decide all on its own that the next line should be a comment or docstring.

Is there an easy way to do this? Basically, I want to write a predicate that doesn't show the completion if it is a comment. Is there a way to access the proposed completion from within the copilot-disable-predicate or some other predicate?

asmeurer avatar Mar 20 '24 21:03 asmeurer

You could add a hook to copilot--display-overlay-completion. If the argument completion contains anything bad, skip the function body.

zerolfx avatar Jul 03 '24 08:07 zerolfx