Skip to content

Commit 0dbd8ff

Browse files
bors[bot]matklad
andauthored
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 <aleksey.kladov@gmail.com>
2 parents 57c27f9 + 43bc03f commit 0dbd8ff

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub struct LspError {
4444
}
4545

4646
impl LspError {
47+
pub const UNKNOWN_FILE: i32 = -32900;
48+
4749
pub fn new(code: i32, message: String) -> LspError {
4850
LspError { code, message }
4951
}
@@ -805,7 +807,14 @@ where
805807
let response = match result {
806808
Ok(resp) => Response::new_ok(id, &resp),
807809
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+
}
809818
Err(e) => {
810819
if is_canceled(&e) {
811820
Response::new_err(

crates/rust-analyzer/src/world.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{
99
};
1010

1111
use crossbeam_channel::{unbounded, Receiver};
12-
use lsp_server::ErrorCode;
1312
use lsp_types::Url;
1413
use parking_lot::RwLock;
1514
use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher};
@@ -251,8 +250,9 @@ impl WorldSnapshot {
251250
let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
252251
let file = self.vfs.read().path2file(&path).ok_or_else(|| {
253252
// Show warning as this file is outside current workspace
253+
// FIXME: just handle such files, and remove `LspError::UNKNOWN_FILE`.
254254
LspError {
255-
code: ErrorCode::InvalidRequest as i32,
255+
code: LspError::UNKNOWN_FILE,
256256
message: "Rust file outside current workspace is not supported yet.".to_string(),
257257
}
258258
})?;

0 commit comments

Comments
 (0)