360: Improve comments and code in ra_vfs r=DJMcNab a=DJMcNab

Some random code/comment improvements I saw whilst trying to understand `ra_vfs`.

Let's see if this works:
bors r+

Co-authored-by: DJMcNab <36049421+djmcnab@users.noreply.github.com>
This commit is contained in:
bors[bot] 2018-12-29 22:46:54 +00:00
commit 748fbb5371
2 changed files with 9 additions and 11 deletions

View File

@ -8,7 +8,7 @@ use walkdir::{DirEntry, WalkDir};
use thread_worker::{WorkerHandle}; use thread_worker::{WorkerHandle};
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use crate::VfsRoot; use crate::{VfsRoot, has_rs_extension};
pub(crate) struct Task { pub(crate) struct Task {
pub(crate) root: VfsRoot, pub(crate) root: VfsRoot,
@ -59,7 +59,7 @@ fn load_root(root: &Path, filter: &dyn Fn(&DirEntry) -> bool) -> Vec<(RelativePa
continue; continue;
} }
let path = entry.path(); let path = entry.path();
if path.extension().and_then(|os| os.to_str()) != Some("rs") { if !has_rs_extension(path) {
continue; continue;
} }
let text = match fs::read_to_string(path) { let text = match fs::read_to_string(path) {

View File

@ -2,11 +2,13 @@
//! //!
//! When doing analysis, we don't want to do any IO, we want to keep all source //! When doing analysis, we don't want to do any IO, we want to keep all source
//! code in memory. However, the actual source code is stored on disk, so you //! code in memory. However, the actual source code is stored on disk, so you
//! component which does this.
//! need to get it into the memory in the first place somehow. VFS is the //! need to get it into the memory in the first place somehow. VFS is the
//! component which does this.
//! //!
//! It also is responsible for watching the disk for changes, and for merging //! It is also responsible for watching the disk for changes, and for merging
//! editor state (modified, unsaved files) with disk state. //! editor state (modified, unsaved files) with disk state.
//! TODO: Some LSP clients support watching the disk, so this crate should
//! to support custom watcher events (related to https://github.com/rust-analyzer/rust-analyzer/issues/131)
//! //!
//! VFS is based on a concept of roots: a set of directories on the file system //! VFS is based on a concept of roots: a set of directories on the file system
//! whihc are watched for changes. Typically, there will be a root for each //! whihc are watched for changes. Typically, there will be a root for each
@ -29,7 +31,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use crossbeam_channel::Receiver; use crossbeam_channel::Receiver;
use walkdir::DirEntry; use walkdir::DirEntry;
use thread_worker::{WorkerHandle}; use thread_worker::WorkerHandle;
use crate::{ use crate::{
arena::{ArenaId, Arena}, arena::{ArenaId, Arena},
@ -57,12 +59,8 @@ impl RootFilter {
if !(self.file_filter)(path) { if !(self.file_filter)(path) {
return None; return None;
} }
if !(path.starts_with(&self.root)) { let path = path.strip_prefix(&self.root).ok()?;
return None; RelativePathBuf::from_path(path).ok()
}
let path = path.strip_prefix(&self.root).unwrap();
let path = RelativePathBuf::from_path(path).unwrap();
Some(path)
} }
} }