From: João Távora Date: Fri, 19 Apr 2024 21:21:21 +0000 (-0500) Subject: Eglot: tweak previous change (bug#70036) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3df2492722a776e0d45511c2dbcb23fb0752ef89;p=emacs.git Eglot: tweak previous change (bug#70036) * 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) --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index b6cdb2fd51a..d023ea24134 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -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)))) diff --git a/test/lisp/progmodes/eglot-tests.el b/test/lisp/progmodes/eglot-tests.el index 28579ccde5c..282e66f56a5 100644 --- a/test/lisp/progmodes/eglot-tests.el +++ b/test/lisp/progmodes/eglot-tests.el @@ -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 ()