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

Make DocumentSyncListener more efficient if no server is running #2532

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ def session_views_async(self) -> list[SessionView]:
return list(self._session_views.values())

def on_text_changed_async(self, change_count: int, changes: Iterable[sublime.TextChange]) -> None:
if not self.sessions_async():
return
if self.view.is_primary():
for sv in self.session_views_async():
sv.on_text_changed_async(change_count, changes)
rchl marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -364,6 +366,8 @@ def on_activated_async(self) -> None:
return
if not self._registered:
self._register_async()
if not self.sessions_async():
return
if userprefs().show_code_actions:
self._do_code_actions_async()
for sv in self.session_views_async():
Expand All @@ -382,6 +386,8 @@ def on_activated_async(self) -> None:
sb.do_inlay_hints_async(self.view)

def on_selection_modified_async(self) -> None:
if not self.sessions_async():
return
first_region, _ = self._update_stored_selection_async()
if first_region is None:
return
Expand Down Expand Up @@ -483,6 +489,8 @@ def on_query_context(self, key: str, operator: int, operand: Any, match_all: boo
return None

def on_hover(self, point: int, hover_zone: int) -> None:
if not self.sessions_async():
return
if self.view.is_popup_visible():
return
window = self.view.window()
Expand Down Expand Up @@ -525,6 +533,8 @@ def _on_hover_gutter_async(self, point: int) -> None:
on_navigate=lambda href: self._on_navigate(href, point))

def on_text_command(self, command_name: str, args: dict | None) -> tuple[str, dict] | None:
if not self.sessions_async():
return None
if command_name == "auto_complete":
self._auto_complete_triggered_manually = True
elif command_name == "show_scope_name" and userprefs().semantic_highlighting:
Expand All @@ -540,6 +550,8 @@ def on_text_command(self, command_name: str, args: dict | None) -> tuple[str, di
return None

def on_post_text_command(self, command_name: str, args: dict[str, Any] | None) -> None:
if not self.sessions_async():
return
if command_name == 'paste':
format_on_paste = self.view.settings().get('lsp_format_on_paste', userprefs().lsp_format_on_paste)
if format_on_paste and self.session_async("documentRangeFormattingProvider"):
Expand All @@ -553,6 +565,8 @@ def on_post_text_command(self, command_name: str, args: dict[str, Any] | None) -
self.view.hide_popup()

def on_query_completions(self, prefix: str, locations: list[int]) -> sublime.CompletionList | None:
if not self.sessions_async():
return None
completion_list = sublime.CompletionList()
triggered_manually = self._auto_complete_triggered_manually
self._auto_complete_triggered_manually = False # reset state for next completion popup
Expand Down