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.
This commit is contained in:
João Távora 2024-04-19 16:21:21 -05:00
parent 473189ab69
commit f90008411e
2 changed files with 15 additions and 13 deletions

View file

@ -2381,7 +2381,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
@ -2396,13 +2396,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)))
@ -2531,9 +2531,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
@ -2833,7 +2834,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))))

View 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 ()