8000 Reduce redundant lint calls (#505) · python-lsp/python-lsp-server@0056d00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0056d00

Browse files
lgeigergatesn
authored andcommitted
Reduce redundant lint calls (#505)
1 parent de850aa commit 0056d00

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pyls/python_ls.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
LINT_DEBOUNCE_S = 0.5 # 500 ms
1818
PARENT_PROCESS_WATCH_INTERVAL = 10 # 10 s
1919
MAX_WORKERS = 64
20+
# We also watch for changes in config files
21+
PYTHON_FILE_EXTENSIONS = ('.py', '.pyi', 'pycodestyle.cfg', 'setup.cfg', 'tox.ini', '.flake8')
2022

2123

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

297-
def m_workspace__did_change_watched_files(self, **_kwargs):
298-
# Externally changed files may result in changed diagnostics
299+
def m_workspace__did_change_watched_files(self, changes=None, **_kwargs):
300+
changed_py_files = set(d['uri'] for d in changes if d['uri'].endswith(PYTHON_FILE_EXTENSIONS))
301+
# Only externally changed python files and lint configs may result in changed diagnostics.
302+
if not changed_py_files:
303+
return
304+
# TODO: We currently don't cache settings therefor we can just lint again.
305+
# Here would be the right point to update the settings after a change to config files.
299306
for doc_uri in self.workspace.documents:
300-
self.lint(doc_uri)
307+
# Changes in doc_uri are already handled by m_text_document__did_save
308+
if doc_uri not in changed_py_files:
309+
self.lint(doc_uri)
301310

302311
def m_workspace__execute_command(self, command=None, arguments=None):
303312
return self.execute_command(command, arguments)

0 commit comments

Comments
 (0)
0