emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 3228c1222c9 2/2: Better way to fix bug#70036


From: João Távora
Subject: master 3228c1222c9 2/2: Better way to fix bug#70036
Date: Thu, 18 Apr 2024 10:39:51 -0400 (EDT)

branch: master
commit 3228c1222c99e672ca0cd7599c07ea1db852aa1a
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Better way to fix bug#70036
    
    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.
---
 lisp/progmodes/eglot.el | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 00f69b2ca83..90a607075d3 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2518,12 +2518,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)
 
@@ -2816,7 +2821,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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]