MCPcopy Create free account
hub / github.com/AI45Lab/Code / index_files

Method index_files

core/src/context/fs_provider.rs:98–139  ·  view source on GitHub ↗

Index files in the root directory

(&self)

Source from the content-addressed store, hash-verified

96
97 /// Index files in the root directory
98 async fn index_files(&self) -> anyhow::Result<Vec<IndexedFile>> {
99 let mut files = Vec::new();
100
101 let walker = WalkBuilder::new(&self.config.root_path)
102 .hidden(false)
103 .git_ignore(true)
104 .build();
105
106 for entry in walker {
107 let entry = entry.map_err(|e| anyhow::anyhow!("Walk error: {}", e))?;
108 let path = entry.path();
109
110 if !path.is_file() {
111 continue;
112 }
113
114 let metadata =
115 fs::metadata(path).map_err(|e| anyhow::anyhow!("Metadata error: {}", e))?;
116 if metadata.len() > self.config.max_file_size as u64 {
117 continue;
118 }
119
120 if !self.matches_include_patterns(path) {
121 continue;
122 }
123
124 if self.matches_exclude_patterns(path) {
125 continue;
126 }
127
128 let content =
129 fs::read_to_string(path).map_err(|e| anyhow::anyhow!("Read error: {}", e))?;
130
131 files.push(IndexedFile {
132 path: path.to_path_buf(),
133 content,
134 size: metadata.len() as usize,
135 });
136 }
137
138 Ok(files)
139 }
140
141 fn matches_include_patterns(&self, path: &Path) -> bool {
142 if self.config.include_patterns.is_empty() {

Callers 2

get_filesMethod · 0.80
test_index_filesFunction · 0.80

Calls 6

hiddenMethod · 0.80
pathMethod · 0.80
buildMethod · 0.45
lenMethod · 0.45

Tested by 1

test_index_filesFunction · 0.64