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

Reduce redundant lint calls #505

Merged
merged 2 commits into from
Feb 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pyls/python_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
LINT_DEBOUNCE_S = 0.5 # 500 ms
PARENT_PROCESS_WATCH_INTERVAL = 10 # 10 s
MAX_WORKERS = 64
# We also watch for changes in config files
PYTHON_FILE_EXTENSIONS = ('.py', '.pyi', 'pycodestyle.cfg', 'setup.cfg', 'tox.ini', '.flake8')


class _StreamHandlerWrapper(socketserver.StreamRequestHandler, object):
Expand Down Expand Up @@ -294,10 +296,17 @@ def m_workspace__did_change_configuration(self, settings=None):
for doc_uri in self.workspace.documents:
self.lint(doc_uri)

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(PYTHON_FILE_EXTENSIONS))
# Only externally changed python files and lint configs may result in changed diagnostics.
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.
Copy link
Contributor Author

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.

for doc_uri in self.workspace.documents:
self.lint(doc_uri)
# Changes in doc_uri are already handled by m_text_document__did_save
if doc_uri not in changed_py_files:
self.lint(doc_uri)

def m_workspace__execute_command(self, command=None, arguments=None):
return self.execute_command(command, arguments)
Expand Down