aboutsummaryrefslogtreecommitdiff
path: root/crates/vfs/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/vfs/src')
-rw-r--r--crates/vfs/src/file_set.rs2
-rw-r--r--crates/vfs/src/loader.rs12
-rw-r--r--crates/vfs/src/vfs_path.rs35
3 files changed, 33 insertions, 16 deletions
diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs
index 0173f7464..d0ddeafe7 100644
--- a/crates/vfs/src/file_set.rs
+++ b/crates/vfs/src/file_set.rs
@@ -18,7 +18,7 @@ impl FileSet {
18 pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { 18 pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
19 let mut base = self.paths[&anchor].clone(); 19 let mut base = self.paths[&anchor].clone();
20 base.pop(); 20 base.pop();
21 let path = base.join(path); 21 let path = base.join(path)?;
22 let res = self.files.get(&path).copied(); 22 let res = self.files.get(&path).copied();
23 res 23 res
24 } 24 }
diff --git a/crates/vfs/src/loader.rs b/crates/vfs/src/loader.rs
index a216b5f13..6de2e5b3f 100644
--- a/crates/vfs/src/loader.rs
+++ b/crates/vfs/src/loader.rs
@@ -1,7 +1,7 @@
1//! Object safe interface for file watching and reading. 1//! Object safe interface for file watching and reading.
2use std::fmt; 2use std::fmt;
3 3
4use paths::AbsPathBuf; 4use paths::{AbsPath, AbsPathBuf};
5 5
6#[derive(Debug)] 6#[derive(Debug)]
7pub enum Entry { 7pub enum Entry {
@@ -16,7 +16,7 @@ pub struct Config {
16} 16}
17 17
18pub enum Message { 18pub enum Message {
19 Progress { n_entries_total: usize, n_entries_done: usize }, 19 Progress { n_total: usize, n_done: usize },
20 Loaded { files: Vec<(AbsPathBuf, Option<Vec<u8>>)> }, 20 Loaded { files: Vec<(AbsPathBuf, Option<Vec<u8>>)> },
21} 21}
22 22
@@ -28,7 +28,7 @@ pub trait Handle: fmt::Debug {
28 Self: Sized; 28 Self: Sized;
29 fn set_config(&mut self, config: Config); 29 fn set_config(&mut self, config: Config);
30 fn invalidate(&mut self, path: AbsPathBuf); 30 fn invalidate(&mut self, path: AbsPathBuf);
31 fn load_sync(&mut self, path: &AbsPathBuf) -> Option<Vec<u8>>; 31 fn load_sync(&mut self, path: &AbsPath) -> Option<Vec<u8>>;
32} 32}
33 33
34impl Entry { 34impl Entry {
@@ -56,10 +56,10 @@ impl fmt::Debug for Message {
56 Message::Loaded { files } => { 56 Message::Loaded { files } => {
57 f.debug_struct("Loaded").field("n_files", &files.len()).finish() 57 f.debug_struct("Loaded").field("n_files", &files.len()).finish()
58 } 58 }
59 Message::Progress { n_entries_total, n_entries_done } => f 59 Message::Progress { n_total, n_done } => f
60 .debug_struct("Progress") 60 .debug_struct("Progress")
61 .field("n_entries_total", n_entries_total) 61 .field("n_total", n_total)
62 .field("n_entries_done", n_entries_done) 62 .field("n_done", n_done)
63 .finish(), 63 .finish(),
64 } 64 }
65 } 65 }
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs
index 0a8a86c62..dc3031ada 100644
--- a/crates/vfs/src/vfs_path.rs
+++ b/crates/vfs/src/vfs_path.rs
@@ -5,7 +5,7 @@ use paths::{AbsPath, AbsPathBuf};
5 5
6/// Long-term, we want to support files which do not reside in the file-system, 6/// Long-term, we want to support files which do not reside in the file-system,
7/// so we treat VfsPaths as opaque identifiers. 7/// so we treat VfsPaths as opaque identifiers.
8#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] 8#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
9pub struct VfsPath(VfsPathRepr); 9pub struct VfsPath(VfsPathRepr);
10 10
11impl VfsPath { 11impl VfsPath {
@@ -22,15 +22,15 @@ impl VfsPath {
22 VfsPathRepr::VirtualPath(_) => None, 22 VfsPathRepr::VirtualPath(_) => None,
23 } 23 }
24 } 24 }
25 pub fn join(&self, path: &str) -> VfsPath { 25 pub fn join(&self, path: &str) -> Option<VfsPath> {
26 match &self.0 { 26 match &self.0 {
27 VfsPathRepr::PathBuf(it) => { 27 VfsPathRepr::PathBuf(it) => {
28 let res = it.join(path).normalize(); 28 let res = it.join(path).normalize();
29 VfsPath(VfsPathRepr::PathBuf(res)) 29 Some(VfsPath(VfsPathRepr::PathBuf(res)))
30 } 30 }
31 VfsPathRepr::VirtualPath(it) => { 31 VfsPathRepr::VirtualPath(it) => {
32 let res = it.join(path); 32 let res = it.join(path)?;
33 VfsPath(VfsPathRepr::VirtualPath(res)) 33 Some(VfsPath(VfsPathRepr::VirtualPath(res)))
34 } 34 }
35 } 35 }
36 } 36 }
@@ -50,7 +50,7 @@ impl VfsPath {
50 } 50 }
51} 51}
52 52
53#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] 53#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
54enum VfsPathRepr { 54enum VfsPathRepr {
55 PathBuf(AbsPathBuf), 55 PathBuf(AbsPathBuf),
56 VirtualPath(VirtualPath), 56 VirtualPath(VirtualPath),
@@ -71,6 +71,21 @@ impl fmt::Display for VfsPath {
71 } 71 }
72} 72}
73 73
74impl fmt::Debug for VfsPath {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 fmt::Debug::fmt(&self.0, f)
77 }
78}
79
80impl fmt::Debug for VfsPathRepr {
81 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82 match &self {
83 VfsPathRepr::PathBuf(it) => fmt::Debug::fmt(&it.display(), f),
84 VfsPathRepr::VirtualPath(VirtualPath(it)) => fmt::Debug::fmt(&it, f),
85 }
86 }
87}
88
74#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] 89#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
75struct VirtualPath(String); 90struct VirtualPath(String);
76 91
@@ -86,13 +101,15 @@ impl VirtualPath {
86 self.0 = self.0[..pos].to_string(); 101 self.0 = self.0[..pos].to_string();
87 true 102 true
88 } 103 }
89 fn join(&self, mut path: &str) -> VirtualPath { 104 fn join(&self, mut path: &str) -> Option<VirtualPath> {
90 let mut res = self.clone(); 105 let mut res = self.clone();
91 while path.starts_with("../") { 106 while path.starts_with("../") {
92 assert!(res.pop()); 107 if !res.pop() {
108 return None;
109 }
93 path = &path["../".len()..] 110 path = &path["../".len()..]
94 } 111 }
95 res.0 = format!("{}/{}", res.0, path); 112 res.0 = format!("{}/{}", res.0, path);
96 res 113 Some(res)
97 } 114 }
98} 115}