|
1 | 1 | from __future__ import annotations |
| 2 | + |
2 | 3 | from ..api_wrapper_interface import ApiNotificationHandler |
3 | 4 | from ..api_wrapper_interface import ApiRequestHandler |
4 | 5 | from ..api_wrapper_interface import ApiWrapperInterface |
5 | 6 | from ..server_resource_interface import ServerStatus |
6 | 7 | from .api_decorator import register_decorated_handlers |
7 | 8 | from .interface import ClientHandlerInterface |
8 | | -from abc import ABCMeta |
| 9 | +from abc import ABC |
9 | 10 | from functools import partial |
10 | 11 | from LSP.plugin import AbstractPlugin |
11 | 12 | from LSP.plugin import ClientConfig |
|
16 | 17 | from LSP.plugin import Session |
17 | 18 | from LSP.plugin import unregister_plugin |
18 | 19 | from LSP.plugin import WorkspaceFolder |
19 | | -from LSP.plugin.core.rpc import method2attr |
| 20 | +from LSP.plugin.core.rpc import method2attr # pyright: ignore[reportPrivateLocalImportUsage] |
20 | 21 | from os import path |
21 | | -from typing import Any, Callable |
| 22 | +from typing import Any |
| 23 | +from typing import Callable |
| 24 | +from typing import TYPE_CHECKING |
22 | 25 | from typing_extensions import override |
23 | | -from weakref import WeakMethod, ref |
24 | | -import sublime |
| 26 | +from weakref import ref |
| 27 | +from weakref import WeakMethod |
| 28 | + |
| 29 | +if TYPE_CHECKING: |
| 30 | + import sublime |
25 | 31 |
|
26 | 32 | __all__ = ['ClientHandler'] |
27 | 33 |
|
28 | 34 |
|
29 | 35 | class ApiWrapper(ApiWrapperInterface): |
30 | | - def __init__(self, plugin: 'ref[AbstractPlugin]'): |
| 36 | + def __init__(self, plugin: ref[AbstractPlugin]) -> None: |
31 | 37 | self.__plugin = plugin |
32 | 38 |
|
33 | 39 | def __session(self) -> Session | None: |
@@ -72,15 +78,13 @@ def send_request(self, method: str, params: Any, handler: Callable[[Any, bool], |
72 | 78 | session = self.__session() |
73 | 79 | if session: |
74 | 80 | request: Request[Any, Any] = Request(method, params) |
75 | | - session.send_request(request, lambda result: handler(result, False), lambda result: handler(result, True)) |
| 81 | + session.send_request(request, lambda result: handler(result, False), lambda result: handler(result, True)) # noqa: FBT003 |
76 | 82 | else: |
77 | | - handler(None, True) |
| 83 | + handler(None, True) # noqa: FBT003 |
78 | 84 |
|
79 | 85 |
|
80 | | -class ClientHandler(AbstractPlugin, ClientHandlerInterface, metaclass=ABCMeta): |
81 | | - """ |
82 | | - The base class for creating an LSP plugin. |
83 | | - """ |
| 86 | +class ClientHandler(AbstractPlugin, ClientHandlerInterface, ABC): |
| 87 | + """The base class for creating an LSP plugin.""" |
84 | 88 |
|
85 | 89 | # --- AbstractPlugin handlers ------------------------------------------------------------------------------------- |
86 | 90 |
|
@@ -121,9 +125,9 @@ def can_start(cls, window: sublime.Window, initiating_view: sublime.View, |
121 | 125 | if cls.manages_server(): |
122 | 126 | server = cls.get_server() |
123 | 127 | if not server or server.get_status() == ServerStatus.ERROR: |
124 | | - return "{}: Error installing server dependencies.".format(cls.package_name) |
| 128 | + return f"{cls.package_name}: Error installing server dependencies." |
125 | 129 | if server.get_status() != ServerStatus.READY: |
126 | | - return "{}: Server installation in progress...".format(cls.package_name) |
| 130 | + return f"{cls.package_name}: Server installation in progress..." |
127 | 131 | message = cls.is_allowed_to_start(window, initiating_view, workspace_folders, configuration) |
128 | 132 | if message: |
129 | 133 | return message |
@@ -167,6 +171,6 @@ def cleanup(cls) -> None: |
167 | 171 |
|
168 | 172 | def __init__(self, *args: Any, **kwargs: Any) -> None: |
169 | 173 | super().__init__(*args, **kwargs) |
170 | | - api = ApiWrapper(ref(self)) # type: ignore |
| 174 | + api = ApiWrapper(ref(self)) |
171 | 175 | register_decorated_handlers(self, api) |
172 | 176 | self.on_ready(api) |
0 commit comments