mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Add warning when open file outside workspace
This commit is contained in:
parent
0372eca5b2
commit
333feb3869
1 changed files with 15 additions and 5 deletions
|
@ -12,11 +12,13 @@ use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
|
||||||
use relative_path::RelativePathBuf;
|
use relative_path::RelativePathBuf;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use failure::format_err;
|
use failure::format_err;
|
||||||
|
use gen_lsp_server::ErrorCode;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
project_model::ProjectWorkspace,
|
project_model::ProjectWorkspace,
|
||||||
vfs_filter::IncludeRustFiles,
|
vfs_filter::IncludeRustFiles,
|
||||||
Result,
|
Result,
|
||||||
|
LspError,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -152,11 +154,19 @@ impl ServerWorld {
|
||||||
|
|
||||||
pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
|
pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
|
||||||
let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?;
|
let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?;
|
||||||
let file = self
|
let file = self.vfs.read().path2file(&path).ok_or_else(|| {
|
||||||
.vfs
|
// Check whether give path is exists,
|
||||||
.read()
|
// if so, maybe this file is outside out current workspace
|
||||||
.path2file(&path)
|
if path.exists() {
|
||||||
.ok_or_else(|| format_err!("unknown file: {}", path.display()))?;
|
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()))
|
Ok(FileId(file.0.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue