(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
(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)))
`(: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
"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))))
(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 ()