Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix flowy_tool issues
appflowyf9bfe94a6b1f
diff --git a/.run/ProtoBuf_Gen.run.xml b/.run/ProtoBuf_Gen.run.xmlindex 2fdf466875..ab3331fd3e 100644--- a/.run/ProtoBuf_Gen.run.xml+++ b/.run/ProtoBuf_Gen.run.xml@@ -1,17 +1,18 @@<component name="ProjectRunConfigurationManager"><configuration default="false" name="ProtoBuf_Gen" type="CargoCommandRunConfiguration" factoryName="Cargo Command">- <option name="command" value="run --manifest-path $PROJECT_DIR$/scripts/flowy-tool/Cargo.toml -- pb-gen --rust_source=$PROJECT_DIR$/rust-lib/ --derive_meta=$PROJECT_DIR$/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs --flutter_package_lib=$PROJECT_DIR$/app_flowy/packages/flowy_sdk/lib" />- <option name="workingDirectory" value="file://$PROJECT_DIR$" />+ <option name="command" value="run --manifest-path ${flowy_tool} -- pb-gen --rust_sources=${rust_lib},${shared_lib} --derive_meta=${derive_meta} --flutter_package_lib=${flutter_package_lib}" />+ <option name="workingDirectory" value="file://$PROJECT_DIR$/frontend" /><option name="channel" value="DEFAULT" /><option name="allFeatures" value="false" /><option name="emulateTerminal" value="false" /><option name="backtrace" value="SHORT" /><envs>- <env name="rust_source" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/" />- <env name="build_cache" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-derive/src/auto_gen_file/category_from_str.rs" />- <env name="proto_file_output" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-protobuf/define" />- <env name="rust_mod_dir" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-protobuf/src/" />- <env name="flutter_mod_dir" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/flutter-lib/packages/flowy_protobuf/lib/" />+ <env name="flowy_tool" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/scripts/flowy-tool/Cargo.toml" />+ <env name="rust_lib" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/" />+ <env name="shared_lib" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/../shared_lib" />+ <env name="flutter_lib" value="${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages" />+ <env name="derive_meta" value="${shared_lib}/flowy-derive/src/derive_cache/derive_cache.rs" />+ <env name="flutter_package_lib" value="${flutter_lib}/flowy_sdk/lib" /></envs><option name="isRedirectInput" value="false" /><option name="redirectInputPath" value="" />diff --git a/frontend/scripts/flowy-tool/src/dart_event/dart_event.rs b/frontend/scripts/flowy-tool/src/dart_event/dart_event.rsindex 2c57325157..e4288033af 100644--- a/frontend/scripts/flowy-tool/src/dart_event/dart_event.rs+++ b/frontend/scripts/flowy-tool/src/dart_event/dart_event.rs@@ -6,13 +6,13 @@ use syn::Item;use walkdir::WalkDir;pub struct DartEventCodeGen {- pub rust_source: String,+ pub rust_sources: Vec<String>,pub output_dir: String,}impl DartEventCodeGen {pub fn gen(&self) {- let event_crates = parse_dart_event_files(self.rust_source.as_ref());+ let event_crates = parse_dart_event_files(self.rust_sources.clone());let event_ast = event_crates.iter().map(|event_crate| parse_event_crate(event_crate))@@ -55,15 +55,20 @@ impl DartEventCrate {}}-pub fn parse_dart_event_files(root: &str) -> Vec<DartEventCrate> {- WalkDir::new(root)- .into_iter()- .filter_entry(|e| !is_hidden(e))- .filter_map(|e| e.ok())- .filter(|e| is_crate_dir(e))- .flat_map(|e| parse_crate_config_from(&e))- .map(|crate_config| DartEventCrate::from_config(&crate_config))- .collect::<Vec<DartEventCrate>>()+pub fn parse_dart_event_files(roots: Vec<String>) -> Vec<DartEventCrate> {+ let mut dart_event_crates: Vec<DartEventCrate> = vec![];+ roots.iter().for_each(|root| {+ let crates = WalkDir::new(root)+ .into_iter()+ .filter_entry(|e| !is_hidden(e))+ .filter_map(|e| e.ok())+ .filter(|e| is_crate_dir(e))+ .flat_map(|e| parse_crate_config_from(&e))+ .map(|crate_config| DartEventCrate::from_config(&crate_config))+ .collect::<Vec<DartEventCrate>>();+ dart_event_crates.extend(crates);+ });+ dart_event_crates}pub fn parse_event_crate(event_crate: &DartEventCrate) -> Vec<EventASTContext> {diff --git a/frontend/scripts/flowy-tool/src/main.rs b/frontend/scripts/flowy-tool/src/main.rsindex 752192301b..c25b0041b5 100644--- a/frontend/scripts/flowy-tool/src/main.rs+++ b/frontend/scripts/flowy-tool/src/main.rs@@ -11,12 +11,16 @@ fn main() {let matches = app().get_matches();if let Some(ref matches) = matches.subcommand_matches("pb-gen") {- let rust_source = matches.value_of("rust_source").unwrap();+ let rust_sources: Vec<String> = matches+ .values_of("rust_sources")+ .unwrap()+ .map(|value| value.to_owned())+ .collect();let derive_meta = matches.value_of("derive_meta").unwrap();let flutter_package_lib = matches.value_of("flutter_package_lib").unwrap();proto::ProtoGenBuilder::new()- .set_rust_source_dir(rust_source)+ .set_rust_source_dirs(rust_sources).set_derive_meta_dir(derive_meta).set_flutter_package_lib(flutter_package_lib).build()@@ -24,11 +28,15 @@ fn main() {}if let Some(ref matches) = matches.subcommand_matches("dart-event") {- let rust_source = matches.value_of("rust_source").unwrap().to_string();+ let rust_sources: Vec<String> = matches+ .values_of("rust_sources")+ .unwrap()+ .map(|value| value.to_owned())+ .collect();let output_dir = matches.value_of("output").unwrap().to_string();let code_gen = dart_event::DartEventCodeGen {- rust_source,+ rust_sources,output_dir,};code_gen.gen();@@ -44,10 +52,13 @@ pub fn app<'a, 'b>() -> App<'a, 'b> {App::new("pb-gen").about("Generate proto file from rust code").arg(- Arg::with_name("rust_source")- .long("rust_source")+ Arg::with_name("rust_sources")+ .long("rust_sources")+ .multiple(true)+ .required(true)+ .min_values(1).value_name("DIRECTORY")- .help("Directory of the cargo workspace"),+ .help("Directories of the cargo workspace"),).arg(Arg::with_name("derive_meta")@@ -65,10 +76,13 @@ pub fn app<'a, 'b>() -> App<'a, 'b> {App::new("dart-event").about("Generate the codes that sending events from rust ast").arg(- Arg::with_name("rust_source")- .long("rust_source")+ Arg::with_name("rust_sources")+ .long("rust_sources")+ .multiple(true)+ .required(true)+ .min_values(1).value_name("DIRECTORY")- .help("Directory of the cargo workspace"),+ .help("Directories of the cargo workspace"),).arg(Arg::with_name("output")diff --git a/frontend/scripts/flowy-tool/src/proto/ast.rs b/frontend/scripts/flowy-tool/src/proto/ast.rsindex 33a1b07f2d..59e7619312 100644--- a/frontend/scripts/flowy-tool/src/proto/ast.rs+++ b/frontend/scripts/flowy-tool/src/proto/ast.rs@@ -8,8 +8,8 @@ use std::{fs::File, io::Read, path::Path};use syn::Item;use walkdir::WalkDir;-pub fn parse_crate_protobuf(root: &str) -> Vec<CrateProtoInfo> {- let crate_infos = parse_crate_info_from_path(root);+pub fn parse_crate_protobuf(roots: Vec<String>) -> Vec<CrateProtoInfo> {+ let crate_infos = parse_crate_info_from_path(roots);crate_infos.into_iter().map(|crate_info| {diff --git a/frontend/scripts/flowy-tool/src/proto/builder.rs b/frontend/scripts/flowy-tool/src/proto/builder.rsindex 8c6faae3cb..43fae17e48 100644--- a/frontend/scripts/flowy-tool/src/proto/builder.rs+++ b/frontend/scripts/flowy-tool/src/proto/builder.rs@@ -2,7 +2,7 @@ use crate::proto::ProtoGen;#[allow(dead_code)]pub struct ProtoGenBuilder {- rust_source_dir: Option<String>,+ rust_source_dirs: Option<Vec<String>>,flutter_package_lib: Option<String>,derive_meta_dir: Option<String>,}@@ -10,14 +10,14 @@ pub struct ProtoGenBuilder {impl ProtoGenBuilder {pub fn new() -> Self {ProtoGenBuilder {- rust_source_dir: None,+ rust_source_dirs: None,flutter_package_lib: None,derive_meta_dir: None,}}- pub fn set_rust_source_dir(mut self, dir: &str) -> Self {- self.rust_source_dir = Some(dir.to_string());+ pub fn set_rust_source_dirs(mut self, dirs: Vec<String>) -> Self {+ self.rust_source_dirs = Some(dirs);self}@@ -33,7 +33,7 @@ impl ProtoGenBuilder {pub fn build(self) -> ProtoGen {ProtoGen {- rust_source_dir: self.rust_source_dir.unwrap(),+ rust_source_dirs: self.rust_source_dirs.unwrap(),flutter_package_lib: self.flutter_package_lib.unwrap(),derive_meta_dir: self.derive_meta_dir.unwrap(),}diff --git a/frontend/scripts/flowy-tool/src/proto/proto_gen.rs b/frontend/scripts/flowy-tool/src/proto/proto_gen.rsindex 42cb6dd1b3..05f3d791ce 100644--- a/frontend/scripts/flowy-tool/src/proto/proto_gen.rs+++ b/frontend/scripts/flowy-tool/src/proto/proto_gen.rs@@ -5,14 +5,14 @@ use std::path::Path;use std::{fs::OpenOptions, io::Write};pub struct ProtoGen {- pub(crate) rust_source_dir: String,+ pub(crate) rust_source_dirs: Vec<String>,pub(crate) flutter_package_lib: String,pub(crate) derive_meta_dir: String,}impl ProtoGen {pub fn gen(&self) {- let crate_proto_infos = parse_crate_protobuf(self.rust_source_dir.as_ref());+ let crate_proto_infos = parse_crate_protobuf(self.rust_source_dirs.clone());write_proto_files(&crate_proto_infos);// FIXME: ignore unchanged file to reduce time costdiff --git a/frontend/scripts/flowy-tool/src/proto/proto_info.rs b/frontend/scripts/flowy-tool/src/proto/proto_info.rsindex bfacb2b33b..77a77b1de1 100644--- a/frontend/scripts/flowy-tool/src/proto/proto_info.rs+++ b/frontend/scripts/flowy-tool/src/proto/proto_info.rs@@ -95,15 +95,20 @@ pub struct ProtoFile {pub generated_content: String,}-pub fn parse_crate_info_from_path(root: &str) -> Vec<ProtobufCrate> {- WalkDir::new(root)- .into_iter()- .filter_entry(|e| !is_hidden(e))- .filter_map(|e| e.ok())- .filter(|e| is_crate_dir(e))- .flat_map(|e| parse_crate_config_from(&e))- .map(ProtobufCrate::from_config)- .collect::<Vec<ProtobufCrate>>()+pub fn parse_crate_info_from_path(roots: Vec<String>) -> Vec<ProtobufCrate> {+ let mut protobuf_crates: Vec<ProtobufCrate> = vec![];+ roots.iter().for_each(|root| {+ let crates = WalkDir::new(root)+ .into_iter()+ .filter_entry(|e| !is_hidden(e))+ .filter_map(|e| e.ok())+ .filter(|e| is_crate_dir(e))+ .flat_map(|e| parse_crate_config_from(&e))+ .map(ProtobufCrate::from_config)+ .collect::<Vec<ProtobufCrate>>();+ protobuf_crates.extend(crates);+ });+ protobuf_crates}pub struct FlutterProtobufInfo {diff --git a/frontend/scripts/makefile/protobuf.toml b/frontend/scripts/makefile/protobuf.tomlindex 1247401988..5ac9ee2d22 100644--- a/frontend/scripts/makefile/protobuf.toml+++ b/frontend/scripts/makefile/protobuf.toml@@ -19,8 +19,7 @@ script_runner = "@duckscript"script = ["""flowy_tool=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/scripts/flowy-tool/Cargo.toml- rust_source=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/- # rust_lib=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib+ rust_lib=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/shared_lib=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/../shared-libflutter_lib=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages@@ -29,7 +28,7 @@ script = [cargo run \--manifest-path ${flowy_tool} pb-gen \- --rust_source=${rust_source} \+ --rust_sources ${rust_lib},${shared_lib} \--derive_meta=${derive_meta} \--flutter_package_lib=${flutter_package_lib}""",@@ -37,6 +36,7 @@ script = [script_runner = "@shell"+[tasks.gen_pb_file.windows]script = ["""@@ -70,7 +70,7 @@ script = [cargo run \--manifest-path ${flowy_tool} dart-event \- --rust_source=${rust_source} \+ --rust_sources=${rust_source} \--output=${output}""",]diff --git a/shared-lib/flowy-derive/src/derive_cache/derive_cache.rs b/shared-lib/flowy-derive/src/derive_cache/derive_cache.rsindex 90e8b746d1..a8e069b9f2 100644--- a/shared-lib/flowy-derive/src/derive_cache/derive_cache.rs+++ b/shared-lib/flowy-derive/src/derive_cache/derive_cache.rs@@ -15,7 +15,14 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {"HashMap" => TypeCategory::Map,"u8" => TypeCategory::Bytes,"String" => TypeCategory::Str,- "QueryAppRequest"+ "KeyValue"+ | "WorkspaceError"+ | "DocError"+ | "FFIRequest"+ | "FFIResponse"+ | "SubscribeObject"+ | "UserError"+ | "QueryAppRequest"| "AppIdentifier"| "CreateAppRequest"| "ColorStyle"@@ -58,8 +65,6 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {| "Revision"| "RevisionRange"| "WsDocumentData"- | "KeyValue"- | "WorkspaceError"| "WsError"| "WsMessage"| "SignInRequest"@@ -72,25 +77,20 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {| "UserProfile"| "UpdateUserRequest"| "UpdateUserParams"- | "DocError"- | "FFIRequest"- | "FFIResponse"- | "SubscribeObject"- | "UserError"=> TypeCategory::Protobuf,- "TrashType"- | "ViewType"- | "ExportType"- | "ErrorCode"- | "RevType"- | "WsDataType"- | "WorkspaceEvent"+ "WorkspaceEvent"| "WorkspaceNotification"- | "WsModule"+ | "ErrorCode"| "DocObservable"| "FFIStatusCode"| "UserEvent"| "UserNotification"+ | "TrashType"+ | "ViewType"+ | "ExportType"+ | "RevType"+ | "WsDataType"+ | "WsModule"=> TypeCategory::Enum,"Option" => TypeCategory::Opt,