Skip to content

Commit

Permalink
default to use insert_str_runtime for implicit runtime decl entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
weezy20 committed Mar 9, 2024
1 parent 736deb4 commit 3ed2a26
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions src/engines/pallet_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use pallet_entry::Numbers;
use pallet_entry::{AddPalletEntry, ReadPalletEntry};
use parser::RuntimeDeclaration;
use proc_macro2::TokenStream;
use quote::quote;
use std::{
collections::HashMap,
fs::{self, File, OpenOptions},
Expand Down Expand Up @@ -78,7 +79,6 @@ pub struct PalletEngine {
state: State,
/// Cursor for tracking where we are in the output
cursor: usize,

}
impl Drop for PalletEngine {
fn drop(&mut self) {
Expand Down Expand Up @@ -180,9 +180,8 @@ impl PalletEngine {
_ => {},
};
}
let imports = ImportDetails {
last_import: last_import.expect("Imports are always present"),
};
let imports =
ImportDetails { last_import: last_import.expect("Imports are always present") };
let Some(details) = details else {
bail!("No pallets/construct_runtime! found in input");
};
Expand Down Expand Up @@ -328,7 +327,7 @@ impl PalletEngine {
/// Insert configuartion for a pallet - only for pallet-template atm
fn insert_config(&mut self, config: (TokenStream, usize)) -> anyhow::Result<()> {
self.append_tokens(config.0);
self.cursor += config.1;
self.cursor += config.1;
Ok(())
}
/// Append lines [start..end] from `input` source to `output`.
Expand Down Expand Up @@ -449,32 +448,34 @@ impl PalletEngine {
/// Overwrites existing CRT in output, this means that `self.cursor` has to backtracked to crt_start
/// and updated after the pallet entry has been inserted
fn add_pallet_runtime(&mut self, new_pallet: AddPalletEntry) -> anyhow::Result<()> {
use std::io::{Seek, SeekFrom};
// re-render output CRT:
self.insert_at(self.cursor, "//---- ReRender from add_pallet_runtime ----\n")?;
println!("cursor -> {}", self.cursor);
match &mut self.details.declaration {
RuntimeDeclaration::Implicit(i) => {
let mut ultimate = i
.pallets
.last()
.ok_or(anyhow!("Fatal: No pallets defined in construct_runtime!"))?
.clone();
ultimate.index = new_pallet.index;
ultimate.path.inner.segments[0].ident = new_pallet.path;
ultimate.name = new_pallet.name;
i.pallets.push(ultimate);
},
RuntimeDeclaration::Explicit(e) => {
todo!()
},
RuntimeDeclaration::ExplicitExpanded(e) => {
todo!()
},
};
// new_lines will tell cursor to update accounting for the new pallet
// self.render_pallets(new_lines)?;
let mut entry = String::new();
let AddPalletEntry { name, path, index } = new_pallet;
if let Some(idx) = index {
entry = format!("\t\t{}: {} = {},", name, path, idx);
} else {
entry = format!("\t\t{}: {},", name, path);
}
self.insert_str_runtime(&entry)?;
// match &mut self.details.declaration {
// RuntimeDeclaration::Implicit(i) => {
// let mut ultimate = i
// .pallets
// .last()
// .ok_or(anyhow!("Fatal: No pallets defined in construct_runtime!"))?
// .clone();
// ultimate.index = new_pallet.index;
// ultimate.path.inner.segments[0].ident = new_pallet.path;
// ultimate.name = new_pallet.name;
// i.pallets.push(ultimate);
// },
// RuntimeDeclaration::Explicit(e) => {
// todo!()
// },
// RuntimeDeclaration::ExplicitExpanded(e) => {
// todo!()
// },
// };
Ok(())
}
}
// TODO
// TODO

0 comments on commit 3ed2a26

Please sign in to comment.