Skip to content

Commit

Permalink
LSP: Send replies for malformed and unhandled RPC requests (helix-edi…
Browse files Browse the repository at this point in the history
…tor#6058)

Previously we did not respond to malformed or unhandled LSP requests.
The JSONRPC spec says that all non-notification requests must have
responses:

> When a rpc call is made, the Server MUST reply with a Response,
> except for in the case of Notifications

(Note that Helix is the "Server" in this case. Also from the spec:
"The Server is defined as the origin of Response objects and the
handler of Request objects.")

So this change sends error replies for requests which can't be parsed
or handled. Request IDs are also now added to the log messages for
unhandled requests.
  • Loading branch information
the-mikedavis authored and Sagnik Bhattacharya committed Mar 21, 2023
1 parent 7c04d68 commit 4ffee15
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,24 +928,32 @@ impl Application {
Call::MethodCall(helix_lsp::jsonrpc::MethodCall {
method, params, id, ..
}) => {
let call = match MethodCall::parse(&method, params) {
Ok(call) => call,
let reply = match MethodCall::parse(&method, params) {
Err(helix_lsp::Error::Unhandled) => {
error!("Language Server: Method not found {}", method);
return;
error!(
"Language Server: Method {} not found in request {}",
method, id
);
Err(helix_lsp::jsonrpc::Error {
code: helix_lsp::jsonrpc::ErrorCode::MethodNotFound,
message: format!("Method not found: {}", method),
data: None,
})
}
Err(err) => {
log::error!(
"received malformed method call from Language Server: {}: {}",
"Language Server: Received malformed method call {} in request {}: {}",
method,
id,
err
);
return;
Err(helix_lsp::jsonrpc::Error {
code: helix_lsp::jsonrpc::ErrorCode::ParseError,
message: format!("Malformed method call: {}", method),
data: None,
})
}
};

let reply = match call {
MethodCall::WorkDoneProgressCreate(params) => {
Ok(MethodCall::WorkDoneProgressCreate(params)) => {
self.lsp_progress.create(server_id, params.token);

let editor_view = self
Expand All @@ -959,7 +967,7 @@ impl Application {

Ok(serde_json::Value::Null)
}
MethodCall::ApplyWorkspaceEdit(params) => {
Ok(MethodCall::ApplyWorkspaceEdit(params)) => {
apply_workspace_edit(
&mut self.editor,
helix_lsp::OffsetEncoding::Utf8,
Expand All @@ -972,13 +980,13 @@ impl Application {
failed_change: None,
}))
}
MethodCall::WorkspaceFolders => {
Ok(MethodCall::WorkspaceFolders) => {
let language_server =
self.editor.language_servers.get_by_id(server_id).unwrap();

Ok(json!(language_server.workspace_folders()))
}
MethodCall::WorkspaceConfiguration(params) => {
Ok(MethodCall::WorkspaceConfiguration(params)) => {
let result: Vec<_> = params
.items
.iter()
Expand Down

0 comments on commit 4ffee15

Please sign in to comment.