Skip to content

Commit

Permalink
remove unnecessary use of generators for session retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Sep 30, 2024
1 parent 603632e commit 32b6fdf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions plugin/core/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .windows import WindowManager
from .windows import WindowRegistry
from functools import partial
from typing import Any, Generator, Iterable
from typing import Any, Generator
import operator
import sublime
import sublime_plugin
Expand All @@ -21,14 +21,14 @@
windows = WindowRegistry()


def best_session(view: sublime.View, sessions: Iterable[Session], point: int | None = None) -> Session | None:
def best_session(view: sublime.View, sessions: list[Session], point: int | None = None) -> Session | None:
if point is None:
try:
point = view.sel()[0].b
except IndexError:
return None
try:
return max(sessions, key=lambda s: view.score_selector(point, s.config.priority_selector)) # type: ignore
return max(sessions, key=lambda s: view.score_selector(point, s.config.priority_selector))
except ValueError:
return None

Expand Down
6 changes: 3 additions & 3 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,15 @@ def session_async(self, capability: str, point: int | None = None) -> Session |
raise NotImplementedError()

@abstractmethod
def sessions_async(self, capability: str | None = None) -> Generator[Session, None, None]:
def sessions_async(self, capability: str | None = None) -> list[Session]:
raise NotImplementedError()

@abstractmethod
def session_buffers_async(self, capability: str | None = None) -> Generator[SessionBufferProtocol, None, None]:
def session_buffers_async(self, capability: str | None = None) -> list[SessionBufferProtocol]:
raise NotImplementedError()

@abstractmethod
def session_views_async(self) -> Generator[SessionViewProtocol, None, None]:
def session_views_async(self) -> list[SessionViewProtocol]:
raise NotImplementedError()

@abstractmethod
Expand Down
22 changes: 12 additions & 10 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,14 @@ def _update_diagnostic_in_status_bar_async(self) -> None:
return
self.view.erase_status(self.ACTIVE_DIAGNOSTIC)

def session_buffers_async(self, capability: str | None = None) -> Generator[SessionBuffer, None, None]:
for sv in self.session_views_async():
if capability is None or sv.has_capability_async(capability):
yield sv.session_buffer
def session_buffers_async(self, capability: str | None = None) -> list[SessionBuffer]:
return [
sv.session_buffer for sv in self.session_views_async()
if capability is None or sv.has_capability_async(capability)
]

def session_views_async(self) -> Generator[SessionView, None, None]:
yield from self._session_views.values()
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 self.view.is_primary():
Expand Down Expand Up @@ -857,10 +858,11 @@ def _on_initial_folding_ranges(self, kinds: list[str], response: list[FoldingRan
def session_async(self, capability: str, point: int | None = None) -> Session | None:
return best_session(self.view, self.sessions_async(capability), point)

def sessions_async(self, capability: str | None = None) -> Generator[Session, None, None]:
for sb in self.session_buffers_async():
if capability is None or sb.has_capability(capability):
yield sb.session
def sessions_async(self, capability: str | None = None) -> list[Session]:
return [
sb.session for sb in self.session_buffers_async()
if capability is None or sb.has_capability(capability)
]

def session_by_name(self, name: str | None = None) -> Session | None:
for sb in self.session_buffers_async():
Expand Down

0 comments on commit 32b6fdf

Please sign in to comment.