| 100 | } |
| 101 | |
| 102 | async fn list_dir( |
| 103 | &self, |
| 104 | path: &crate::workspace::WorkspacePath, |
| 105 | ) -> crate::workspace::WorkspaceResult<Vec<crate::workspace::WorkspaceDirEntry>> { |
| 106 | let prefix = if path.is_root() { |
| 107 | String::new() |
| 108 | } else { |
| 109 | format!("{}/", path.as_str()) |
| 110 | }; |
| 111 | let files = self.files.read().unwrap(); |
| 112 | let mut entries = Vec::new(); |
| 113 | |
| 114 | for (file_path, content) in files.iter() { |
| 115 | if !file_path.starts_with(&prefix) { |
| 116 | continue; |
| 117 | } |
| 118 | let remaining = &file_path[prefix.len()..]; |
| 119 | if remaining.is_empty() || remaining.contains('/') { |
| 120 | continue; |
| 121 | } |
| 122 | entries.push(crate::workspace::WorkspaceDirEntry { |
| 123 | name: remaining.to_string(), |
| 124 | kind: crate::workspace::WorkspaceFileType::File, |
| 125 | size: content.len() as u64, |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | Ok(entries) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | #[derive(Default)] |