diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 5480b9e4d41..221f464b65b 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -44,6 +44,8 @@ pub struct LspError { } impl LspError { + pub const UNKNOWN_FILE: i32 = -32900; + pub fn new(code: i32, message: String) -> LspError { LspError { code, message } } @@ -805,7 +807,14 @@ fn result_to_task(id: RequestId, result: Result) -> Task let response = match result { Ok(resp) => Response::new_ok(id, &resp), Err(e) => match e.downcast::() { - Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message), + Ok(lsp_error) => { + if lsp_error.code == LspError::UNKNOWN_FILE { + // Work-around for https://github.com/rust-analyzer/rust-analyzer/issues/1521 + Response::new_ok(id, ()) + } else { + Response::new_err(id, lsp_error.code, lsp_error.message) + } + } Err(e) => { if is_canceled(&e) { Response::new_err( diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 96efab844d5..dce243ede55 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -9,7 +9,6 @@ }; use crossbeam_channel::{unbounded, Receiver}; -use lsp_server::ErrorCode; use lsp_types::Url; use parking_lot::RwLock; use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher}; @@ -252,8 +251,9 @@ pub fn uri_to_file_id(&self, uri: &Url) -> Result { let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; let file = self.vfs.read().path2file(&path).ok_or_else(|| { // Show warning as this file is outside current workspace + // FIXME: just handle such files, and remove `LspError::UNKNOWN_FILE`. LspError { - code: ErrorCode::InvalidRequest as i32, + code: LspError::UNKNOWN_FILE, message: "Rust file outside current workspace is not supported yet.".to_string(), } })?;