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

Add mypy's error code to the error diagnostic message #76

Open
lieryan opened this issue Jan 15, 2024 · 5 comments
Open

Add mypy's error code to the error diagnostic message #76

lieryan opened this issue Jan 15, 2024 · 5 comments

Comments

@lieryan
Copy link

lieryan commented Jan 15, 2024

Use case

Whenever I want to add an # type ignore[xxx] for an error, I often need to recall what error code that this particular error message has.

image

It would be nice if the diagnostic message produced by pylsp-mypy would also display the error code, similar to mypy's default error message on the CLI:

...
foo.py:8: error: Incompatible return value type (got "int", expected "str")  [return-value]

Additionally, it'd be even nicer if there's a code action that allows you to add an ignore line and/or automatically suggest some common quick fixes for some of the more common error codes.

@Richardk2n
Copy link
Member

The error code is not part of the message. However, pylsp-mypy passes the error code with the message to pylsp which in turn gives it to your editor (as far as I know). The editor is then responsible for displaying it is so desired by the user.

The only quick fix I can think of would be the ignore. Is there another you would like to see implemented?

@lieryan
Copy link
Author

lieryan commented Jan 29, 2024

Adding type: ignore is pretty much the only use case I needed it for now. I can run mypy <filename> on the terminal for the rarer cases or just copy the error code from the code action.

However, pylsp-mypy passes the error code with the message to pylsp which in turn gives it to your editor (as far as I know)

Thanks for the pointer, I'll double check if this is something that my LSP client can be configured to do.

@CameronNemo
Copy link

I think I've noticed the same problem with ruff, too. I get the description of the error, but not the actual code. I am using neovim's builtin LSP client.

@Richardk2n
Copy link
Member

The code action is implemented now. From my testing client support was not as straight forward as I expected. Feel free to try the current master and tell me if it works.

@ccordoba12 Quick question: Does Spyder support LSP code actions, because I did not find them.

@lieryan
Copy link
Author

lieryan commented Mar 5, 2024

The quickfix action works well so far on master, I hadn't noticed any issues. Tested on vim-lsp.

Thanks @Richardk2n!

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

No branches or pull requests

3 participants