(cl-defmethod initialize-instance :before ((_server eglot-lsp-server) &optional args)
(cl-remf args :initializationOptions))
+(defvar-local eglot--versioned-identifier 0
+ "LSP document version. Bumped on `eglot--after-change'.")
+
(defvar eglot--servers-by-project (make-hash-table :test #'equal)
"Keys are projects. Values are lists of processes.")
(defalias 'eglot--make-diag #'flymake-make-diagnostic)
(defalias 'eglot--diag-data #'flymake-diagnostic-data)
+(defun eglot--flymake-diagnostics (beg &optional end)
+ "Like `flymake-diagnostics', but for Eglot-specific diagnostics."
+ (cl-loop for diag in (flymake-diagnostics beg end)
+ for data = (eglot--diag-data diag)
+ for lsp-diag = (alist-get 'eglot-lsp-diag data)
+ for version = (alist-get 'eglot--doc-version data)
+ when (and lsp-diag (or (null version)
+ (= version eglot--versioned-identifier)))
+ collect diag))
+
+(defun eglot--diag-to-lsp-diag (diag)
+ (alist-get 'eglot-lsp-diag (eglot--diag-data diag)))
+
(defvar eglot-diagnostics-map
(let ((map (make-sparse-keymap)))
(define-key map [mouse-2] #'eglot-code-actions-at-mouse)
(1+ (plist-get (plist-get range :end) :line)))))))
(cons beg end)))
-(defvar-local eglot--versioned-identifier 0)
-
(cl-defmethod eglot-handle-notification
(server (_method (eql textDocument/publishDiagnostics))
&key uri diagnostics version
(eglot--make-diag
(current-buffer) beg end
(eglot--diag-type severity)
- message `((eglot-lsp-diag . ,diag-spec))
+ message `((eglot-lsp-diag . ,diag-spec)
+ (eglot--doc-version . ,version))
(when-let ((faces
(cl-loop for tag across tags
when (alist-get tag eglot--tag-faces)
"Calculate appropriate bounds depending on region and point."
(let (diags boftap)
(cond ((use-region-p) `(,(region-beginning) ,(region-end)))
- ((setq diags (flymake-diagnostics (point)))
+ ((setq diags (eglot--flymake-diagnostics (point)))
(cl-loop for d in diags
minimizing (flymake-diagnostic-beg d) into beg
maximizing (flymake-diagnostic-end d) into end
:end (eglot--pos-to-lsp-position end))
:context
`(:diagnostics
- [,@(cl-loop for diag in (flymake-diagnostics beg end)
- when (cdr (assoc 'eglot-lsp-diag
- (eglot--diag-data diag)))
- collect it)]
+ [,@(mapcar #'eglot--diag-to-lsp-diag
+ (eglot--flymake-diagnostics beg end))]
,@(when only `(:only [,only]))
,@(when triggerKind `(:triggerKind ,triggerKind)))))