Skip to content

Commit 36f5d99

Browse files
Merge #1119
1119: Add warning when open file outside workspace r=matklad a=edwin0cheng When file is not found in `ra_vfs` but exist, use `LspError` for warning instead of `error_fmt` to bail out error, Temporarily fix #967 . edit: typo Co-authored-by: Edwin Cheng <[email protected]>
2 parents 990e74b + ce3d783 commit 36f5d99

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/ra_lsp_server/src/server_world.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ use ra_ide_api::{
1111
use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
1212
use relative_path::RelativePathBuf;
1313
use parking_lot::RwLock;
14-
use failure::format_err;
14+
use failure::{Error, format_err};
15+
use gen_lsp_server::ErrorCode;
1516

1617
use crate::{
1718
project_model::ProjectWorkspace,
1819
vfs_filter::IncludeRustFiles,
1920
Result,
21+
LspError,
2022
};
2123

2224
#[derive(Debug)]
@@ -152,11 +154,13 @@ impl ServerWorld {
152154

153155
pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
154156
let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?;
155-
let file = self
156-
.vfs
157-
.read()
158-
.path2file(&path)
159-
.ok_or_else(|| format_err!("unknown file: {}", path.display()))?;
157+
let file = self.vfs.read().path2file(&path).ok_or_else(|| {
158+
// Show warning as this file is outside current workspace
159+
Error::from(LspError {
160+
code: ErrorCode::InvalidRequest as i32,
161+
message: "Rust file outside current workspace is not supported yet.".to_string(),
162+
})
163+
})?;
160164
Ok(FileId(file.0.into()))
161165
}
162166

0 commit comments

Comments
 (0)