unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#32034: 26.1; [PACTH] better xref-location-marker for imperfect file locations
@ 2018-07-02 13:46 João Távora
  2018-07-02 14:35 ` Robert Pluim
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: João Távora @ 2018-07-02 13:46 UTC (permalink / raw)
  To: 32034; +Cc: dgutov

Hi maintainers,

Observed this when working on Eglot, an Emacs LSP client.  Some LSP
servers, when asked about symbol definitions, make the mistake of
sending an non-existent or outdated path and location.

On the other hand, because xrefs come in potentially large numbers, a
sane xref backend will not check if a file exists before making
xref-file-location objects (neither should it check if the file contains
the purported location of the definition).  This can only reasonably be
done when the user decides to visit such a location.

So, currently, if the user chooses to visit a xref-file-location
pointing to a non-existing file, that file buffer is created
automatically and the command will probably error with an cryptic "End
of buffer" because of the `forward-char' call in the corresponding
xref-location-marker method.  The new empty buffer isn't even shown
which would at least help the user recognize the problem.

So:

1. xref-location-marker should check for `file-readable-p' before trying
to open the file, and if that fails issues an error ("File %s can't be
found.").

2. if the file is found, xref-location-marker should detect if the
location is indeed available in the file, and if it isn't, issue a
message.  In that case it should return a marker to the nearest possible
location.

3. Number 2. could turn out to be brittle and annoying if we have
changed the file in the meantime (but probably not more so than jumping
to a wrong location).  So we could have a "hint" field in
xref-file-location (or a xref-hinted-file-location) that helps in
looking around the landing point for, say, a regexp, and puts point
there.  Historically, this technique is successfully used in SLIME.  We
could also reasonably default that field to the identifier being looked
for.

The attached patch fixes 1. and 2.  It should probably go into emacs-26

Then, I'd like to know your opinions on 3., to go into master.

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index b0bdd62ae9..d38328cccd 100644ppp
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -119,13 +119,19 @@ xref-make-file-location
     (with-current-buffer
         (or (get-file-buffer file)
             (let ((find-file-suppress-same-file-warnings t))
+              (unless (file-exists-p file)
+                (error "File %s doesn't exist!" file))
               (find-file-noselect file)))
       (save-restriction
         (widen)
         (save-excursion
           (goto-char (point-min))
           (beginning-of-line line)
-          (forward-char column)
+          (ignore-errors (forward-char column))
+          (unless (and (= (1+ (current-line)) line)
+                       (= (current-column) column))
+            (message "Intended xref location was line=%d, column=%d"
+                     line column))
           (point-marker))))))
 
 (cl-defmethod xref-location-group ((l xref-file-location))

João






^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2020-08-10 20:42 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-02 13:46 bug#32034: 26.1; [PACTH] better xref-location-marker for imperfect file locations João Távora
2018-07-02 14:35 ` Robert Pluim
2018-07-02 15:22   ` João Távora
2018-07-02 14:47 ` Eli Zaretskii
2018-07-02 15:28   ` João Távora
2018-07-02 15:37     ` Eli Zaretskii
2018-07-02 15:50       ` João Távora
2018-07-02 16:32         ` Eli Zaretskii
2018-07-02 16:55           ` João Távora
2018-07-02 17:29             ` Eli Zaretskii
2020-08-10 12:59               ` Lars Ingebrigtsen
2020-08-10 18:53                 ` Dmitry Gutov
2020-08-10 20:42                   ` João Távora
2018-07-03 13:56 ` Dmitry Gutov
2018-07-03 14:50   ` João Távora
2018-07-03 15:07     ` Dmitry Gutov
2018-07-03 15:43       ` João Távora
2018-07-04 12:58         ` Dmitry Gutov
2018-07-04 13:37           ` João Távora
2018-07-04 14:33             ` Dmitry Gutov
2018-07-04 14:53               ` João Távora
2018-07-04 15:08                 ` Dmitry Gutov
2018-07-04 19:16                   ` João Távora

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).