python-lsp / pylsp-mypy

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

Add dmypy support via mypy.api.run_dmypy #1

Closed asford closed 3 years ago

asford commented 3 years ago

https://github.com/palantir/python-language-server/issues/391

Update plugin flow for non-live-mode dmypy invocation via mypy.api.run_dmypy.

Minor fix to update detect .mypy.ini as well as mypy.ini: https://mypy.readthedocs.io/en/stable/config_file.html

asford commented 3 years ago

@Richardk2n Friendly ping, I'm not sure if you'd like to fold this in along with #2 but it'd be great to include this if possible.

I've fixed up the lingering 3.6 syntax failures.

asford commented 3 years ago

Referenced in https://github.com/tomv564/pyls-mypy/issues/51

Richardk2n commented 3 years ago

Once #2 is successfully merged (probably in a few minutes), I will look at this (maybe ask some questions) and then probably merge it as well.

Richardk2n commented 3 years ago

@asford Should the daemon be closed for example atexit ?

asford commented 3 years ago

@asford Should the daemon be closed for example atexit ?

I don't think the daemon should be closed, as the daemon can persist expensive cached state between editor sessions. For example, I use vim-lsp and end-up reusing the dmypy daemon as I hop between vim sessions. In some codebases, where dmypy is ...extremely useful... starting the daemon for a first run is extremely expensive. Most users are probably just calling dmypy run from the command line, which doesn't stop the server after the run.

haplo commented 3 years ago

The codebase is now formatted with black after #4 was merged. @asford you can pull from master, ignore all changes to plugin.py and then run black . to blacken your changes.

Richardk2n commented 3 years ago

@asford please note that 90a37e118a8af3c1fab845a425071ec742bfdb4d contains how I would like to have this merged. I put it in a commit to make sure it does not get lost when you pull/merge from master.

asford commented 3 years ago

Roger, thanks for the through review. I've squash-rebased on the most-recent upstream, so this should be a minimal mergeable diff.

rchl commented 3 years ago

I've noticed that using dmypy through pylsp creates a .dmypy.json file in every project. Ideally that wouldn't happen. Is it possible to create that file in a temp directory?

Richardk2n commented 3 years ago

I've noticed that using dmypy through pylsp creates a .dmypy.json file in every project. Ideally that wouldn't happen. Is it possible to create that file in a temp directory?

mypy also creates a .mypy_cache folder, which seems to not be a problem? Why is .dmypy.json a problem?

rchl commented 3 years ago

I guess I'm used to .mypy_cache being git-ignored while .dmypy.json is new to me and from the naming looks like a configuration file rather than something that should be ignored.

From the documentation it looks like it's in fact a temporary file that could be ignored but in that case can't we actually define its location to be .mypy_cache/.dmypy.json? I think that would be nice if it worked.

But in the worse case, git-ignoring .dmypy.json is an acceptable solution of course. But it would require updating .gitignore file in many projects.