Skip to main content

swls_core/util/
fs.rs

1use std::sync::Arc;
2
3use bevy_ecs::prelude::Resource;
4use derive_more::derive::AsRef;
5
6#[derive(Resource, Clone, AsRef, Debug)]
7pub struct Fs(pub Arc<dyn FsTrait>);
8
9pub struct File {
10    pub name: String,
11    pub content: String,
12}
13
14#[tower_lsp::async_trait]
15pub trait FsTrait: Send + Sync + 'static + std::fmt::Debug {
16    fn virtual_url(&self, url: &str) -> Option<crate::lsp_types::Url>;
17    fn lov_url(&self, url: &str, prefix: &str) -> Option<crate::lsp_types::Url> {
18        if !url.starts_with("http") {
19            return None;
20        }
21
22        // let prefix_url = crate::lsp_types::Url::parse(url).ok();
23        // let prefix_origin = prefix_url.as_ref().map(|x| x.path()).unwrap_or("none");
24        let url = self.virtual_url(&format!("{}.ttl", prefix))?;
25        tracing::debug!("lov url {} {} -> {}", url, prefix, url);
26        Some(url)
27    }
28    async fn read_file(&self, url: &crate::lsp_types::Url) -> Option<String>;
29    async fn glob_read(&self, url: &str) -> Option<Vec<File>>;
30    async fn write_file(&self, url: &crate::lsp_types::Url, content: &str) -> Option<()>;
31}