Skip to content

Commit

Permalink
refactor: overhaul (#212)
Browse files Browse the repository at this point in the history
- remvoe the internal payloads
- add executors for every manager
- refactor formula manager
- upgrade gents and use undefined instead of null
  • Loading branch information
ImJeremyHe authored Dec 29, 2023
1 parent 4ccb6b0 commit c0444a1
Show file tree
Hide file tree
Showing 157 changed files with 4,449 additions and 5,129 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/buildtools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2018"
authors = ["ImJeremyHe<[email protected]>"]

[dependencies]
gents = "0.7.0"
gents = "0.8.0"

logisheets_controller = {path = "../controller", features = ["gents"]}
logisheets_sequencer = {path = "../sequencer", features = ["gents"]}
Expand Down
4 changes: 2 additions & 2 deletions crates/buildtools/src/generate.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn main() {
use gents::FileGroup;
use logisheets_controller::controller::display::{DisplayRequest, DisplayResponse};
use logisheets_controller::controller::edit_action::AsyncFuncResult;
use logisheets_controller::controller::edit_action::{ActionEffect, EditAction};
use logisheets_controller::edit_action::AsyncFuncResult;
use logisheets_controller::edit_action::{ActionEffect, EditAction};
let path = "packages/web/src/bindings";
let mut file_group = FileGroup::new();
file_group.add::<DisplayRequest>();
Expand Down
4 changes: 2 additions & 2 deletions crates/controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ logisheets_parser = {version = "0.4.0", path = "./parser"}
logisheets_workbook = {version = "0.4.0", path = "../workbook", features = ["gents"]}
logisheets_astchecker = {version = "0.4.0", path = "./ast_checker"}

gents = {version = "0.7.0", optional = true}
gents_derives = {version = "0.7.0", optional = true}
gents = {version = "0.8.0", optional = true}
gents_derives = {version = "0.8.0", optional = true}

[features]
gents = ["dep:gents", "dep:gents_derives"]
Expand Down
4 changes: 2 additions & 2 deletions crates/controller/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ thiserror = "1.0.48"

logisheets_workbook = {version = "0.4.0", path = "../../workbook"}

gents = {version = "0.7.0", optional = true}
gents_derives = {version = "0.7.0", optional = true}
gents = {version = "0.8.0", optional = true}
gents_derives = {version = "0.8.0", optional = true}

[features]
gents = ["dep:gents", "dep:gents_derives"]
8 changes: 8 additions & 0 deletions crates/controller/base/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub enum BasicError {
ColIndexUnavailable(ColId),
#[error("Failed to fetch block by the block id: {1} in sheet {0}")]
BlockIdNotFound(SheetId, BlockId),
#[error("Failed to fetch block cell by the block id: {1}, row: {2}, col: {3} in sheet {0}")]
BlockCellIdNotFound(SheetId, BlockId, usize, usize),
#[error("Failed to create block because the block id is already existed")]
BlockIdHasAlreadyExisted(BlockId),
#[error("Failed to fetch sheet by the sheet id: {0}")]
SheetIdNotFound(SheetId),
#[error(
Expand All @@ -40,6 +44,10 @@ pub enum BasicError {

#[error("sheet name not found: {0}")]
SheetNameNotFound(String),
#[error("sheet idx exceed the maximum: {0}")]
SheetIdxExceed(usize),
#[error("creating block on an existed block: {0}")]
CreatingBlockOn(BlockId),
#[error("ext ref id not found: {0}")]
ExtRefIdNotFound(ExtRefId),
}
20 changes: 18 additions & 2 deletions crates/controller/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ pub enum CellId {
BlockCell(BlockCellId),
}

impl CellId {
pub fn assert_normal_cell_id(self) -> NormalCellId {
match self {
CellId::NormalCell(n) => n,
CellId::BlockCell(_) => panic!("this cell id should be normal cell id"),
}
}
}

#[derive(Clone, Hash, Debug, Eq, PartialEq, Copy, Serialize)]
#[cfg_attr(feature = "gents", derive(gents_derives::TS))]
#[cfg_attr(feature = "gents", ts(file_name = "normal_cell_id.ts"))]
#[serde(rename_all = "camelCase")]
pub struct NormalCellId {
pub row: RowId,
pub col: ColId,
pub follow_row: Option<RowId>,
pub follow_col: Option<ColId>,
}

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -97,6 +104,15 @@ pub enum Range {
Block(BlockRange),
}

impl From<CellId> for Range {
fn from(value: CellId) -> Self {
match value {
CellId::NormalCell(n) => Range::Normal(NormalRange::Single(n)),
CellId::BlockCell(b) => Range::Block(BlockRange::Single(b)),
}
}
}

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub struct Cube {
pub from_sheet: SheetId,
Expand Down
26 changes: 22 additions & 4 deletions crates/controller/base/src/traits/block_affect.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use crate::{errors::BasicError, BlockCellId, BlockId, CellId, SheetId};
use crate::{errors::BasicError, BlockCellId, BlockId, NormalCellId, SheetId};

pub trait BlockAffectTrait {
fn get_all_block_cells(
&self,
sheet_id: SheetId,
block_id: BlockId,
) -> Result<Vec<BlockCellId>, BasicError>;
fn get_master_cell(&self, sheet_id: SheetId, block_id: BlockId) -> Result<CellId, BasicError>;
fn get_master_cell(
&self,
sheet_id: SheetId,
block_id: BlockId,
) -> Result<NormalCellId, BasicError>;
fn get_block_cells_by_line(
&self,
sheet_id: SheetId,
Expand All @@ -21,19 +25,33 @@ pub trait BlockAffectTrait {
block_id: BlockId,
) -> Result<(usize, usize), BasicError>;
fn get_blocks_across_line(
&mut self,
&self,
sheet_id: SheetId,
from_idx: usize,
cnt: usize,
is_row: bool,
) -> Result<Vec<BlockId>, BasicError>;
fn any_other_blocks_in(
&mut self,
&self,
sheet_id: SheetId,
block_id: BlockId,
start_row: usize,
end_row: usize,
start_col: usize,
end_col: usize,
) -> bool;
fn get_affected_blockplace(
&self,
sheet_id: SheetId,
line_idx: usize,
cnt: usize,
is_row: bool,
) -> Result<Vec<BlockId>, BasicError>;
fn get_block_cell_id(
&self,
sheet_id: SheetId,
block_id: BlockId,
row: usize,
col: usize,
) -> Result<BlockCellId, BasicError>;
}
5 changes: 0 additions & 5 deletions crates/controller/base/src/traits/get_active_sheet.rs

This file was deleted.

10 changes: 0 additions & 10 deletions crates/controller/base/src/traits/get_norm_cell_id.rs

This file was deleted.

16 changes: 0 additions & 16 deletions crates/controller/base/src/traits/get_norm_cells_in_line.rs

This file was deleted.

14 changes: 13 additions & 1 deletion crates/controller/base/src/traits/id_fetcher.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use crate::{Cube, CubeId, ExtRef, ExtRefId, NormalCellId, Range, RangeId};
use crate::{BlockCellId, BlockId, Cube, CubeId, ExtRef, ExtRefId, NormalCellId, Range, RangeId};

use crate::{errors::BasicError, CellId, ColId, ExtBookId, FuncId, NameId, RowId, SheetId, TextId};

pub trait SheetIdFetcherTrait {
fn fetch_sheet_id(&mut self, sheet_name: &str) -> SheetId;
}

pub trait SheetIdFetcherByIdxTrait {
// Return the count of sheets if `idx` exceeds.
fn fetch_sheet_id_by_index(&self, idx: usize) -> Result<SheetId, usize>;
}

pub trait IdFetcherTrait {
fn fetch_row_id(&self, sheet_id: &SheetId, row_idx: usize) -> Result<RowId, BasicError>;
fn fetch_col_id(&self, sheet_id: &SheetId, col_idx: usize) -> Result<ColId, BasicError>;
Expand All @@ -22,6 +27,13 @@ pub trait IdFetcherTrait {
row_idx: usize,
col_idx: usize,
) -> Result<NormalCellId, BasicError>;
fn fetch_block_cell_id(
&self,
sheet_id: &SheetId,
block_id: &BlockId,
row: usize,
col: usize,
) -> Result<BlockCellId, BasicError>;

fn fetch_sheet_id(&mut self, sheet_name: &str) -> SheetId;

Expand Down
3 changes: 0 additions & 3 deletions crates/controller/base/src/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
pub mod block_affect;
pub mod get_active_sheet;
pub mod get_book_name;
pub mod get_curr_addr;
pub mod get_norm_cell_id;
pub mod get_norm_cells_in_line;
pub mod id_fetcher;
pub mod index_fetcher;
pub mod name_fetcher;
Expand Down
2 changes: 1 addition & 1 deletion crates/controller/base/src/types/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub type SheetId = u16;
pub type TextId = u32;
pub type NameId = u8;
pub type FuncId = u16;
pub type BlockId = u16;
pub type BlockId = usize;
pub const CURR_BOOK: ExtBookId = 0;
pub type ExtBookId = u8;
pub type AuthorId = u8;
Expand Down
28 changes: 12 additions & 16 deletions crates/controller/parser/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
use logisheets_base::errors::BasicError;
use logisheets_base::get_active_sheet::GetActiveSheetTrait;
use logisheets_base::get_book_name::GetBookNameTrait;
use logisheets_base::id_fetcher::{IdFetcherTrait, VertexFetcherTrait};
use logisheets_base::{
Cube, CubeId, ExtBookId, ExtRef, ExtRefId, FuncId, NameId, NormalCellId, Range, RangeId,
SheetId, TextId,
};

pub trait ContextTrait:
IdFetcherTrait + GetActiveSheetTrait + GetBookNameTrait + VertexFetcherTrait
{
}
pub trait ContextTrait: IdFetcherTrait + GetBookNameTrait + VertexFetcherTrait {}

pub struct Context<'a, T, F>
where
T: IdFetcherTrait,
F: VertexFetcherTrait,
{
pub sheet_id: SheetId,
pub book_name: &'a str,
pub id_fetcher: &'a mut T,
pub vertex_fetcher: &'a mut F,
Expand Down Expand Up @@ -48,16 +43,6 @@ where
}
}

impl<'a, T, F> GetActiveSheetTrait for Context<'a, T, F>
where
T: IdFetcherTrait,
F: VertexFetcherTrait,
{
fn get_active_sheet(&self) -> SheetId {
self.sheet_id
}
}

impl<'a, T, F> GetBookNameTrait for Context<'a, T, F>
where
T: IdFetcherTrait,
Expand Down Expand Up @@ -127,4 +112,15 @@ where
self.id_fetcher
.fetch_norm_cell_id(sheet_id, row_idx, col_idx)
}

fn fetch_block_cell_id(
&self,
sheet_id: &SheetId,
block_id: &logisheets_base::BlockId,
row: usize,
col: usize,
) -> Result<logisheets_base::BlockCellId, BasicError> {
self.id_fetcher
.fetch_block_cell_id(sheet_id, block_id, row, col)
}
}
Loading

0 comments on commit c0444a1

Please sign in to comment.