diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 5 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/mod.rs | 18 |
4 files changed, 24 insertions, 4 deletions
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 2b3257117..e4fc40a3a 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -8,6 +8,7 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
8 | rayon = "1.0.2" | 8 | rayon = "1.0.2" |
9 | relative-path = "0.3.7" | 9 | relative-path = "0.3.7" |
10 | failure = "0.1.2" | 10 | failure = "0.1.2" |
11 | failure_derive = "0.1.2" | ||
11 | serde_json = "1.0.24" | 12 | serde_json = "1.0.24" |
12 | serde = "1.0.71" | 13 | serde = "1.0.71" |
13 | serde_derive = "1.0.71" | 14 | serde_derive = "1.0.71" |
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index f1b17f282..ce77b2a33 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -12,6 +12,8 @@ extern crate rayon; | |||
12 | extern crate log; | 12 | extern crate log; |
13 | extern crate cargo_metadata; | 13 | extern crate cargo_metadata; |
14 | extern crate drop_bomb; | 14 | extern crate drop_bomb; |
15 | #[macro_use] | ||
16 | extern crate failure_derive; | ||
15 | extern crate im; | 17 | extern crate im; |
16 | extern crate relative_path; | 18 | extern crate relative_path; |
17 | extern crate rustc_hash; | 19 | extern crate rustc_hash; |
@@ -34,4 +36,4 @@ pub mod thread_watcher; | |||
34 | mod vfs; | 36 | mod vfs; |
35 | 37 | ||
36 | pub type Result<T> = ::std::result::Result<T, ::failure::Error>; | 38 | pub type Result<T> = ::std::result::Result<T, ::failure::Error>; |
37 | pub use crate::{caps::server_capabilities, main_loop::main_loop}; | 39 | pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError}; \ No newline at end of file |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 11f34eb93..b27b5d007 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -7,6 +7,7 @@ use languageserver_types::{ | |||
7 | InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit, | 7 | InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit, |
8 | RenameParams, WorkspaceEdit, PrepareRenameResponse | 8 | RenameParams, WorkspaceEdit, PrepareRenameResponse |
9 | }; | 9 | }; |
10 | use gen_lsp_server::ErrorCode; | ||
10 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind}; | 11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind}; |
11 | use ra_syntax::text_utils::contains_offset_nonstrict; | 12 | use ra_syntax::text_utils::contains_offset_nonstrict; |
12 | use serde_json::to_value; | 13 | use serde_json::to_value; |
@@ -16,7 +17,7 @@ use crate::{ | |||
16 | project_model::TargetKind, | 17 | project_model::TargetKind, |
17 | req::{self, Decoration}, | 18 | req::{self, Decoration}, |
18 | server_world::ServerWorld, | 19 | server_world::ServerWorld, |
19 | Result, | 20 | Result, LspError |
20 | }; | 21 | }; |
21 | 22 | ||
22 | pub fn handle_syntax_tree( | 23 | pub fn handle_syntax_tree( |
@@ -476,7 +477,7 @@ pub fn handle_rename( | |||
476 | let offset = params.position.conv_with(&line_index); | 477 | let offset = params.position.conv_with(&line_index); |
477 | 478 | ||
478 | if params.new_name.is_empty() { | 479 | if params.new_name.is_empty() { |
479 | return Ok(None); | 480 | return Err(LspError::new(ErrorCode::InvalidParams as i32, "New Name cannot be empty".into()).into()); |
480 | } | 481 | } |
481 | 482 | ||
482 | let refs = world.analysis().find_all_refs(file_id, offset)?; | 483 | let refs = world.analysis().find_all_refs(file_id, offset)?; |
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 69dcc7e57..e681062ca 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::{ | |||
23 | Result, | 23 | Result, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | #[derive(Debug, Fail)] | ||
27 | #[fail(display = "Language Server request failed with {}. ({})", code, message)] | ||
28 | pub struct LspError { | ||
29 | pub code: i32, | ||
30 | pub message: String, | ||
31 | } | ||
32 | |||
33 | impl LspError { | ||
34 | pub fn new(code: i32, message: String) -> LspError { | ||
35 | LspError {code, message} | ||
36 | } | ||
37 | } | ||
38 | |||
26 | #[derive(Debug)] | 39 | #[derive(Debug)] |
27 | enum Task { | 40 | enum Task { |
28 | Respond(RawResponse), | 41 | Respond(RawResponse), |
@@ -361,7 +374,10 @@ impl<'a> PoolDispatcher<'a> { | |||
361 | let resp = match f(world, params) { | 374 | let resp = match f(world, params) { |
362 | Ok(resp) => RawResponse::ok::<R>(id, &resp), | 375 | Ok(resp) => RawResponse::ok::<R>(id, &resp), |
363 | Err(e) => { | 376 | Err(e) => { |
364 | RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()) | 377 | match e.downcast::<LspError>() { |
378 | Ok(lsp_error) => RawResponse::err(id, lsp_error.code, lsp_error.message), | ||
379 | Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()) | ||
380 | } | ||
365 | } | 381 | } |
366 | }; | 382 | }; |
367 | let task = Task::Respond(resp); | 383 | let task = Task::Respond(resp); |