Make DocumentSyncListener more efficient if no server is running #2532
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently if LSP (this package) is installed, it runs quite some code in the background whenever the callbacks from
DocumentSyncListener
, which is a subclass ofsublime.ViewEventListener
, are triggered. This happens for all views, not only when a server is active. For example it creates an empty (if no server is running)sublime.CompletionList
and schedules to run more code on the async thread inLSP/plugin/documents.py
Lines 555 to 560 in a6b17a4
or it runs the debouncing in
LSP/plugin/documents.py
Line 384 in a6b17a4
sublime.set_timeout_async
each time when the cursor position changes.All of this runs on the async thread, so you won't immediately experience any lag from this. But still it feels very inefficient and I wondered how it could be prevented or improved. We can't use the
is_applicable
classmethod forDocumentSyncListener
, because if the view's syntax is changed later, an LSP session might still get attached to this view. So my idea would be to add a check in each of the ST callback methods and return early if there is no session running for this view. Does it make sense or is there a better solution?