python-lsp / pylsp-mypy

Mypy plugin for the Python LSP Server.
MIT License
118 stars 35 forks source link

Handle custom `overrides` which may not include `show_column_numbers` or `show_error_end` settings #79

Open snejus opened 6 months ago

snejus commented 6 months ago

In projects which configure 'show_column_numbers = true', pylsp would not return anything back to my editor.

In the logs I found messages like below

... discarding result for beetsplug/bandcamp/track.py:113 against /home/sarunas/repo/beetcamp/beetsplug/bandcamp/track.py

The logic only returns the result if the latter filename ends with the former, thus it seems that the column number (':113') is not supposed to be present here.

Having had a look at the matching pattern I found that it does not take into account that the column number may be present.

This commit adjusts the pattern to handle the column number correctly.

Edit:

Seems like the issue was actually caused by me providing custom mypy overrides through the plugin settings which did not include show_column_numbers = true setting that the plugin sets internally.

Richardk2n commented 4 months ago

Can you provide an example producing this issue? Given pylsp-mypy sets show-error-end, which implies show_column_numbers, setting that should not make a difference. This second pattern was introduced for certain errors not honoring these flags and should normally not be used. It seems you stumbled upon one, that partially respects the flag. I was not aware of such errors and would like to investigate.

snejus commented 4 months ago

Given pylsp-mypy sets show-error-end, which implies show_column_numbers, setting that should not make a difference.

Completely! I later found that this probably happened because I provided my own overrides in the plugin settings which did not include show_column_numbers or show_error_end. I will update the PR description accordingly now.

snejus commented 4 months ago

Given the above, it seems like we'd rather always provide --show-error-end to mypy regardless of whether there are overrides or not. What do you think?

snejus commented 4 months ago

With overrides = {}

[ERROR][2024-04-26 12:02:20] .../vim/lsp/rpc.lua:734    "rpc"   "/media/pipx-3.8/bin/pylsp"     "stderr"        "2024-04-26 12:02:20,097 BST - WARNING - pylsp_mypy.plugin - executing mypy args = [] via api\n"

With overrides = { true }

[ERROR][2024-04-26 12:03:14] .../vim/lsp/rpc.lua:734    "rpc"   "/media/pipx-3.8/bin/pylsp"     "stderr"        "2024-04-26 12:03:14,040 BST - WARNING - pylsp_mypy.plugin - executing mypy args = ['--show-error-end', '--no-error-summary', '--config-file', '/home/sarunas/repo/pyls-mypy/pyproject.toml', '/home/sarunas/repo/pyls-mypy/pylsp_mypy/plugin.py', '--incremental', '--follow-imports', 'silent'] via api\n"
snejus commented 4 months ago

See the last three commits: