From 333feb3869da455d81029bb22076ae9f967d357f Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 7 Apr 2019 01:20:33 +0800 Subject: Add warning when open file outside workspace --- crates/ra_lsp_server/src/server_world.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'crates/ra_lsp_server') 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}; use relative_path::RelativePathBuf; use parking_lot::RwLock; use failure::format_err; +use gen_lsp_server::ErrorCode; use crate::{ project_model::ProjectWorkspace, vfs_filter::IncludeRustFiles, Result, + LspError, }; #[derive(Debug)] @@ -152,11 +154,19 @@ impl ServerWorld { pub fn uri_to_file_id(&self, uri: &Url) -> Result { let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; - let file = self - .vfs - .read() - .path2file(&path) - .ok_or_else(|| format_err!("unknown file: {}", path.display()))?; + let file = self.vfs.read().path2file(&path).ok_or_else(|| { + // Check whether give path is exists, + // if so, maybe this file is outside out current workspace + if path.exists() { + LspError { + code: ErrorCode::InvalidRequest as i32, + message: "Rust file outside current workspace is not supported yet.".to_string(), + } + .into() + } else { + format_err!("unknown file: {}", path.display()) + } + })?; Ok(FileId(file.0.into())) } -- cgit v1.2.3 From e92740c28b10c4f947ae20ad881fd30f78d3f487 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 7 Apr 2019 12:46:45 +0800 Subject: fix formatting --- crates/ra_lsp_server/src/server_world.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 2f5088fd5..6fe0d39df 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -160,7 +160,8 @@ impl ServerWorld { if path.exists() { LspError { code: ErrorCode::InvalidRequest as i32, - message: "Rust file outside current workspace is not supported yet.".to_string(), + message: "Rust file outside current workspace is not supported yet." + .to_string(), } .into() } else { -- cgit v1.2.3 From ce3d78335d5db2643e05caf91041f9e92577ecc3 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 7 Apr 2019 18:26:02 +0800 Subject: Remove checking file exists --- crates/ra_lsp_server/src/server_world.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 6fe0d39df..4b1d592bb 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -11,7 +11,7 @@ use ra_ide_api::{ use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; use relative_path::RelativePathBuf; use parking_lot::RwLock; -use failure::format_err; +use failure::{Error, format_err}; use gen_lsp_server::ErrorCode; use crate::{ @@ -155,18 +155,11 @@ impl ServerWorld { pub fn uri_to_file_id(&self, uri: &Url) -> Result { let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; let file = self.vfs.read().path2file(&path).ok_or_else(|| { - // Check whether give path is exists, - // if so, maybe this file is outside out current workspace - if path.exists() { - LspError { - code: ErrorCode::InvalidRequest as i32, - message: "Rust file outside current workspace is not supported yet." - .to_string(), - } - .into() - } else { - format_err!("unknown file: {}", path.display()) - } + // Show warning as this file is outside current workspace + Error::from(LspError { + code: ErrorCode::InvalidRequest as i32, + message: "Rust file outside current workspace is not supported yet.".to_string(), + }) })?; Ok(FileId(file.0.into())) } -- cgit v1.2.3