diff --git a/pygls/server.py b/pygls/server.py index 66e4bca0..06b500c9 100644 --- a/pygls/server.py +++ b/pygls/server.py @@ -21,7 +21,7 @@ from concurrent.futures import Future, ThreadPoolExecutor from multiprocessing.pool import ThreadPool from threading import Event -from typing import Callable, Dict, List +from typing import Callable, Dict, List, TypeVar from pygls.types import (ApplyWorkspaceEditResponse, ConfigCallbackType, Diagnostic, MessageType, RegistrationParams, TextDocumentSyncKind, UnregistrationParams, @@ -34,6 +34,8 @@ logger = logging.getLogger(__name__) +F = TypeVar('F', bound=Callable) + async def aio_readline(loop, executor, stop_event, rfile, proxy): """Reads data from stdin in separate thread (asynchronously).""" @@ -234,7 +236,7 @@ def apply_edit(self, edit: WorkspaceEdit, label: str = None) -> ApplyWorkspaceEd """Sends apply edit request to the client.""" return self.lsp.apply_edit(edit, label) - def command(self, command_name: str) -> Callable: + def command(self, command_name: str) -> Callable[[F], F]: """Decorator used to register custom commands. Example: @@ -244,7 +246,7 @@ def my_cmd(ls, a, b, c): """ return self.lsp.fm.command(command_name) - def feature(self, feature_name: str, **options: Dict) -> Callable: + def feature(self, feature_name: str, **options: Dict) -> Callable[[F], F]: """Decorator used to register LSP features. Example: