Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 not valid",
}
}

def m_exit(self, **_kwargs):
self._endpoint.shutdown()
if self._jsonrpc_stream_reader is not None:
Expand Down