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 let url = self.virtual_url(&format!("{}.ttl", prefix))?;
22 tracing::info!("lov url {} {} -> {}", url, prefix, url);
23 Some(url)
24 }
25 async fn read_file(&self, url: &crate::lsp_types::Url) -> Option<String>;
26 async fn glob_read(&self, url: &str) -> Option<Vec<File>>;
27 async fn write_file(&self, url: &crate::lsp_types::Url, content: &str) -> Option<()>;
28}