ale icon indicating copy to clipboard operation
ale copied to clipboard

Support `dmypy` to speed up linting with `mypy` without too much user intervention

Open sigmavirus24 opened this issue 2 years ago • 1 comments

Disclaimer:
I'm going to structure this probably oddly because I understand the blockers here and want to be clear that I'm hoping to contribute to a discussion to make this plausible and not try to put the burden entirely on the maintainers here.


Background

Today, ALE supports running mypy against a given file. This is super helpful to get static analysis in the editor. mypy, unfortunately, is dreadfully slow and running it against a single file often causes it to sprawl across imports, etc. This is helpful, but leads to a very poor user experience (in my opinion as a user). mypy has recently(?) introduced dmypy which allows users to start a server that caches much of the information and run analysis much faster.

One can detect dmypy as being up and running (by default) when the directory it was started from has .dmypy.json present whose contents look like

{"pid": 155810, "connection_name": "/tmp/tmp9vo1oy2m/dmypy.sock"}

Request

I'd love to be able to - when possible (this is the hard part I think) - use dmypy with ALE but that would require re-configuring ALE each time I know that I am already running the dmypy server for that project.

First step towards better experience

I'm wondering if as a first step towards better behaviour we could detect the presence of that file in whatever directory vim is started in and auto-swap to dmypy run or dmypy check with the given file.

I think this shouldn't be too bad but I don't know if ALE already has a pattern like this for another language and if it's worth adding this kind of behaviour to the plugin.

Bigger step towards a better experience

Long term it would be awesome for ALE to detect dmypy exists as an executable, and start it from whatever directory here or maybe in the parent(s) has mypy config.

This is super hard if only because mypy allows a range of files to hold configuration in and we'd have to be reasonably confident we've found a directory with that to start dmypy from. Then, how do we know what files to include in the start command? It becomes kind of nightmare-ish when you think about the variety of project layouts and possibilities and then "what's the smart/fast thing" versus "what's the better UX thing".

Honestly, I'm not a vim plugin developer and haven't done much, nor have I dug into ALE's internals so this isn't something I have my hopes high for.

sigmavirus24 avatar Mar 19 '22 13:03 sigmavirus24

From a quick look at dmypy documentation it seems it can be used as any normal linter so it should be straightforward to add it to ALE as any other linter. Invoking dmypy run -- <flags> <files> starts the server if is not running and changes to configuration automatically restarts the daemon.

Not tested but I think that modifiying the ale_linters#python#mypy#GetCommand() and ale_linters#python#mypy#GetExecutable() methods to return the proper executable and invocation command should do. Note these functions have some logic to support pipenv and poetry if they are being used.

hsanson avatar Apr 06 '22 11:04 hsanson