Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 12 additions & 6 deletions LSP.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,18 @@
// // file on disk.
// "schemes": ["file", "buffer", "res"],
//
// // When you want to connect to the language server via TCP (on
// // localhost), specify the port here. If you put a value of 0 here,
// // then LSP will select a free port number on localhost. In that case,
// // you can use the string templates $port or ${port} in the "command".
// // The syntax "{port}" is also allowed, but deprecated in favor of
// // $port and ${port}.
// // When set to a positive number bigger than 0, specifies the TCP port to
// // use to connect to the language server process listening on the given
// // port. When set to zero, a free TCP port is chosen. Chosen TCP port
// // number can be accessed through a template variable, i.e. as `${port}`
// // in the "command"`.
// //
// // Set to a negative number to make the LSP client act as TCP server
// // awaiting connection from the LSP server. Using `-1` opens a random port.
// // To use a fixed port number, use `-X` as the value for `tcp_port`, where
// // `X` is the desired (positive) port number.
// //
// // If not specified, STDIO is used as the transport.
// "tcp_port": 1234,
//
// // Sent to server once using workspace/didChangeConfiguration
Expand Down
34 changes: 17 additions & 17 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
from .protocol import ResponseError
from .settings import globalprefs
from .settings import userprefs
from .transports import Transport
from .transports import TransportCallbacks
from .transports import TransportWrapper
from .types import Capabilities
from .types import ClientConfig
from .types import ClientStates
Expand Down Expand Up @@ -958,15 +958,15 @@ def check_applicable(self, sb: SessionBufferProtocol, *, suppress_requests: bool
_PARTIAL_RESULT_PROGRESS_PREFIX = "$ublime-partial-result-progress-"


class Session(APIHandler, TransportCallbacks['dict[str, Any]']):
class Session(APIHandler, TransportCallbacks):

def __init__(self, manager: Manager, logger: Logger, workspace_folders: list[WorkspaceFolder],
config: ClientConfig, plugin_class: type[AbstractPlugin] | None) -> None:
self.transport: Transport | None = None
self.transport: TransportWrapper | None = None
self.working_directory: str | None = None
self.request_id = 0 # Our request IDs are always integers.
self._logger = logger
self._response_handlers: dict[int, tuple[Request[Any, Any], Callable[[Any], None], Callable[[ResponseError], None]]] = {} # noqa: E501
self._response_handlers: dict[str | int, tuple[Request[Any, Any], Callable[[Any], None], Callable[[ResponseError], None]]] = {} # noqa: E501
self.config = config
self.config_status_message = ''
self.manager = weakref.ref(manager)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ def initialize_async(
self,
variables: dict[str, str],
working_directory: str | None,
transport: Transport,
transport: TransportWrapper,
init_callback: InitCallback
) -> None:
self.transport = transport
Expand Down Expand Up @@ -2046,7 +2046,8 @@ def on_progress(self, params: ProgressParams) -> None:
# call window/workDoneProgress/create before hand. In that case, we check the 'kind' field of the
# progress data. If the 'kind' field is 'begin', we set up a progress reporter anyway.
try:
request_id = int(token[len(_WORK_DONE_PROGRESS_PREFIX):]) # type: ignore
token = str(token)
request_id = int(token[len(_WORK_DONE_PROGRESS_PREFIX):])
request = self._response_handlers[request_id][0]
self._invoke_views(request, "on_request_progress", request_id, params)
return
Expand Down Expand Up @@ -2196,21 +2197,20 @@ def send_error_response(self, request_id: int | str, error: Error) -> None:

def exit(self) -> None:
self.send_notification(Notification.exit())
try:
self.transport.close() # type: ignore
except AttributeError:
pass
if self.transport:
self.transport.close()
self.transport = None

def send_payload(self, payload: JSONRPCMessage) -> None:
try:
self.transport.send(payload) # type: ignore
self.transport.send(payload) # pyright: ignore[reportOptionalMemberAccess]
except AttributeError:
pass

def deduce_payload(
self,
payload: dict[str, Any]
) -> tuple[Callable | None, Any, int | None, str | None, str | None]:
payload: JSONRPCMessage
) -> tuple[Callable | None, Any, str | int | None, str | None, str | None]:
if "method" in payload:
method = payload["method"]
handler = self._get_handler(method)
Expand All @@ -2230,7 +2230,7 @@ def deduce_payload(
return res
elif "id" in payload:
response_id = payload["id"]
if response_id is None:
if response_id is None: # pyright: ignore[reportUnnecessaryComparison]
self._logger.incoming_response('<missing>', payload.get("error"), True)
return (None, None, None, None, None)
handler, method, result, is_error = self.response_handler(response_id, payload)
Expand All @@ -2240,10 +2240,10 @@ def deduce_payload(
self._plugin.on_server_response_async(method, response) # type: ignore
return handler, response.result, None, None, None
else:
debug("Unknown payload type: ", payload)
debug("Unknown payload type: ", payload) # pyright: ignore[reportUnreachable]
return (None, None, None, None, None)

def on_payload(self, payload: dict[str, Any]) -> None:
def on_payload(self, payload: JSONRPCMessage) -> None:
handler, result, req_id, typestr, _method = self.deduce_payload(payload)
if handler:
result_promise: Promise[Response[Any]] | None = None
Expand All @@ -2268,7 +2268,7 @@ def on_payload(self, payload: dict[str, Any]) -> None:
result_promise.then(self.send_response)

def response_handler(
self, response_id: int, response: dict[str, Any]
self, response_id: str | int, response: JSONRPCMessage
) -> tuple[Callable[[ResponseError], None], str | None, Any, bool]:
matching_handler = self._response_handlers.pop(response_id)
if not matching_handler:
Expand Down
Loading