Skip to content

Commit

Permalink
Add buffer-local variable lsp-bridge-diagnostic-records for flymake i…
Browse files Browse the repository at this point in the history
…nterface
  • Loading branch information
liuyinz committed Oct 4, 2023
1 parent 0ad8afb commit 8036500
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions core/fileaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def try_push_diagnostics(self, ticker):
# Only push diagnostics to Emacs when ticker is newest.
# Drop all temporarily diagnostics when typing.
if ticker == self.diagnostics_ticker:
eval_in_emacs("lsp-bridge-diagnostic--update", self.filepath, get_lsp_file_host(), self.get_diagnostics())
eval_in_emacs("lsp-bridge-diagnostic--render", self.filepath, get_lsp_file_host(), self.get_diagnostics())

def push_code_actions(self, actions, server_name, action_kind):
Expand Down
39 changes: 29 additions & 10 deletions lsp-bridge-diagnostic.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@
:type 'float
:group 'lsp-bridge)

(defcustom lsp-bridge-diagnostic-use-builtin t
"The style for diagnostics rendering overlays.
Set to nil if flymake/flycheck frontend is used instead."
:type 'boolean
:group 'lsp-bridge)

(defcustom lsp-bridge-diagnostic-update-hook '()
"The hook for diagnostics updates."
:type 'hook
:group 'lsp-bridge)

(defface lsp-bridge-diagnostics-error-face
'((t (:underline (:style wave :color "Red1"))))
"Face error diagnostic."
Expand Down Expand Up @@ -149,6 +160,8 @@ You can set this value with `(2 3 4) if you just need render error diagnostic."
:type 'list
:group 'lsp-bridge)

(defvar-local lsp-bridge-diagnostic-records nil)

(defvar-local lsp-bridge-diagnostic-overlays '())

(defvar lsp-bridge-diagnostic-frame nil)
Expand All @@ -169,13 +182,19 @@ You can set this value with `(2 3 4) if you just need render error diagnostic."

(defun lsp-bridge-diagnostic--render (filepath filehost diagnostics)
(lsp-bridge--with-file-buffer filepath filehost
(lsp-bridge-diagnostic-hide-overlays)

(let ((diagnostic-index 0)
(diagnostic-number (length diagnostics)))
(dolist (diagnostic diagnostics)
(let ((severity (plist-get diagnostic :severity)))
(unless (member severity lsp-bridge-diagnostic-hide-severities)
(setq-local lsp-bridge-diagnostic-records
(seq-remove
(lambda (diagnostic)
(member (plist-get diagnostic :severity) lsp-bridge-diagnostic-hide-severities))
diagnostics))
(run-hooks 'lsp-bridge-diagnostic-update-hook)

(when lsp-bridge-diagnostic-use-builtin
(lsp-bridge-diagnostic-hide-overlays)
(let ((diagnostic-index 0)
(diagnostic-number (length lsp-bridge-diagnostic-records)))
(dolist (diagnostic lsp-bridge-diagnostic-records)
(let ((severity (plist-get diagnostic :severity)))
(let* ((diagnostic-start (acm-backend-lsp-position-to-point (plist-get (plist-get diagnostic :range) :start)))
(diagnostic-end (acm-backend-lsp-position-to-point (plist-get (plist-get diagnostic :range) :end)))
(overlay (if (eq diagnostic-start diagnostic-end)
Expand All @@ -196,10 +215,10 @@ You can set this value with `(2 3 4) if you just need render error diagnostic."
(if (> diagnostic-number 1)
(format "[%s:%s] %s" (1+ diagnostic-index) diagnostic-number message)
message))
(push overlay lsp-bridge-diagnostic-overlays))))
(push overlay lsp-bridge-diagnostic-overlays)))

(setq diagnostic-index (1+ diagnostic-index))))
(setq-local lsp-bridge-diagnostic-overlays (reverse lsp-bridge-diagnostic-overlays))))
(setq diagnostic-index (1+ diagnostic-index))))
(setq-local lsp-bridge-diagnostic-overlays (reverse lsp-bridge-diagnostic-overlays)))))

(defvar lsp-bridge-diagnostic-frame nil)

Expand Down

0 comments on commit 8036500

Please sign in to comment.