From 43bc03faf04fe195ea3debb0c464698d3b146ee0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 Mar 2020 10:54:14 +0100 Subject: Silence "file out of workspace" errors 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. --- crates/rust-analyzer/src/main_loop.rs | 11 ++++++++++- 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 { } impl LspError { + pub const UNKNOWN_FILE: i32 = -32900; + pub fn new(code: i32, message: String) -> LspError { LspError { code, message } } @@ -805,7 +807,14 @@ where 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 96efab844..dce243ede 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -9,7 +9,6 @@ use std::{ }; 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 @@ impl WorldSnapshot { 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(), } })?; -- cgit v1.2.3