qlty_analysis/workspace_entries/
workspace_entry.rs1use anyhow::Result;
2use path_absolutize::Absolutize;
3use serde::Serialize;
4use std::hash::Hash;
5use std::sync::Arc;
6use std::{path::PathBuf, time::SystemTime};
7
8use crate::utils::fs::path_to_string;
9
10#[derive(Default, Debug, Serialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub enum WorkspaceEntryKind {
12 #[default]
13 File,
14 Directory,
15}
16
17#[derive(Debug, Serialize, Eq, PartialEq, PartialOrd, Hash, Clone)]
18pub struct WorkspaceEntry {
19 pub path: PathBuf,
20 pub kind: WorkspaceEntryKind,
21 pub content_modified: SystemTime,
22 pub contents_size: u64,
23 pub language_name: Option<String>,
24}
25
26impl WorkspaceEntry {
27 pub fn path_string(&self) -> String {
28 path_to_string(&self.path)
29 }
30
31 pub fn full_path(&self, base_path: &PathBuf) -> Result<PathBuf> {
32 self.path
33 .absolutize_from(base_path)
34 .map(|p| p.into_owned())
35 .map_err(|e| {
36 anyhow::anyhow!(
37 "Failed to get the absolute path for {}: {}",
38 self.path.display(),
39 e
40 )
41 })
42 }
43}
44
45pub trait WorkspaceEntrySource: std::fmt::Debug + Send + Sync {
46 fn entries(&self) -> Arc<Vec<WorkspaceEntry>>;
47}