From 563575b6b0b3179a51a79329ee34d1579664a542 Mon Sep 17 00:00:00 2001 From: Lukas Geiger Date: Fri, 15 Feb 2019 18:24:37 +0100 Subject: [PATCH 1/2] Reduce redundant lint calls 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. --- pyls/python_ls.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pyls/python_ls.py b/pyls/python_ls.py index d4275f5d..20cca98e 100644 --- a/pyls/python_ls.py +++ b/pyls/python_ls.py @@ -294,10 +294,15 @@ 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(('.py', '.pyi'))) + # Only externally changed python files may result in changed diagnostics + if not changed_py_files: + return 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) From 4bfd36acf2dad3979888447b5c7b2d6ab1f3c51c Mon Sep 17 00:00:00 2001 From: Lukas Geiger Date: Thu, 21 Feb 2019 11:48:54 +0000 Subject: [PATCH 2/2] Lint if config changes --- pyls/python_ls.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyls/python_ls.py b/pyls/python_ls.py index 20cca98e..b9e54634 100644 --- a/pyls/python_ls.py +++ b/pyls/python_ls.py @@ -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): @@ -295,10 +297,12 @@ def m_workspace__did_change_configuration(self, settings=None): self.lint(doc_uri) 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'))) - # Only externally changed python files may result in changed diagnostics + 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: # Changes in doc_uri are already handled by m_text_document__did_save if doc_uri not in changed_py_files: