aboutsummaryrefslogtreecommitdiff
path: root/crates/vfs/src/file_set.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/vfs/src/file_set.rs')
-rw-r--r--crates/vfs/src/file_set.rs37
1 files changed, 23 insertions, 14 deletions
diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs
index 7dc721f7e..0173f7464 100644
--- a/crates/vfs/src/file_set.rs
+++ b/crates/vfs/src/file_set.rs
@@ -2,9 +2,8 @@
2//! 2//!
3//! Files which do not belong to any explicitly configured `FileSet` belong to 3//! Files which do not belong to any explicitly configured `FileSet` belong to
4//! the default `FileSet`. 4//! the default `FileSet`.
5use std::{cmp, fmt, iter}; 5use std::{fmt, iter};
6 6
7use paths::AbsPathBuf;
8use rustc_hash::FxHashMap; 7use rustc_hash::FxHashMap;
9 8
10use crate::{FileId, Vfs, VfsPath}; 9use crate::{FileId, Vfs, VfsPath};
@@ -41,7 +40,13 @@ impl fmt::Debug for FileSet {
41#[derive(Debug)] 40#[derive(Debug)]
42pub struct FileSetConfig { 41pub struct FileSetConfig {
43 n_file_sets: usize, 42 n_file_sets: usize,
44 roots: Vec<(AbsPathBuf, usize)>, 43 roots: Vec<(VfsPath, usize)>,
44}
45
46impl Default for FileSetConfig {
47 fn default() -> Self {
48 FileSetConfig::builder().build()
49 }
45} 50}
46 51
47impl FileSetConfig { 52impl FileSetConfig {
@@ -60,19 +65,20 @@ impl FileSetConfig {
60 self.n_file_sets 65 self.n_file_sets
61 } 66 }
62 fn classify(&self, path: &VfsPath) -> usize { 67 fn classify(&self, path: &VfsPath) -> usize {
63 for (root, idx) in self.roots.iter() { 68 let idx = match self.roots.binary_search_by(|(p, _)| p.cmp(path)) {
64 if let Some(path) = path.as_path() { 69 Ok(it) => it,
65 if path.starts_with(root) { 70 Err(it) => it.saturating_sub(1),
66 return *idx; 71 };
67 } 72 if path.starts_with(&self.roots[idx].0) {
68 } 73 self.roots[idx].1
74 } else {
75 self.len() - 1
69 } 76 }
70 self.len() - 1
71 } 77 }
72} 78}
73 79
74pub struct FileSetConfigBuilder { 80pub struct FileSetConfigBuilder {
75 roots: Vec<Vec<AbsPathBuf>>, 81 roots: Vec<Vec<VfsPath>>,
76} 82}
77 83
78impl Default for FileSetConfigBuilder { 84impl Default for FileSetConfigBuilder {
@@ -82,18 +88,21 @@ impl Default for FileSetConfigBuilder {
82} 88}
83 89
84impl FileSetConfigBuilder { 90impl FileSetConfigBuilder {
85 pub fn add_file_set(&mut self, roots: Vec<AbsPathBuf>) { 91 pub fn len(&self) -> usize {
92 self.roots.len()
93 }
94 pub fn add_file_set(&mut self, roots: Vec<VfsPath>) {
86 self.roots.push(roots) 95 self.roots.push(roots)
87 } 96 }
88 pub fn build(self) -> FileSetConfig { 97 pub fn build(self) -> FileSetConfig {
89 let n_file_sets = self.roots.len() + 1; 98 let n_file_sets = self.roots.len() + 1;
90 let mut roots: Vec<(AbsPathBuf, usize)> = self 99 let mut roots: Vec<(VfsPath, usize)> = self
91 .roots 100 .roots
92 .into_iter() 101 .into_iter()
93 .enumerate() 102 .enumerate()
94 .flat_map(|(i, paths)| paths.into_iter().zip(iter::repeat(i))) 103 .flat_map(|(i, paths)| paths.into_iter().zip(iter::repeat(i)))
95 .collect(); 104 .collect();
96 roots.sort_by_key(|(path, _)| cmp::Reverse(path.to_string_lossy().len())); 105 roots.sort();
97 FileSetConfig { n_file_sets, roots } 106 FileSetConfig { n_file_sets, roots }
98 } 107 }
99} 108}