Skip to content

Commit 0d86844

Browse files
authored
Use invalid request handler rather than raising key error for requests after shutdown (python-lsp#432)
1 parent e837c55 commit 0d86844

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

pylsp/lsp.py

+18
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,21 @@ class TextDocumentSyncKind:
9595
class NotebookCellKind:
9696
Markup = 1
9797
Code = 2
98+
99+
100+
# https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#errorCodes
101+
class ErrorCodes:
102+
ParseError = -32700
103+
InvalidRequest = -32600
104+
MethodNotFound = -32601
105+
InvalidParams = -32602
106+
InternalError = -32603
107+
jsonrpcReservedErrorRangeStart = -32099
108+
ServerNotInitialized = -32002
109+
UnknownErrorCode = -32001
110+
jsonrpcReservedErrorRangeEnd = -32000
111+
lspReservedErrorRangeStart = -32899
112+
ServerCancelled = -32802
113+
ContentModified = -32801
114+
RequestCancelled = -32800
115+
lspReservedErrorRangeEnd = -32800

pylsp/python_lsp.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def __getitem__(self, item):
215215
if self._shutdown and item != "exit":
216216
# exit is the only allowed method during shutdown
217217
log.debug("Ignoring non-exit method during shutdown: %s", item)
218-
raise KeyError
218+
item = "invalid_request_after_shutdown"
219219

220220
try:
221221
return super().__getitem__(item)
@@ -234,6 +234,14 @@ def m_shutdown(self, **_kwargs):
234234
workspace.close()
235235
self._shutdown = True
236236

237+
def m_invalid_request_after_shutdown(self, **_kwargs):
238+
return {
239+
"error": {
240+
"code": lsp.ErrorCodes.InvalidRequest,
241+
"message": "Requests after shutdown are not valid",
242+
}
243+
}
244+
237245
def m_exit(self, **_kwargs):
238246
self._endpoint.shutdown()
239247
if self._jsonrpc_stream_reader is not None:

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies = [
1717
"importlib_metadata>=4.8.3;python_version<\"3.10\"",
1818
"jedi>=0.17.2,<0.20.0",
1919
"pluggy>=1.0.0",
20-
"python-lsp-jsonrpc>=1.0.0",
20+
"python-lsp-jsonrpc>=1.1.0,<2.0.0",
2121
"ujson>=3.0.0",
2222
]
2323
dynamic = ["version"]

0 commit comments

Comments
 (0)