aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-04-06 18:20:33 +0100
committerEdwin Cheng <[email protected]>2019-04-06 18:20:33 +0100
commit333feb3869da455d81029bb22076ae9f967d357f (patch)
tree8424d5b67b1eb03bfcb22524cf71d53671ca90aa
parent0372eca5b2e6dade5132a08db46992ca73a25188 (diff)
Add warning when open file outside workspace
-rw-r--r--crates/ra_lsp_server/src/server_world.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index af4798494..2f5088fd5 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -12,11 +12,13 @@ use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
12use relative_path::RelativePathBuf; 12use relative_path::RelativePathBuf;
13use parking_lot::RwLock; 13use parking_lot::RwLock;
14use failure::format_err; 14use failure::format_err;
15use gen_lsp_server::ErrorCode;
15 16
16use crate::{ 17use crate::{
17 project_model::ProjectWorkspace, 18 project_model::ProjectWorkspace,
18 vfs_filter::IncludeRustFiles, 19 vfs_filter::IncludeRustFiles,
19 Result, 20 Result,
21 LspError,
20}; 22};
21 23
22#[derive(Debug)] 24#[derive(Debug)]
@@ -152,11 +154,19 @@ impl ServerWorld {
152 154
153 pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> { 155 pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
154 let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; 156 let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?;
155 let file = self 157 let file = self.vfs.read().path2file(&path).ok_or_else(|| {
156 .vfs 158 // Check whether give path is exists,
157 .read() 159 // if so, maybe this file is outside out current workspace
158 .path2file(&path) 160 if path.exists() {
159 .ok_or_else(|| format_err!("unknown file: {}", path.display()))?; 161 LspError {
162 code: ErrorCode::InvalidRequest as i32,
163 message: "Rust file outside current workspace is not supported yet.".to_string(),
164 }
165 .into()
166 } else {
167 format_err!("unknown file: {}", path.display())
168 }
169 })?;
160 Ok(FileId(file.0.into())) 170 Ok(FileId(file.0.into()))
161 } 171 }
162 172