feat: append LSP diagnostic codes to flymake messages#5036
Conversation
|
Can you do this to |
|
Hi @jcs090218, thanks for the quick reply already. I checked flycheck. The good news is that we don't need to change anything in the flycheck branch. The code is already correct and exactly displays the error code as [CODE]. You can see that code? was already deconstructed and passed to (-map (-lambda ((&Diagnostic :message :severity? :tags? :code? :source?
: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
:filename buffer-file-name
:message message
:level (lsp-diagnostics--flycheck-calculate-level severity? tags?)
:id code?
:group source?
:line (lsp-translate-line (1+ start-line))
:column (1+ (lsp-translate-column start-character))
:end-line (lsp-translate-line (1+ end-line))
:end-column (unless (lsp--position-equal start end)
(1+ (lsp-translate-column end-character))))))What was missing was precisely the flymake branch where the code was not displayed. If this PR makes it to upstream, then both branches display the same message and error code. |
|
Hi @jcs090218 and maintainers, I looked into the three failing CI checks (the While I have your attention, would you be open to a follow-up that makes this more configurable per client? Two directions where I'd appreciate your feedback:
My motivation is that for some servers the codes are essential (Pyright, tsc), while for others they're just visual noise on every line. Happy to prepare a demo PR for whichever direction you prefer, either extending this one, or as a separate PR once this lands. Let me know what you think is the best. |
Yeah, there are breaking changes on the Emacs snapshot. No need to worry about those job failures (at least for now). :)
I prefer the Composable formatter approach because it's more flexible and gives users greater control. Thanks for bringing this up! :D |
b94bab6 to
d468183
Compare
d468183 to
723a064
Compare
Currently,
lsp-diagnostics--flymake-update-diagnosticsextracts:messageand:severity?from each LSP diagnostic but silently drops:code?. As a result, flymake displays messages like:without the diagnostic rule name that the language server also provides.
This patch binds
:code?and appends it to the message text when present:This is a small but valuable change. The diagnostic code is the primary handle users need to:
# pyright: ignore[reportPossiblyUnbound])Without the code, users must guess the rule name. The fix is a two-line change: bind
:code?in the existing-let*destructuring and conditionally append[code]to the message.The code field is optional in the LSP spec, so the format falls back gracefully to the plain message when absent.