[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 06451eaaac 1/4: Per #794: Support optional Diagno
From: |
ELPA Syncer |
Subject: |
[elpa] externals/eglot 06451eaaac 1/4: Per #794: Support optional Diagnostic.tags |
Date: |
Thu, 13 Jan 2022 08:01:47 -0500 (EST) |
branch: externals/eglot
commit 06451eaaac6b75e47e54570624e28178082752ef
Author: Brian Leung <leungbk@posteo.net>
Commit: Stefan Kangas <stefankangas@gmail.com>
Per #794: Support optional Diagnostic.tags
https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#diagnosticTag
A DiagnosticTag can be either 1 (DiagnosticTag.Unnecessary) or
2 (DiagnosticTag.Deprecated). Following the rendering suggestions in
the protocol, we fade out Unnecessary code and strike-through
Deprecated code.
* eglot.el (eglot-diagnostic-tag-unnecessary-face)
(eglot-diagnostic-tag-deprecated-face): New faces.
(eglot--tag-faces): New defconst.
(eglot--lsp-interface-alist): Add Diagnostic.tags.
(eglot-client-capabilities): Advertise supported tags.
(eglot-handle-notification): Assign the appropriate properties.
* eglot-tests.el (diagnostic-tags-unnecessary-code): New test.
---
eglot-tests.el | 21 +++++++++++++++++++++
eglot.el | 28 ++++++++++++++++++++++++----
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/eglot-tests.el b/eglot-tests.el
index e43cc612cf..ba29d12544 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -426,6 +426,27 @@ Pass TIMEOUT to `eglot--with-timeout'."
(flymake-goto-next-error 1 '() t)
(should (eq 'flymake-error (face-at-point)))))))
+(ert-deftest diagnostic-tags-unnecessary-code ()
+ "Test rendering of diagnostics tagged \"unnecessary\"."
+ (skip-unless (executable-find "rust-analyzer"))
+ (eglot--with-fixture
+ '(("diagnostic-tag-project" .
+ (("main.rs" .
+ "fn main() -> () { let test=3; }"))))
+ (with-current-buffer
+ (eglot--find-file-noselect "diagnostic-tag-project/main.rs")
+ (let ((eglot-server-programs '((rust-mode . ("rust-analyzer")))))
+ (should (zerop (shell-command "cargo init")))
+ (eglot--sniffing (:server-notifications s-notifs)
+ (eglot--tests-connect)
+ (eglot--wait-for (s-notifs 5)
+ (&key _id method &allow-other-keys)
+ (string= method "textDocument/publishDiagnostics"))
+ (flymake-start)
+ (goto-char (point-min))
+ (flymake-goto-next-error 1 '() t)
+ (should (eq 'eglot-diagnostic-tag-unnecessary-face
(face-at-point))))))))
+
(defun eglot--eldoc-on-demand ()
;; Trick Eldoc 1.1.0 into accepting on-demand calls.
(eldoc t))
diff --git a/eglot.el b/eglot.el
index 813b29775e..dc20ef751b 100644
--- a/eglot.el
+++ b/eglot.el
@@ -252,6 +252,14 @@ CONTACT can be:
'((t (:inherit font-lock-constant-face :weight bold)))
"Face for package-name in EGLOT's mode line.")
+(defface eglot-diagnostic-tag-unnecessary-face
+ '((t . (:weight ultra-light)))
+ "Face used to render unused or unnecessary code.")
+
+(defface eglot-diagnostic-tag-deprecated-face
+ '((t . (:strike-through t)))
+ "Face used to render deprecated or obsolete code.")
+
(defcustom eglot-autoreconnect 3
"Control ability to reconnect automatically to the LSP server.
If t, always reconnect automatically (not recommended). If nil,
@@ -332,6 +340,10 @@ This can be useful when using docker to run a language
server.")
(21 . "Constant") (22 . "Struct") (23 . "Event") (24 . "Operator")
(25 . "TypeParameter")))
+(defconst eglot--tag-faces
+ `((1 . eglot-diagnostic-tag-unnecessary-face)
+ (2 . eglot-diagnostic-tag-deprecated-face)))
+
(defconst eglot--{} (make-hash-table) "The empty JSON object.")
(defun eglot--executable-find (command &optional remote)
@@ -353,7 +365,7 @@ This can be useful when using docker to run a language
server.")
:sortText :filterText :insertText
:insertTextFormat
:textEdit :additionalTextEdits :commitCharacters
:command :data))
- (Diagnostic (:range :message) (:severity :code :source
:relatedInformation :codeDescription))
+ (Diagnostic (:range :message) (:severity :code :source
:relatedInformation :codeDescription :tags))
(DocumentHighlight (:range) (:kind))
(FileSystemWatcher (:globPattern) (:kind))
(Hover (:contents) (:range))
@@ -695,7 +707,11 @@ treated as in `eglot-dbind'."
;; TODO: We can support
:codeDescription after
;; adding an appropriate UI to
;; Flymake.
- :codeDescriptionSupport :json-false))
+ :codeDescriptionSupport :json-false
+ :tagSupport
+ `(:valueSet
+ [,@(mapcar
+ #'car eglot--tag-faces)])))
:experimental eglot--{})))
(defclass eglot-lsp-server (jsonrpc-process-connection)
@@ -1811,7 +1827,7 @@ COMMAND is a symbol naming the command."
(with-current-buffer buffer
(cl-loop
for diag-spec across diagnostics
- collect (eglot--dbind ((Diagnostic) range message severity source)
+ collect (eglot--dbind ((Diagnostic) range message severity source
tags)
diag-spec
(setq message (concat source ": " message))
(pcase-let
@@ -1839,7 +1855,11 @@ COMMAND is a symbol naming the command."
((<= sev 1) 'eglot-error)
((= sev 2) 'eglot-warning)
(t 'eglot-note))
- message `((eglot-lsp-diag .
,diag-spec)))))
+ message `((eglot-lsp-diag . ,diag-spec))
+ (and tags
+ `((face . ,(mapcar (lambda (tag)
+ (alist-get
tag eglot--tag-faces))
+ tags)))))))
into diags
finally (cond (eglot--current-flymake-report-fn
(eglot--report-to-flymake diags))