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 <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-03-09 09:59:02 +00:00 committed by GitHub
commit 0dbd8ff59b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -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<R>(id: RequestId, result: Result<R::Result>) -> Task
let response = match result {
Ok(resp) => Response::new_ok(id, &resp),
Err(e) => match e.downcast::<LspError>() {
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(

View File

@ -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};
@ -251,8 +250,9 @@ pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
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(),
}
})?;