]> git.eshelyaron.com Git - emacs.git/commitdiff
Better way to fix bug#70036
authorJoão Távora <joaotavora@gmail.com>
Thu, 18 Apr 2024 13:03:10 +0000 (08:03 -0500)
committerEshel Yaron <me@eshelyaron.com>
Sat, 20 Apr 2024 11:07:38 +0000 (14:07 +0300)
Cache a new eglot--cached-tdi var per buffer, which contains value to
return from eglot--TextDocumentIdentifier.

This avoids frequent expensive recomputation of a value that requires
potentially many 'file-truename' calls.  This technique is used in a
number of other cases already, like eglot--recent-changes or
eglot--versioned-identifier.

* lisp/progmodes/eglot.el (eglot--cached-tdi): New variable.
(eglot--TextDocumentIdentifier): Tweak.
(eglot--signal-textDocument/didOpen): Clear eglot--cached-tdi.

(cherry picked from commit 3228c1222c99e672ca0cd7599c07ea1db852aa1a)

lisp/progmodes/eglot.el

index fbae5aadd7891eb4b871f9eab3e873644cf9e3e6..122a1d06435fa36e5c32ec4d9843060e9c3c3fc4 100644 (file)
@@ -2519,12 +2519,17 @@ THINGS are either registrations or unregisterations (sic)."
      (t (setq success :json-false)))
     `(:success ,success)))
 
+(defvar-local eglot--cached-tdi nil
+  "A cached LSP TextDocumentIdentifier URI string.")
+
 (defun eglot--TextDocumentIdentifier ()
   "Compute TextDocumentIdentifier object for current buffer."
-  `(:uri ,(eglot-path-to-uri (or buffer-file-name
-                                  (ignore-errors
-                                    (buffer-file-name
-                                     (buffer-base-buffer)))))))
+  `(:uri ,(or eglot--cached-tdi
+              (setq eglot--cached-tdi
+                    (eglot-path-to-uri (or buffer-file-name
+                                           (ignore-errors
+                                             (buffer-file-name
+                                              (buffer-base-buffer)))))))))
 
 (defvar-local eglot--versioned-identifier 0)
 
@@ -2817,7 +2822,9 @@ When called interactively, use the currently active server"
 
 (defun eglot--signal-textDocument/didOpen ()
   "Send textDocument/didOpen to server."
-  (setq eglot--recent-changes nil eglot--versioned-identifier 0)
+  (setq eglot--recent-changes nil
+        eglot--versioned-identifier 0
+        eglot--cached-tdi nil)
   (jsonrpc-notify
    (eglot--current-server-or-lose)
    :textDocument/didOpen `(:textDocument ,(eglot--TextDocumentItem))))