aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-29 22:46:54 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-29 22:46:54 +0000
commit748fbb5371b4ec1b2413dde057c3ae6e050481b7 (patch)
tree7faaff4e5e54baeeabd614e363c8f59ab33b66ae /crates
parent7fe32938b672d1fb9668b29061ac47b90f1ba599 (diff)
parent5dd602f90162cc3ec89751d76265c761b5aa2797 (diff)
Merge #360
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 <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_vfs/src/io.rs4
-rw-r--r--crates/ra_vfs/src/lib.rs16
2 files changed, 9 insertions, 11 deletions
diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs
index be400bae9..4cfdb83da 100644
--- a/crates/ra_vfs/src/io.rs
+++ b/crates/ra_vfs/src/io.rs
@@ -8,7 +8,7 @@ use walkdir::{DirEntry, WalkDir};
8use thread_worker::{WorkerHandle}; 8use thread_worker::{WorkerHandle};
9use relative_path::RelativePathBuf; 9use relative_path::RelativePathBuf;
10 10
11use crate::VfsRoot; 11use crate::{VfsRoot, has_rs_extension};
12 12
13pub(crate) struct Task { 13pub(crate) struct Task {
14 pub(crate) root: VfsRoot, 14 pub(crate) root: VfsRoot,
@@ -59,7 +59,7 @@ fn load_root(root: &Path, filter: &dyn Fn(&DirEntry) -> bool) -> Vec<(RelativePa
59 continue; 59 continue;
60 } 60 }
61 let path = entry.path(); 61 let path = entry.path();
62 if path.extension().and_then(|os| os.to_str()) != Some("rs") { 62 if !has_rs_extension(path) {
63 continue; 63 continue;
64 } 64 }
65 let text = match fs::read_to_string(path) { 65 let text = match fs::read_to_string(path) {
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs
index 4de07b093..90d5e21f4 100644
--- a/crates/ra_vfs/src/lib.rs
+++ b/crates/ra_vfs/src/lib.rs
@@ -2,11 +2,13 @@
2//! 2//!
3//! When doing analysis, we don't want to do any IO, we want to keep all source 3//! When doing analysis, we don't want to do any IO, we want to keep all source
4//! code in memory. However, the actual source code is stored on disk, so you 4//! code in memory. However, the actual source code is stored on disk, so you
5//! component which does this.
6//! need to get it into the memory in the first place somehow. VFS is the 5//! need to get it into the memory in the first place somehow. VFS is the
6//! component which does this.
7//! 7//!
8//! It also is responsible for watching the disk for changes, and for merging 8//! It is also responsible for watching the disk for changes, and for merging
9//! editor state (modified, unsaved files) with disk state. 9//! editor state (modified, unsaved files) with disk state.
10//! TODO: Some LSP clients support watching the disk, so this crate should
11//! to support custom watcher events (related to https://github.com/rust-analyzer/rust-analyzer/issues/131)
10//! 12//!
11//! VFS is based on a concept of roots: a set of directories on the file system 13//! VFS is based on a concept of roots: a set of directories on the file system
12//! whihc are watched for changes. Typically, there will be a root for each 14//! whihc are watched for changes. Typically, there will be a root for each
@@ -29,7 +31,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
29use relative_path::RelativePathBuf; 31use relative_path::RelativePathBuf;
30use crossbeam_channel::Receiver; 32use crossbeam_channel::Receiver;
31use walkdir::DirEntry; 33use walkdir::DirEntry;
32use thread_worker::{WorkerHandle}; 34use thread_worker::WorkerHandle;
33 35
34use crate::{ 36use crate::{
35 arena::{ArenaId, Arena}, 37 arena::{ArenaId, Arena},
@@ -57,12 +59,8 @@ impl RootFilter {
57 if !(self.file_filter)(path) { 59 if !(self.file_filter)(path) {
58 return None; 60 return None;
59 } 61 }
60 if !(path.starts_with(&self.root)) { 62 let path = path.strip_prefix(&self.root).ok()?;
61 return None; 63 RelativePathBuf::from_path(path).ok()
62 }
63 let path = path.strip_prefix(&self.root).unwrap();
64 let path = RelativePathBuf::from_path(path).unwrap();
65 Some(path)
66 } 64 }
67} 65}
68 66