Skip to content

Commit

Permalink
finally fastn-core depends on v0.5/fastn-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 4, 2024
1 parent 928b3a4 commit cb7ae3c
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ fastn-core.path = "fastn-core"
fastn-issues.path = "fastn-issues"
fastn-package.path = "fastn-package"
fastn-utils.path = "fastn-utils"
fastn-compiler = { path = "v0.5/fastn-compiler", features = ["owned-tdoc"] }
fastn-unresolved.path = "v0.5/fastn-unresolved"
fastn-runtime.path = "fastn-runtime"
fbt-lib.path = "fbt_lib"
fastn-expr.path = "fastn-expr"
Expand Down
2 changes: 2 additions & 0 deletions fastn-ds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ homepage.workspace = true

[dependencies]
fastn-utils.workspace = true
fastn-compiler.workspace = true
fastn-unresolved.workspace = true
tokio.workspace = true
thiserror.workspace = true
actix-web.workspace = true
Expand Down
1 change: 1 addition & 0 deletions fastn-ds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod user_data;
mod utils;
pub mod wasm;
pub use user_data::UserDataError;
mod symbols;

pub use create_pool::create_pool;

Expand Down
67 changes: 67 additions & 0 deletions fastn-ds/src/symbols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
impl fastn_ds::DocumentStore {
// fn find_all_definitions_in_a_module(
// &mut self,
// arena: &mut fastn_unresolved::Arena,
// global_aliases: &fastn_unresolved::AliasesSimple,
// (file, module): (String, fastn_unresolved::Module),
// ) -> Vec<fastn_unresolved::URD> {
// // we need to fetch the symbol from the store
// let source = match std::fs::File::open(file.as_str()).and_then(std::io::read_to_string) {
// Ok(v) => v,
// Err(e) => {
// println!("failed to read file {}.ftd: {e:?}", file);
// return vec![];
// }
// };
//
// let d = fastn_unresolved::parse(module.clone(), &source, arena, global_aliases);
//
// d.definitions
// .into_iter()
// .map(|d| match d {
// fastn_unresolved::UR::UnResolved(mut v) => {
// v.symbol = Some(module.symbol(v.name.unresolved().unwrap().str(), arena));
// fastn_unresolved::UR::UnResolved(v)
// }
// _ => {
// unreachable!("fastn_unresolved::parse() only returns unresolved definitions")
// }
// })
// .collect::<Vec<_>>()
// }
}

#[async_trait::async_trait]
impl fastn_compiler::SymbolStore for fastn_ds::DocumentStore {
async fn lookup(
&mut self,
_arena: &mut fastn_unresolved::Arena,
_global_aliases: &fastn_unresolved::AliasesSimple,
_symbols: &std::collections::HashSet<fastn_unresolved::Symbol>,
) -> Vec<fastn_unresolved::URD> {
todo!()
// let unique_modules = symbols
// .iter()
// .map(|s| file_for_symbol(s, arena))
// .collect::<std::collections::HashSet<_>>();
//
// unique_modules
// .into_iter()
// .flat_map(|m| self.find_all_definitions_in_a_module(arena, global_aliases, m))
// .collect()
}
}

// fn file_for_symbol(
// symbol: &fastn_unresolved::Symbol,
// arena: &mut fastn_unresolved::Arena,
// ) -> (String, fastn_unresolved::Module) {
// (
// // this code is nonsense right now
// match symbol.module(arena) {
// Some(module) => format!("{}/{}.ftd", symbol.package(arena), module),
// None => format!("{}/index.ftd", symbol.package(arena)),
// },
// symbol.parent(arena),
// )
// }
2 changes: 2 additions & 0 deletions v0.5/fastn-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ license.workspace = true
repository.workspace = true
homepage.workspace = true

[features]
owned-tdoc = []

[dependencies]
async-trait.workspace = true
Expand Down
36 changes: 36 additions & 0 deletions v0.5/fastn-compiler/src/tdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,74 @@ impl CompiledDocument {
}

impl fastn_resolved::tdoc::TDoc for CompiledDocument {
#[cfg(not(feature = "owned-tdoc"))]
fn get_opt_function(&self, name: &str) -> Option<&fastn_resolved::Function> {
match self.get(name) {
Some(fastn_resolved::Definition::Function(f)) => Some(f),
_ => None,
}
}

#[cfg(feature = "owned-tdoc")]
fn get_opt_function(&self, name: &str) -> Option<fastn_resolved::Function> {
match self.get(name) {
Some(fastn_resolved::Definition::Function(f)) => Some(f.clone()),
_ => None,
}
}

#[cfg(not(feature = "owned-tdoc"))]
fn get_opt_record(&self, name: &str) -> Option<&fastn_resolved::Record> {
match self.get(name) {
Some(fastn_resolved::Definition::Record(f)) => Some(f),
_ => None,
}
}

#[cfg(feature = "owned-tdoc")]
fn get_opt_record(&self, name: &str) -> Option<fastn_resolved::Record> {
match self.get(name) {
Some(fastn_resolved::Definition::Record(f)) => Some(f.clone()),
_ => None,
}
}

fn name(&self) -> &str {
self.name.as_str()
}

#[cfg(not(feature = "owned-tdoc"))]
fn get_opt_component(&self, name: &str) -> Option<&fastn_resolved::ComponentDefinition> {
match self.get(name) {
Some(fastn_resolved::Definition::Component(f)) => Some(f),
_ => None,
}
}

#[cfg(feature = "owned-tdoc")]
fn get_opt_component(&self, name: &str) -> Option<fastn_resolved::ComponentDefinition> {
match self.get(name) {
Some(fastn_resolved::Definition::Component(f)) => Some(f.clone()),
_ => None,
}
}

#[cfg(not(feature = "owned-tdoc"))]
fn get_opt_web_component(&self, name: &str) -> Option<&fastn_resolved::WebComponentDefinition> {
match self.get(name) {
Some(fastn_resolved::Definition::WebComponent(f)) => Some(f),
_ => None,
}
}

#[cfg(feature = "owned-tdoc")]
fn get_opt_web_component(&self, name: &str) -> Option<fastn_resolved::WebComponentDefinition> {
match self.get(name) {
Some(fastn_resolved::Definition::WebComponent(f)) => Some(f.clone()),
_ => None,
}
}

fn definitions(&self) -> &indexmap::IndexMap<String, fastn_resolved::Definition> {
&self.definitions
}
Expand Down

0 comments on commit cb7ae3c

Please sign in to comment.