]> git.eshelyaron.com Git - emacs.git/commitdiff
Eglot: tweak previous change (bug#70036)
authorJoão Távora <joaotavora@gmail.com>
Fri, 19 Apr 2024 21:21:21 +0000 (16:21 -0500)
committerEshel Yaron <me@eshelyaron.com>
Sat, 20 Apr 2024 11:09:29 +0000 (14:09 +0300)
* lisp/progmodes/eglot.el (eglot--TextDocumentIdentifier-uri):
Rename from eglot--cached-tdi.
(eglot-handle-notification): Tweak comment.  Use
eglot--TextDocumentIdentifier-uri.
(eglot--TextDocumentIdentifier)
(eglot--signal-textDocument/didOpen): Use
eglot--TextDocumentIdentifier-uri.

* test/lisp/progmodes/eglot-tests.el (eglot-test-basic-symlink):
Address compilation warning.  Tweak comment slightly.

(cherry picked from commit f90008411e827390857a4ad25e0c40fa5d27212a)

lisp/progmodes/eglot.el
test/lisp/progmodes/eglot-tests.el

index b6cdb2fd51ae0ad05990cf7d0b60e561aab5c1dd..d023ea241344d3f3f14513452847dcd180e55e99 100644 (file)
@@ -2382,7 +2382,7 @@ still unanswered LSP requests to the server\n")))
                         (lambda ()
                           (remhash token (eglot--progress-reporters server))))))))))
 
-(defvar-local eglot--cached-tdi nil
+(defvar-local eglot--TextDocumentIdentifier-uri nil
   "A cached LSP TextDocumentIdentifier URI string.")
 
 (cl-defmethod eglot-handle-notification
@@ -2397,13 +2397,13 @@ still unanswered LSP requests to the server\n")))
             (mess (source code message)
               (concat source (and code (format " [%s]" code)) ": " message))
             (find-it (uri)
-              ;; Search the managed buffers for a buffer with the
-              ;; provided diagnostic from the server.  We do this to
-              ;; avoid calling `file-truename' too often, gaining an
-              ;; increase in performance.
+              ;; Search managed buffers with server-provided URIs since
+              ;; that's what we give them in the "didOpen" notification
+              ;; `find-buffer-visiting' would be nicer, but it calls the
+              ;; the potentially slow `file-truename' (bug#70036).
               (cl-loop for b in (eglot--managed-buffers server)
                        when (with-current-buffer b
-                              (equal eglot--cached-tdi uri))
+                              (equal eglot--TextDocumentIdentifier-uri uri))
                        return b)))
     (if-let* ((path (expand-file-name (eglot-uri-to-path uri)))
               (buffer (find-it uri)))
@@ -2532,9 +2532,10 @@ THINGS are either registrations or unregisterations (sic)."
     `(:success ,success)))
 
 (defun eglot--TextDocumentIdentifier ()
-  "Compute TextDocumentIdentifier object for current buffer."
-  `(:uri ,(or eglot--cached-tdi
-              (setq eglot--cached-tdi
+  "Compute TextDocumentIdentifier object for current buffer.
+Sets `eglot--TextDocumentIdentifier-uri' (which see) as a side effect."
+  `(:uri ,(or eglot--TextDocumentIdentifier-uri
+              (setq eglot--TextDocumentIdentifier-uri
                     (eglot-path-to-uri (or buffer-file-name
                                            (ignore-errors
                                              (buffer-file-name
@@ -2834,7 +2835,7 @@ When called interactively, use the currently active server"
   "Send textDocument/didOpen to server."
   (setq eglot--recent-changes nil
         eglot--versioned-identifier 0
-        eglot--cached-tdi nil)
+        eglot--TextDocumentIdentifier-uri nil)
   (jsonrpc-notify
    (eglot--current-server-or-lose)
    :textDocument/didOpen `(:textDocument ,(eglot--TextDocumentItem))))
index 28579ccde5cb4246099128437e676f335391aba9..282e66f56a5d415d4fbfa404257f4a1e1d11f59b 100644 (file)
@@ -453,9 +453,10 @@ directory hierarchy."
         (goto-char 5)
         (xref-find-references "foo")
         (with-current-buffer (get-buffer "*xref*")
-          (end-of-buffer)
-          ;; Expect the xref buffer to not contain duplicate references to
-          ;; main.c and mainlink.c.  If it did total lines would be 7.
+          (goto-char (point-max))
+          ;; Expect xref buffer to not contain duplicate references to
+          ;; main.c and mainlink.c.  If it did, total lines would be 7.
+          ;; FIXME: make less brittle by counting actual references.
           (should (= (line-number-at-pos (point)) 5)))))))
 
 (ert-deftest eglot-test-diagnostic-tags-unnecessary-code ()