aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-10-30 18:38:29 +0000
committerAleksey Kladov <[email protected]>2020-10-30 18:57:52 +0000
commit3b9548e163ed64d21d56873a4ba3583bf2f44535 (patch)
tree4de2b573a2e0b4f02e6edc788737d40199a7a204 /crates/rust-analyzer/src/main_loop.rs
parente7c8c600b783bbf12deb952a2e10be23264de953 (diff)
Respond with JSON-RPC error if we failed to deserialize request
Historically, we intentinally violated JSON-RPC spec here by hard crashing. The idea was to poke both the clients and servers to fix stuff. However, this is confusing for server implementors, and falls down in one important place -- protocol extension are not always backwards compatible, which causes crashes simply due to version mismatch. We had once such case with our own extension, and one for semantic tokens. So let's be less adventerous and just err on the err side!
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs70
1 files changed, 33 insertions, 37 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index ff855fe1a..53f8ca194 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -403,53 +403,49 @@ impl GlobalState {
403 handlers::handle_matching_brace(s.snapshot(), p) 403 handlers::handle_matching_brace(s.snapshot(), p)
404 })? 404 })?
405 .on_sync::<lsp_ext::MemoryUsage>(|s, p| handlers::handle_memory_usage(s, p))? 405 .on_sync::<lsp_ext::MemoryUsage>(|s, p| handlers::handle_memory_usage(s, p))?
406 .on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)? 406 .on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)
407 .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)? 407 .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
408 .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)? 408 .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)
409 .on::<lsp_ext::ParentModule>(handlers::handle_parent_module)? 409 .on::<lsp_ext::ParentModule>(handlers::handle_parent_module)
410 .on::<lsp_ext::Runnables>(handlers::handle_runnables)? 410 .on::<lsp_ext::Runnables>(handlers::handle_runnables)
411 .on::<lsp_ext::InlayHints>(handlers::handle_inlay_hints)? 411 .on::<lsp_ext::InlayHints>(handlers::handle_inlay_hints)
412 .on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)? 412 .on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)
413 .on::<lsp_ext::ResolveCodeActionRequest>(handlers::handle_resolve_code_action)? 413 .on::<lsp_ext::ResolveCodeActionRequest>(handlers::handle_resolve_code_action)
414 .on::<lsp_ext::HoverRequest>(handlers::handle_hover)? 414 .on::<lsp_ext::HoverRequest>(handlers::handle_hover)
415 .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs)? 415 .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs)
416 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)? 416 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)
417 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)? 417 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)
418 .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)? 418 .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)
419 .on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition)? 419 .on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition)
420 .on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)? 420 .on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)
421 .on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)? 421 .on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)
422 .on::<lsp_types::request::Completion>(handlers::handle_completion)? 422 .on::<lsp_types::request::Completion>(handlers::handle_completion)
423 .on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)? 423 .on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)
424 .on::<lsp_types::request::CodeLensResolve>(handlers::handle_code_lens_resolve)? 424 .on::<lsp_types::request::CodeLensResolve>(handlers::handle_code_lens_resolve)
425 .on::<lsp_types::request::FoldingRangeRequest>(handlers::handle_folding_range)? 425 .on::<lsp_types::request::FoldingRangeRequest>(handlers::handle_folding_range)
426 .on::<lsp_types::request::SignatureHelpRequest>(handlers::handle_signature_help)? 426 .on::<lsp_types::request::SignatureHelpRequest>(handlers::handle_signature_help)
427 .on::<lsp_types::request::PrepareRenameRequest>(handlers::handle_prepare_rename)? 427 .on::<lsp_types::request::PrepareRenameRequest>(handlers::handle_prepare_rename)
428 .on::<lsp_types::request::Rename>(handlers::handle_rename)? 428 .on::<lsp_types::request::Rename>(handlers::handle_rename)
429 .on::<lsp_types::request::References>(handlers::handle_references)? 429 .on::<lsp_types::request::References>(handlers::handle_references)
430 .on::<lsp_types::request::Formatting>(handlers::handle_formatting)? 430 .on::<lsp_types::request::Formatting>(handlers::handle_formatting)
431 .on::<lsp_types::request::DocumentHighlightRequest>( 431 .on::<lsp_types::request::DocumentHighlightRequest>(handlers::handle_document_highlight)
432 handlers::handle_document_highlight, 432 .on::<lsp_types::request::CallHierarchyPrepare>(handlers::handle_call_hierarchy_prepare)
433 )?
434 .on::<lsp_types::request::CallHierarchyPrepare>(
435 handlers::handle_call_hierarchy_prepare,
436 )?
437 .on::<lsp_types::request::CallHierarchyIncomingCalls>( 433 .on::<lsp_types::request::CallHierarchyIncomingCalls>(
438 handlers::handle_call_hierarchy_incoming, 434 handlers::handle_call_hierarchy_incoming,
439 )? 435 )
440 .on::<lsp_types::request::CallHierarchyOutgoingCalls>( 436 .on::<lsp_types::request::CallHierarchyOutgoingCalls>(
441 handlers::handle_call_hierarchy_outgoing, 437 handlers::handle_call_hierarchy_outgoing,
442 )? 438 )
443 .on::<lsp_types::request::SemanticTokensFullRequest>( 439 .on::<lsp_types::request::SemanticTokensFullRequest>(
444 handlers::handle_semantic_tokens_full, 440 handlers::handle_semantic_tokens_full,
445 )? 441 )
446 .on::<lsp_types::request::SemanticTokensFullDeltaRequest>( 442 .on::<lsp_types::request::SemanticTokensFullDeltaRequest>(
447 handlers::handle_semantic_tokens_full_delta, 443 handlers::handle_semantic_tokens_full_delta,
448 )? 444 )
449 .on::<lsp_types::request::SemanticTokensRangeRequest>( 445 .on::<lsp_types::request::SemanticTokensRangeRequest>(
450 handlers::handle_semantic_tokens_range, 446 handlers::handle_semantic_tokens_range,
451 )? 447 )
452 .on::<lsp_ext::Ssr>(handlers::handle_ssr)? 448 .on::<lsp_ext::Ssr>(handlers::handle_ssr)
453 .finish(); 449 .finish();
454 Ok(()) 450 Ok(())
455 } 451 }