Skip to content

Commit

Permalink
Reduce redundant lint calls (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgeiger authored and gatesn committed Feb 21, 2019
1 parent de850aa commit 0056d00
Showing 1 changed file with 12 additions and 3 deletions.
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.
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

0 comments on commit 0056d00

Please sign in to comment.