Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use invalid request handler rather than raising key error for requests after shutdown #432

Merged
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: 18 additions & 0 deletions pylsp/lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,21 @@ class TextDocumentSyncKind:
class NotebookCellKind:
Markup = 1
Code = 2


# https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#errorCodes
class ErrorCodes:
ParseError = -32700
InvalidRequest = -32600
MethodNotFound = -32601
InvalidParams = -32602
InternalError = -32603
jsonrpcReservedErrorRangeStart = -32099
ServerNotInitialized = -32002
UnknownErrorCode = -32001
jsonrpcReservedErrorRangeEnd = -32000
lspReservedErrorRangeStart = -32899
ServerCancelled = -32802
ContentModified = -32801
RequestCancelled = -32800
lspReservedErrorRangeEnd = -32800
10 changes: 9 additions & 1 deletion pylsp/python_lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def __getitem__(self, item):
if self._shutdown and item != "exit":
# exit is the only allowed method during shutdown
log.debug("Ignoring non-exit method during shutdown: %s", item)
raise KeyError
item = "invalid_request_after_shutdown"

try:
return super().__getitem__(item)
Expand All @@ -234,6 +234,14 @@ def m_shutdown(self, **_kwargs):
workspace.close()
self._shutdown = True

def m_invalid_request_after_shutdown(self, **_kwargs):
return {
"error": {
"code": lsp.ErrorCodes.InvalidRequest,
"message": "Requests after shutdown are not valid",
}
}

def m_exit(self, **_kwargs):
self._endpoint.shutdown()
if self._jsonrpc_stream_reader is not None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies = [
"importlib_metadata>=4.8.3;python_version<\"3.10\"",
"jedi>=0.17.2,<0.20.0",
"pluggy>=1.0.0",
"python-lsp-jsonrpc>=1.0.0",
"python-lsp-jsonrpc>=1.1.0,<2.0.0",
"ujson>=3.0.0",
]
dynamic = ["version"]
Expand Down