Skip to content
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

Support optional Diagnostic.tags #794

Merged
merged 1 commit into from Jan 13, 2022
Merged

Conversation

leungbk
Copy link
Contributor

@leungbk leungbk commented Jan 11, 2022

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--lsp-interface-alist): Add Diagnostic.tags.
    (eglot-client-capabilities): Advertise supported tags.
    (eglot-handle-notification): Assign the appropriate properties.

eglot.el Outdated Show resolved Hide resolved
@skangas
Copy link
Collaborator

skangas commented Jan 11, 2022

Thanks, this looks like a very useful feature. I would suggest that we should have faces instead of a defconst here, to make it easier for users to customize this with the full power of customize-option+defface. WDYT?

@leungbk
Copy link
Contributor Author

leungbk commented Jan 11, 2022

Thanks, this looks like a very useful feature. I would suggest that we should have faces instead of a defconst here, to make it easier for users to customize this with the full power of customize-option+defface. WDYT?

Done.

eglot.el Show resolved Hide resolved
@dgutov
Copy link
Collaborator

dgutov commented Jan 11, 2022

FWIW, company-capf uses the :company-deprecated property for the latter. And has a matching face definition.

The "unnecessary" tag never came up before.

@joaotavora
Copy link
Owner

I generally think this PR is good to go (after the usual git commit tweaks maybe).

@dgutov can you explain what your suggestion is? How can :company-deprecated help here? AFAIU this is for diagnostics, nor completions

@leungbk
Copy link
Contributor Author

leungbk commented Jan 11, 2022

Oh yeah, do we want a test for this before merging? Pyright sends the Unused property, and that was how I checked my commit. I'm not at home right now, but I can get around to writing a test by tomorrow.

@dgutov
Copy link
Collaborator

dgutov commented Jan 11, 2022

Ah, sorry.

I thought you were going to add "deprecated" support for completions, which is also missing in Eglot.

@skangas
Copy link
Collaborator

skangas commented Jan 11, 2022

@leungbk A test case would be useful, I think.

@leungbk
Copy link
Contributor Author

leungbk commented Jan 12, 2022

@skangas Done. My test case (requires npm i -g pyright) passes after running make check.

@leungbk
Copy link
Contributor Author

leungbk commented Jan 12, 2022

Actually...hold on, I need to spend some time debugging the test.

@leungbk
Copy link
Contributor Author

leungbk commented Jan 12, 2022

@skangas OK, now it works. I used rust-analyzer instead since pyright-langserver behaved unexpectedly when running tests.

@leungbk leungbk force-pushed the diag-tags branch 3 times, most recently from 8a6da0c to 45c3a89 Compare January 12, 2022 16:14
@skangas
Copy link
Collaborator

skangas commented Jan 12, 2022

This seems to lead to a byte-compiler warning:

eglot.el:1822:1: Warning: Destructuring for Diagnostic has extraneous (:tags)

@joaotavora
Copy link
Owner

Nice. That just means that the Diagnostic type further up in the file must also be changed, informing Eglot that tags is a new optional field.

@leungbk
Copy link
Contributor Author

leungbk commented Jan 13, 2022

This seems to lead to a byte-compiler warning:

eglot.el:1822:1: Warning: Destructuring for Diagnostic has extraneous (:tags)

I can't reproduce this with make clean && make check in the root directory. The Diagnostic type seems to be appropriately extended with the new optional :tags field; you might be looking at one of my earlier (botched) attempts at fixing a merge conflict, when I made a typo extending the Diagnostic type.

@skangas
Copy link
Collaborator

skangas commented Jan 13, 2022

I can't reproduce this with make clean && make check in the root directory.

Hmm, I can reproduce this consistently... but it seems like I can't reproduce this after restarting Emacs, nor can I reproduce it from emacs -Q. I guess something was going on with the Emacs session where I'm seeing this. Sorry for the noise.

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.
@skangas skangas merged commit 06451ea into joaotavora:master Jan 13, 2022
@skangas
Copy link
Collaborator

skangas commented Jan 13, 2022

I had to increase the test timeout to 5 seconds, but now everything is working here. I see this diagnostic when replicating the test case manually:

rustc: unused variable: `test`
`#[warn(unused_variables)]` on by default
rustc: if this is intentional, prefix it with an underscore: `_test`

So I fixed up the commit message slightly (feel free to take a look at the changes) and merged this to master. Thanks for your contribution!

@theothornhill
Copy link
Contributor

I can't reproduce this with make clean && make check in the root directory.

Hmm, I can reproduce this consistently... but it seems like I can't reproduce this after restarting Emacs, nor can I reproduce it from emacs -Q. I guess something was going on with the Emacs session where I'm seeing this. Sorry for the noise.

This can happen if you eval-buffer eglot. I've seen this sometimes as well, and I believe it has with some of the eval-and-compiles running around.

@joaotavora
Copy link
Owner

This can happen if you eval-buffer eglot. I've seen this sometimes as well, and I believe it has with some of the eval-and-compiles running around.

Yes, Eglot is meant to be compiled, then loaded. If you just interpret it you will get some of that trouble when you do try to compile it. So I recommend always M-x emacs-lisp-byte-compile-and-load when loading the whole file. Even for individual definitions, I tend to prefer compile-defun. But of course C-M-x and C-x C-e also work 99% of the time.

Nice test, btw, @leungbk! Seems very clean. And @skangas now that there's a rust-analyzer test there, maybe the "watches files" test can also migrate from rls to rust-analyzer?

@skangas
Copy link
Collaborator

skangas commented Jan 14, 2022

@skangas now that there's a rust-analyzer test there, maybe the "watches files" test can also migrate from rls to rust-analyzer?

Yup, I'll look into it.

bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 18, 2022
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.
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
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.
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
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.

#794: joaotavora/eglot#794
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this pull request Oct 12, 2022
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.

GitHub-reference: per joaotavora/eglot#794
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this pull request Oct 20, 2022
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.

GitHub-reference: per joaotavora/eglot#794
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants