copilot-emacs / copilot.el

An unofficial Copilot plugin for Emacs.
MIT License
1.79k stars 126 forks source link

Cursor position error #200

Open JiaweiChenC opened 10 months ago

JiaweiChenC commented 10 months ago

When the real cursor position is not at the start of the overlay preview. The cursor will jump to the end of the overlay.

For example: copilot_bug the cursor will keep jumping to the end of the overlay.

Another similar situation: another_bug the cursor's real position is after :, but it will jump to the end of the completion.

To reproduce:

emacs -Q -l test.el test.py
;; test.el
(package-initialize)

;; straight.el initialization
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))

;; Location of my use-package git clone
(add-to-list 'load-path "~/.emacs.d/.local/straight/repos/use-package/")
(require 'use-package)

(use-package copilot
  :straight (:host github :repo "zerolfx/copilot.el" :files ("dist" "*.el"))
  :ensure t)

(add-hook 'prog-mode-hook 'copilot-mode)
emil-vdw commented 9 months ago

It seems that this happens when the first character of the completion is a newline and the code is attempting to set the cursor property on the newline character. :thinking:

johnnywalker commented 8 months ago

Is this the same issue reported with Typescript? https://github.com/copilot-emacs/copilot.el/issues/165

I often have issues with the cursor jumping in TS files, but that issue was closed as stale a while back.

baongoc124 commented 5 months ago

I still have the same problem on latest master so upvoted this issue.

jcs090218 commented 5 months ago

I'll look into this!

mostafah commented 3 months ago

If it helps, here’s another reproduction of the issue that happens for me all the time. Here after if I type ( instead of hitting tab because I want to write something other than the suggestion. The ( does not show behind the suggestion, but it’s there and later appears after what I type. This is typescript-mode with lsp-mode. Everything should be latest version, I suppose.

https://github.com/copilot-emacs/copilot.el/assets/531910/b4bb41fa-834b-4586-8055-ca2e38f2cb63

julian-hoch commented 3 months ago

Same here, with typescript-mode (happens without lsp-mode / eglot). Colons, parentheses, braces are all affected.

dov commented 3 months ago

It happens in python model as well, that sometimes the cursor is placed at the end of the suggestion instead of the beginning. E.g. in the following image the last character input by my was ":", the rest was filled in by copilot and the cursor is shown at the end of the suggestion, instead of the beginning:

wrong-cursor

AndreaOrru commented 2 months ago

I'm also experiencing this in Python.