aboutsummaryrefslogtreecommitdiff
path: root/crates/vfs
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-09-03 21:18:23 +0100
committerKirill Bulatov <[email protected]>2020-09-09 23:42:20 +0100
commit17870a3e2c39770a99f9ab5ce090abbe1dc334d2 (patch)
tree85e98d57518fd2735820e9b70f16a7e2ab54d082 /crates/vfs
parent4bed588001a1d6cd5c83a3eefc6ef77c439de40b (diff)
Better API
Diffstat (limited to 'crates/vfs')
-rw-r--r--crates/vfs/src/file_set.rs28
-rw-r--r--crates/vfs/src/vfs_path.rs15
2 files changed, 29 insertions, 14 deletions
diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs
index 8bce17bc0..0caddc3bc 100644
--- a/crates/vfs/src/file_set.rs
+++ b/crates/vfs/src/file_set.rs
@@ -20,15 +20,24 @@ impl FileSet {
20 self.files.len() 20 self.files.len()
21 } 21 }
22 pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { 22 pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
23 let mut base = self.paths[&anchor].clone(); 23 let mut base = dbg!(self.paths[&anchor].clone());
24 base.pop(); 24 base.pop();
25 let path = base.join(path)?; 25 let path = dbg!(base).join(dbg!(path))?;
26 self.files.get(&path).copied() 26 self.files.get(&path).copied()
27 } 27 }
28 pub fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> { 28
29 let anchor_path = self.paths[&anchor].clone(); 29 pub fn file_name_and_extension(&self, file: FileId) -> Option<(&str, &str)> {
30 self.paths[&file].file_name_and_extension()
31 }
32
33 pub fn list_files(&self, directory: FileId) -> Vec<(FileId, String)> {
34 // TODO kb determine the ways to list all applicable files
35 // Maybe leave list directory here only and the move the rest of the logic into the database impl?
36 // cache results in Salsa?
37
38 dbg!(directory);
30 /* 39 /*
31 [crates/vfs/src/file_set.rs:30] anchor_path = "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/lib.rs" 40 [crates/vfs/src/file_set.rs:30] directory = "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/"
32 [crates/vfs/src/file_set.rs:31] self.files.keys() = [ 41 [crates/vfs/src/file_set.rs:31] self.files.keys() = [
33 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2/test_mod_3.rs", 42 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2/test_mod_3.rs",
34 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2.rs", 43 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2.rs",
@@ -38,15 +47,6 @@ impl FileSet {
38 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3.rs", 47 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3.rs",
39 ] 48 ]
40 */ 49 */
41
42 // TODO kb determine the ways to list all applicable files
43 // Maybe leave list directory here only and the move the rest of the logic into the database impl?
44
45 // Need to get the following things:
46 // * name of the anchor_path file (file_name, validate that it's a file!)
47 // * list of all files in the file's contai/ning directory (file_dir)
48 // * list of all files in `file_dir/file_name` or just `file_dir/`, for lib.rs or mod.rs
49 // * consider special case for /src/bin/foo.rs as a mod<|> source
50 Vec::new() 50 Vec::new()
51 } 51 }
52 pub fn insert(&mut self, file_id: FileId, path: VfsPath) { 52 pub fn insert(&mut self, file_id: FileId, path: VfsPath) {
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs
index 944a702df..7b965bb4c 100644
--- a/crates/vfs/src/vfs_path.rs
+++ b/crates/vfs/src/vfs_path.rs
@@ -49,6 +49,16 @@ impl VfsPath {
49 } 49 }
50 } 50 }
51 51
52 pub fn file_name_and_extension(&self) -> Option<(&str, &str)> {
53 match &self.0 {
54 VfsPathRepr::PathBuf(p) => p
55 .file_stem()
56 .zip(p.extension())
57 .and_then(|(name, extension)| Some((name.to_str()?, extension.to_str()?))),
58 VfsPathRepr::VirtualPath(p) => p.file_name_and_extension(),
59 }
60 }
61
52 // Don't make this `pub` 62 // Don't make this `pub`
53 pub(crate) fn encode(&self, buf: &mut Vec<u8>) { 63 pub(crate) fn encode(&self, buf: &mut Vec<u8>) {
54 let tag = match &self.0 { 64 let tag = match &self.0 {
@@ -268,4 +278,9 @@ impl VirtualPath {
268 res.0 = format!("{}/{}", res.0, path); 278 res.0 = format!("{}/{}", res.0, path);
269 Some(res) 279 Some(res)
270 } 280 }
281
282 pub fn file_name_and_extension(&self) -> Option<(&str, &str)> {
283 // TODO kb check if is a file
284 Some(("test_mod_1", "rs"))
285 }
271} 286}