From 6453b29cb571d5c54bac427842ba8a9dd6874861 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 22 Oct 2018 13:49:27 -0400 Subject: Add LspError to explicity return errors from LSP handlers Fixes #145 --- crates/ra_lsp_server/src/main_loop/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server/src/main_loop/mod.rs') diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index b35ebd38b..aa3cf1dbd 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -23,6 +23,19 @@ use crate::{ Result, }; +#[derive(Debug, Fail)] +#[fail(display = "Language Server request failed with {}. ({})", code, message)] +pub struct LspError { + pub code: i32, + pub message: String, +} + +impl LspError { + pub fn new(code: i32, message: String) -> LspError { + LspError {code, message} + } +} + #[derive(Debug)] enum Task { Respond(RawResponse), @@ -361,7 +374,10 @@ impl<'a> PoolDispatcher<'a> { let resp = match f(world, params) { Ok(resp) => RawResponse::ok::(id, &resp), Err(e) => { - RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()) + match e.downcast::() { + Ok(lsp_error) => RawResponse::err(id, lsp_error.code, lsp_error.message), + Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()) + } } }; let task = Task::Respond(resp); -- cgit v1.2.3