Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong diagnostic position in the narrowed buffer #479

Closed
muffinmad opened this issue May 13, 2020 · 4 comments
Closed

Wrong diagnostic position in the narrowed buffer #479

muffinmad opened this issue May 13, 2020 · 4 comments
Labels

Comments

@muffinmad
Copy link
Collaborator

Python file:

from datetime import datetime


print()

Note eglot-warning on line 1.

Select print() and do C-x n n (narrow-to-region).

Cancel selection and make an edit, e.g. add and remove space at the end of the line.

Note eglot-warning "datetime imported but unused" on the line print().

Not sure if this is eglot or flymake bug though.

@joaotavora joaotavora added the bug label May 14, 2020
@nemethf
Copy link
Collaborator

nemethf commented May 16, 2020

Does the following patch fix the issue for you? If it does, maybe we can start to think about how to create a better fix that calls save-restriction and widen less frequently, for example, just once for every received LSP message. Or maybe the overhead is negligible, I don't know.

diff --git a/eglot.el b/eglot.el
index 8a1d162..ccd7f94 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1118,6 +1118,7 @@ be set to `eglot-move-to-lsp-abiding-column' (the default), and
   "Convert LSP position POS-PLIST to Emacs point.
 If optional MARKER, return a marker instead"
   (save-excursion
+    (save-restriction (widen)
     (goto-char (point-min))
     (forward-line (min most-positive-fixnum
                        (plist-get pos-plist :line)))
@@ -1130,7 +1131,7 @@ If optional MARKER, return a marker instead"
            col)
           (setq col 0))
         (funcall eglot-move-to-column-function col)))
-    (if marker (copy-marker (point-marker)) (point))))
+    (if marker (copy-marker (point-marker)) (point)))))
 
 (defun eglot--path-to-uri (path)
   "URIfy PATH."

@joaotavora
Copy link
Owner

@nemethf that;s 99% the right fix. I don't have any reason to believe that save-restriction is expensive. A naive conjecture of how it works tells me that it is just saving and restoring two integers.

@joaotavora
Copy link
Owner

Earlier I meant to say "99% sure". It does solve @muffinmad's problem, but indeed something is hiding in that 1%, because as soon as you add the space another "unused import" gets added to the invisible first line. I think in this case it's Flymake failing to remove diagnostics out of scope.

@joaotavora
Copy link
Owner

I think in this case it's Flymake failing to remove diagnostics out of scope.

I meant to say "outside the region". And it wasn't Flymake's fault, it was the fault of a somewhat hackish solution to fix #159. Anyway, should be fixed now.

bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 18, 2022
…fers

* eglot.el (eglot--lsp-position-to-point)
(eglot-handle-notification): save-restriction and widen
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 19, 2022
…fers

* eglot.el (eglot--lsp-position-to-point)
(eglot-handle-notification): save-restriction and widen
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 19, 2022
* eglot.el (eglot--lsp-position-to-point)
(eglot-handle-notification): save-restriction and widen

#479: joaotavora/eglot#479
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this issue Oct 12, 2022
* eglot.el (eglot--lsp-position-to-point)
(eglot-handle-notification): save-restriction and widen

GitHub-reference: fix joaotavora/eglot#479
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants