GithubHelp home page GithubHelp logo

Comments (5)

zerolfx avatar zerolfx commented on August 27, 2024 1

Workaround: use https://github.com/lewang/ws-butler

I will try to fix it later.

from copilot.el.

Rogach avatar Rogach commented on August 27, 2024 1

My apologies, I somehow missed that case (despite the comment talking exactly about that).

Seems that error happens because (thing-at-point 'line) returns incorrect data at that last line (it returns previous line instead of what we expect). Here's the updated patch, now your example works as expected:

@@ -389,17 +389,11 @@ USER-POS is the cursor position (for verification only)."
   (save-excursion
     (widen)
     (goto-char (point-min))
-    (if (= (line-end-position line) (1- (point-max)))
-        ; special case if the last line is empty
-        (progn
-          (goto-char (point-max))
-          (newline)
-          (forward-char -1))
-      (forward-line line)
-      (forward-char col))
-
-    ; remove common prefix
-    (let* ((cur-line (s-chop-suffix "\n" (or (thing-at-point 'line) "")))
+    (forward-line line)
+    (forward-char col)
+
+    ;; remove common prefix
+    (let* ((cur-line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
            (common-prefix-len (length (s-shared-start completion cur-line))))
       (setq completion (substring completion common-prefix-len))
       (forward-char common-prefix-len))

from copilot.el.

Rogach avatar Rogach commented on August 27, 2024

It seems that the problem comes from these lines:

    (if (= (line-end-position line) (1- (point-max)))
        ; special case if the last line is empty
        (progn
          (goto-char (point-max))
          (newline)
          (forward-char -1))
      (forward-line line)
      (forward-char col))

Do we actually need this special case? I tested removing it and everything worked fine for me:

@@ -389,14 +389,8 @@ USER-POS is the cursor position (for verification only)."
   (save-excursion
     (widen)
     (goto-char (point-min))
-    (if (= (line-end-position line) (1- (point-max)))
-        ; special case if the last line is empty
-        (progn
-          (goto-char (point-max))
-          (newline)
-          (forward-char -1))
-      (forward-line line)
-      (forward-char col))
+    (forward-line line)
+    (forward-char col)
 
     ; remove common prefix
     (let* ((cur-line (s-chop-suffix "\n" (or (thing-at-point 'line) "")))

(my Emacs version is 30.0.50)

from copilot.el.

zerolfx avatar zerolfx commented on August 27, 2024

image

@Rogach
In the screenshot, my cursor is on the second line while this file has only one line. With the special case, copilot.el can provide completions in this situation, otherwise, you will see an "End of buffer" message.

While creating new lines for users may seem strange, being able to show completions at the ends of files is useful. Any better workaround is welcome.

from copilot.el.

zerolfx avatar zerolfx commented on August 27, 2024

@Rogach Patch applied. Thanks for your elegant solution!

from copilot.el.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.