Skip to content
Merged
Changes from all commits
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
114 changes: 114 additions & 0 deletions stubs/sublime_plugin.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import sublime
from typing import Optional, Union, List, Dict, Tuple


class CommandInputHandler():
def name(self) -> str: ...
def next_input(self, args: dict) -> Optional[CommandInputHandler]: ...
def placeholder(self) -> str: ...
def initial_text(self) -> str: ...
def preview(self, arg: dict) -> Union[str, sublime.Html]: ...
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be

def preview(self, arg: str)
def validate(self, arg: str)
def confirm(self, arg: str)

Also note that confirm can receive an event. Not sure how to handle this.
We could add def confirm_(self, arg: str, event: sublime.Event)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't verified this right now, but from the documentation, the arg received should be the value of a ListInputHandler's list item, which may be any serializable, meaning ListInputHandler must be a generic class.

TextInputHandler would then inherit CommandInputHandler[str].

This means that ListInputItem needs to be generic as well, but we don't have that at all currently since it's ST4 only.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I only tried on TextInputHandler.
What's the plan for Python 3.8 and ST4? Is there a specific branch I should look at?

def validate(self, arg: dict) -> bool: ...
def cancel(self) -> None: ...
def confirm(self, arg: dict) -> None: ...


class BackInputHandler(CommandInputHandler):
pass


class TextInputHandler(CommandInputHandler):
def description(self, text: str) -> str: ...


class ListInputHandler(CommandInputHandler):
def list_items(self) -> list: ...
def description(self, v: object, text: str) -> str: ...


class Command():
def is_enabled(self) -> bool: ...
def is_visible(self) -> bool: ...
def is_checked(self) -> bool: ...
def description(self) -> str: ...
def input(self, args: dict) -> Optional[CommandInputHandler]: ...
def input_description(self) -> str: ...


class ApplicationCommand(Command):
def run(self) -> None: ...


class WindowCommand(Command):
window: sublime.Window

def run(self) -> None: ...


class TextCommand(Command):
view: sublime.View

def run(self, edit: sublime.Edit) -> None: ...
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one is tricky. TextCommand can accepts more argument.
But subclassing run(self, edit: sublime.Edit, **args: Any) by run(self, edit: sublime.Edit, my_cmd_argument: str) isn't allowed anyway.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just having run: Callable[..., None] would be more inline of mypy philosophy of "no false positive"

def want_event(self) -> bool: ...


class EventListener():
def on_new(self, view: sublime.View) -> None: ...
def on_new_async(self, view: sublime.View) -> None: ...
def on_clone(self, view: sublime.View) -> None: ...
def on_clone_async(self, view: sublime.View) -> None: ...
def on_load(self, view: sublime.View) -> None: ...
def on_load_async(self, view: sublime.View) -> None: ...
def on_pre_close(self, view: sublime.View) -> None: ...
def on_close(self, view: sublime.View) -> None: ...
def on_pre_save(self, view: sublime.View) -> None: ...
def on_pre_save_async(self, view: sublime.View) -> None: ...
def on_post_save(self, view: sublime.View) -> None: ...
def on_post_save_async(self, view: sublime.View) -> None: ...
def on_modified(self, view: sublime.View) -> None: ...
def on_modified_async(self, view: sublime.View) -> None: ...
def on_selection_modified(self, view: sublime.View) -> None: ...
def on_selection_modified_async(self, view: sublime.View) -> None: ...
def on_activated(self, view: sublime.View) -> None: ...
def on_activated_async(self, view: sublime.View) -> None: ...
def on_deactivated(self, view: sublime.View) -> None: ...
def on_deactivated_async(self, view: sublime.View) -> None: ...
def on_hover(self, view: sublime.View, point: int, hover_zone: int) -> None: ...
def on_query_context(self, view: sublime.View, key: str, operator: int, operand: str, match_all: bool) -> Optional[None]: ...
def on_query_completions(self, view: sublime.View, prefix: str, locations: List[int]) -> Union[None, list, tuple]: ...
def on_text_command(self, view: sublime.View, command_name: str, args: dict) -> Tuple[str, dict]: ...
def on_post_text_command(self, view: sublime.View, command_name: str, args: dict) -> None: ...
def on_window_command(self, view: sublime.Window, command_name: str, args: dict) -> Tuple[str, dict]: ...
def on_post_window_command(self, view: sublime.Window, command_name: str, args: dict) -> None: ...


class ViewEventListener():
view: sublime.View

@classmethod
def is_applicable(cls, settings: sublime.Settings) -> bool: ...

@classmethod
def applies_to_primary_view_only(cls) -> bool: ...

def on_load(self) -> None: ...
def on_load_async(self) -> None: ...
def on_pre_close(self) -> None: ...
def on_close(self) -> None: ...
def on_pre_save(self) -> None: ...
def on_pre_save_async(self) -> None: ...
def on_post_save(self) -> None: ...
def on_post_save_async(self) -> None: ...
def on_modified(self) -> None: ...
def on_modified_async(self) -> None: ...
def on_selection_modified(self) -> None: ...
def on_selection_modified_async(self) -> None: ...
def on_activated_modified(self) -> None: ...
def on_activated_modified_async(self) -> None: ...
def on_deactivated_modified(self) -> None: ...
def on_deactivated_modified_async(self) -> None: ...
def on_hover(self, point: int, hover_zone: int) -> None: ...
def on_query_context(self, key: str, operator: int, operand: str, match_all: bool) -> Optional[None]: ...
def on_query_completions(self, prefix: str, locations: List[int]) -> Union[None, list, tuple]: ...
def on_text_command(self, command_name: str, args: dict) -> Tuple[str, dict]: ...
def on_post_text_command(self, command_name: str, args: dict) -> None: ...