-
-
Notifications
You must be signed in to change notification settings - Fork 890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A couple minor fixes for Flymake diagnostics #4435
base: master
Are you sure you want to change the base?
Conversation
@@ -298,7 +307,7 @@ See https://github.com/emacs-lsp/lsp-mode." | |||
(when (= start end) | |||
(if-let ((region (flymake-diag-region (current-buffer) | |||
(1+ start-line) | |||
character))) | |||
(1+ character)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate why +1? 🤔 Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flymake-diag-region
expects the line and column values to start at 1, not start at 0 like LSP specifies. Thus, both the line and column need incrementing when calling flymake-diag-region
. The line number was already incremented but the column was not.
Note that this logic is only executed when the LSP server doesn't support an end position (i.e., the start and end position are the same), so flymake-diag-region
is used to compute it.
flymake-diag-region
is typically used to turn a normal compiler diagnostic position (1-based) into a region. Since LSP specifies position as 0-based, we need to adjust the line and column numbers before using the function.
Previously, there was a Flycheck specific defcustom, which was used to select a default error level for Flycheck. However, there was nothing for Flymake. Additionally, there were numerous other places in lsp-mode which query the severity attribute of the diagnostic, such as for statistics, modeline, headerline, etc. All of these were being handled inconsistently, either not at all (causing an error when the attribute was not sent by the server), ignoring it when it was missing (causing statistics to be inaccurate) or assuming a default of error, which might have been different than the Flycheck specific configuration, therefore causing an inconsistency in the modeline statistics vs what Flycheck would report. This change creates a common defcustom which is then used anywhere the diagnostic severity is needed, but was not provided by the server. This should create consistent statistics between the modeline and the back-end checkers. Additionally, the mapping between this defcustom and the checker specific values happens in the diagnostic package. Since this defcustom is used outside of the lsp-diagnostic package, it resides in the lsp-mode package and renamed more generally. Additionally, the Flycheck specific defcustom has been obsoleted.
71a9a69
to
a686a77
Compare
I decided to take a different approach with respect to the default severity level. Instead of adding an additional On a side note, I have also seen |
(level (cond ((= severity lsp/diagnostic-severity-error) 'error) | ||
((= severity lsp/diagnostic-severity-warning) 'warning) | ||
((= severity lsp/diagnostic-severity-information) 'info) | ||
((= severity lsp/diagnostic-severity-hint) 'info))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using pcase
is probably cleaner.
And the one below, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that at first, but was having trouble with pcase
not evaluating the lsp/diagnostic
variables. If you have an example of how to transform this, I'd appreciate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this isn't any cleaner. 🤔
(pcase severity
((pred (= lsp/diagnostic-severity-error)) 'error)
((pred (= lsp/diagnostic-severity-warning)) 'warning)
((pred (= lsp/diagnostic-severity-information)) 'info)
((pred (= lsp/diagnostic-severity-hint)) 'info)
(_ 'info))
It's okay to leave it as it is.
(const :tag "Information" info) | ||
(const :tag "Hint" hint)) | ||
:group 'lsp-mode | ||
:package-version '(lsp-mode . "9.0.1")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep this in lsp-diagnostics.el
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jcs090218, the reason I put it in lsp-mode.el is because there are multiple users, not just lsp-diagnostics.el. lsp-modeline, lsp-headerline, lsp-mode and lsp-diagnostics all need this information, so it seemed more general and likely belongs in lsp-mode.el. It answers the general question of what the user wants to do in the absence of LSP severity information. lsp-diagnostics.el is just one such user of this information.
I placed it in lsp-mode.el near a couple other diagnostic-related user options (i.e., lsp-after-diagnostics-hook and lsp-diagnostics-updated-hook) to be consistent there. It appears that lsp-diagnostics.el is strictly the diagnostics provider (i.e., Flymake/Flycheck) interfacing, but other LSP diagnostics related information is kept in lsp-mode.el.
No description provided.