Skip to content

Commit

Permalink
refactor: tidy codes
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
  • Loading branch information
jfcherng committed Jun 13, 2024
1 parent 23dfb5b commit 019d0e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
3 changes: 3 additions & 0 deletions boot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


def reload_plugin() -> None:
import sys

Expand Down
18 changes: 2 additions & 16 deletions plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Pattern, cast, overload

import sublime
from more_itertools import first_true

from .constants import VIEW_SETTING_TIMESTAMP_KEY
from .types import RegionLike, T_AnyCallable
Expand Down Expand Up @@ -115,10 +116,7 @@ def view_find_all(
"""

def expand(region: sublime.Region) -> sublime.Region:
return next(
filter(None, (view.expand_to_scope(region.a, selector) for selector in expand_selectors)),
region,
)
return first_true((view.expand_to_scope(region.a, selector) for selector in expand_selectors), region) # type: ignore

if isinstance(expand_selectors, str):
expand_selectors = (expand_selectors,)
Expand All @@ -129,12 +127,8 @@ def expand(region: sublime.Region) -> sublime.Region:

@overload
def view_last_typing_timestamp_val(view: sublime.View) -> float: ...


@overload
def view_last_typing_timestamp_val(view: sublime.View, timestamp_s: float) -> None: ...


def view_last_typing_timestamp_val(view: sublime.View, timestamp_s: float | None = None) -> float | None:
"""
@brief Set/Get the last timestamp (in sec) when "OUIB_uri_regions" is updated
Expand Down Expand Up @@ -177,12 +171,8 @@ def view_is_dirty_val(view: sublime.View, is_dirty: bool | None = None) -> bool

@overload
def region_shift(region: sublime.Region, shift: int) -> sublime.Region: ...


@overload
def region_shift(region: int | list[int] | tuple[int, int], shift: int) -> tuple[int, int]: ...


def region_shift(region: RegionLike, shift: int) -> tuple[int, int] | sublime.Region:
"""
@brief Shift the region by given amount.
Expand All @@ -206,15 +196,11 @@ def region_expand(
region: sublime.Region,
expansion: int | list[int] | tuple[int, int],
) -> sublime.Region: ...


@overload
def region_expand(
region: int | list[int] | tuple[int, int],
expansion: int | list[int] | tuple[int, int],
) -> tuple[int, int]: ...


def region_expand(
region: RegionLike,
expansion: int | list[int] | tuple[int, int],
Expand Down

0 comments on commit 019d0e2

Please sign in to comment.