-
Notifications
You must be signed in to change notification settings - Fork 285
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
Reduce redundant lint calls #505
Conversation
Currently, whenever a file in the workspace changes all open documents are linted. This causes a lot of unnecessary lint calls. With this PR changes to files not ending with `.py` or `.pyi` and changes that are already handled by the `didChange` event are ignored. This issue is very problematic when using [`pyls-mypy'](https://github.com/tomv564/pyls-mypy/). `mypy` writes cache files after each lint which results in `didChangeWatchedFiles` to be triggered, resulting in a infinite lint loop.
@gatesn Do you have time to review this PR? |
pyls/python_ls.py
Outdated
def m_workspace__did_change_watched_files(self, **_kwargs): | ||
# Externally changed files may result in changed diagnostics | ||
def m_workspace__did_change_watched_files(self, changes=None, **_kwargs): | ||
changed_py_files = set(d['uri'] for d in changes if d['uri'].endswith(('.py', '.pyi'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be add .cfg
and .ini
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect that this is handled by didChangeConfig, but on the other hand the client doesn't know that we're also accepting config files.
I'll look into what config file changes should trigger a lint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move the list of file extensions to a static at the top? And thoughts about trying to cover some of the linter config files too?
As for the mypy thing, have you tried out #392 ? Wondering whether to invest more time in it
I had a few weird errors with https://github.com/tomv564/pyls-mypy since it occasionally writes to stdout, but I didn't had a chance to checkout your PR. I'll try it our soon. |
Fixed in 4bfd36a |
if not changed_py_files: | ||
return | ||
# TODO: We currently don't cache settings therefor we can just lint again. | ||
# Here would be the right point to update the settings after a change to config files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix this TODO after this PR has been merged.
Currently, whenever a file in the workspace changes all open documents are linted. This causes a lot of unnecessary lint calls.
With this PR
pyls
ignores changes to files that do not end with.py
or.pyi
and changes that are already handled by the didChange event.This issue is very problematic when using
pyls-mypy
.mypy
writes cache files after each lint which results indidChangeWatchedFiles
to be triggered, resulting in a infinite lint loop.