(lambda ()
(remhash token (eglot--progress-reporters server))))))))))
+(defvar-local eglot--cached-tdi nil
+ "A cached LSP TextDocumentIdentifier URI string.")
+
(cl-defmethod eglot-handle-notification
- (_server (_method (eql textDocument/publishDiagnostics)) &key uri diagnostics
+ (server (_method (eql textDocument/publishDiagnostics)) &key uri diagnostics
&allow-other-keys) ; FIXME: doesn't respect `eglot-strict-mode'
"Handle notification publishDiagnostics."
(cl-flet ((eglot--diag-type (sev)
((= sev 2) 'eglot-warning)
(t 'eglot-note)))
(mess (source code message)
- (concat source (and code (format " [%s]" 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.
+ (cl-loop for b in (eglot--managed-buffers server)
+ when (with-current-buffer b
+ (equal eglot--cached-tdi uri))
+ return b)))
(if-let* ((path (expand-file-name (eglot-uri-to-path uri)))
- (buffer (find-buffer-visiting path)))
+ (buffer (find-it uri)))
(with-current-buffer buffer
(cl-loop
initially
(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 ,(or eglot--cached-tdi
(flymake-goto-next-error 1 '() t)
(should (eq 'flymake-error (face-at-point)))))))
+(ert-deftest eglot-test-basic-symlink ()
+ "Test basic symlink support."
+ (skip-unless (executable-find "clangd"))
+ (eglot--with-fixture
+ `(("symlink-project" .
+ (("main.cpp" . "#include\"foo.h\"\nint main() { return foo(); }")
+ ("foo.h" . "int foo();"))))
+ (with-current-buffer
+ (find-file-noselect "symlink-project/main.cpp")
+ (make-symbolic-link "main.cpp" "mainlink.cpp")
+ (eglot--tests-connect)
+ (find-file-noselect "mainlink.cpp")
+ (with-current-buffer
+ (find-file-noselect "foo.h")
+ (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.
+ (should (= (line-number-at-pos (point)) 5)))))))
+
(ert-deftest eglot-test-diagnostic-tags-unnecessary-code ()
"Test rendering of diagnostics tagged \"unnecessary\"."
(skip-unless (executable-find "clangd"))