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.
This commit is contained in:
João Távora 2024-04-18 08:03:10 -05:00
parent 306feb7d96
commit 3228c1222c

View file

@ -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))))