Skip to content

Commit

Permalink
Allow Flycheck to determine a diagnostic end position when needed. (#…
Browse files Browse the repository at this point in the history
…4429)

When a Language Server doesn't support an end position for a
diagnostic (by specifying an end position the same as the start
position) Flycheck should be asked to compute the end position using
it's `flycheck-highlighting-mode` setting.  This is accomplished by
passing nil as the end-column to `flycheck-error-new`.

This provides consistent behavior between Flymake and Flycheck as the
Flymake integration already checks for this condition and uses it's
similar functionality (i.e., `flymake-diag-region`) to compute an end
position.
  • Loading branch information
brownts committed Apr 16, 2024
1 parent 4a0aec0 commit e67008b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lsp-diagnostics.el
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ CALLBACK is the status callback passed by Flycheck."

(->> (lsp--get-buffer-diagnostics)
(-map (-lambda ((&Diagnostic :message :severity? :tags? :code? :source?
:range (&Range :start (&Position :line start-line
:character start-character)
:end (&Position :line end-line
:character end-character))))
:range (&Range :start (start &as &Position
:line start-line
:character start-character)
:end (end &as &Position
:line end-line
:character end-character))))
(flycheck-error-new
:buffer (current-buffer)
:checker checker
Expand All @@ -171,7 +173,8 @@ CALLBACK is the status callback passed by Flycheck."
:line (lsp-translate-line (1+ start-line))
:column (1+ (lsp-translate-column start-character))
:end-line (lsp-translate-line (1+ end-line))
:end-column (1+ (lsp-translate-column end-character)))))
:end-column (unless (lsp--position-equal start end)
(1+ (lsp-translate-column end-character))))))
(funcall callback 'finished)))

(defun lsp-diagnostics--flycheck-buffer ()
Expand Down

0 comments on commit e67008b

Please sign in to comment.