diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-09 09:59:02 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-09 09:59:02 +0000 |
commit | 0dbd8ff59b854570329c325431126a078505e5f5 (patch) | |
tree | 966fd9fa6f720ad2b7569790cc047ddbbbdb0643 | |
parent | 57c27f91392fdd9d72fd023f4e2fecd8b68a7d09 (diff) | |
parent | 43bc03faf04fe195ea3debb0c464698d3b146ee0 (diff) |
Merge #3526
3526: Silence "file out of workspace" errors r=matklad a=matklad
We really should fix this limitation of the VFS, but it's some way off
at the moment, so let's just silence the user-visible error for now.
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 11 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 4 |
2 files changed, 12 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 5480b9e4d..221f464b6 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -44,6 +44,8 @@ pub struct LspError { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | impl LspError { | 46 | impl LspError { |
47 | pub const UNKNOWN_FILE: i32 = -32900; | ||
48 | |||
47 | pub fn new(code: i32, message: String) -> LspError { | 49 | pub fn new(code: i32, message: String) -> LspError { |
48 | LspError { code, message } | 50 | LspError { code, message } |
49 | } | 51 | } |
@@ -805,7 +807,14 @@ where | |||
805 | let response = match result { | 807 | let response = match result { |
806 | Ok(resp) => Response::new_ok(id, &resp), | 808 | Ok(resp) => Response::new_ok(id, &resp), |
807 | Err(e) => match e.downcast::<LspError>() { | 809 | Err(e) => match e.downcast::<LspError>() { |
808 | Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message), | 810 | Ok(lsp_error) => { |
811 | if lsp_error.code == LspError::UNKNOWN_FILE { | ||
812 | // Work-around for https://github.com/rust-analyzer/rust-analyzer/issues/1521 | ||
813 | Response::new_ok(id, ()) | ||
814 | } else { | ||
815 | Response::new_err(id, lsp_error.code, lsp_error.message) | ||
816 | } | ||
817 | } | ||
809 | Err(e) => { | 818 | Err(e) => { |
810 | if is_canceled(&e) { | 819 | if is_canceled(&e) { |
811 | Response::new_err( | 820 | Response::new_err( |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index c92cf137c..6f394055a 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -9,7 +9,6 @@ use std::{ | |||
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crossbeam_channel::{unbounded, Receiver}; | 11 | use crossbeam_channel::{unbounded, Receiver}; |
12 | use lsp_server::ErrorCode; | ||
13 | use lsp_types::Url; | 12 | use lsp_types::Url; |
14 | use parking_lot::RwLock; | 13 | use parking_lot::RwLock; |
15 | use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher}; | 14 | use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher}; |
@@ -251,8 +250,9 @@ impl WorldSnapshot { | |||
251 | let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; | 250 | let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; |
252 | let file = self.vfs.read().path2file(&path).ok_or_else(|| { | 251 | let file = self.vfs.read().path2file(&path).ok_or_else(|| { |
253 | // Show warning as this file is outside current workspace | 252 | // Show warning as this file is outside current workspace |
253 | // FIXME: just handle such files, and remove `LspError::UNKNOWN_FILE`. | ||
254 | LspError { | 254 | LspError { |
255 | code: ErrorCode::InvalidRequest as i32, | 255 | code: LspError::UNKNOWN_FILE, |
256 | message: "Rust file outside current workspace is not supported yet.".to_string(), | 256 | message: "Rust file outside current workspace is not supported yet.".to_string(), |
257 | } | 257 | } |
258 | })?; | 258 | })?; |