From f5920c5839d8d67b8d150d762ca5f4fda175ad41 Mon Sep 17 00:00:00 2001 From: utnim2 Date: Sat, 4 May 2024 05:41:11 +0530 Subject: [PATCH 1/3] `get_schema_type` and `get_full_schema_type` will now return `SchemaType` instance Signed-off-by: utnim2 --- kclvm/api/src/service/ty.rs | 1 + kclvm/query/src/query.rs | 5 ++++- kclvm/spec/gpyrpc/gpyrpc.proto | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kclvm/api/src/service/ty.rs b/kclvm/api/src/service/ty.rs index 51a8a7b29..83fff2350 100644 --- a/kclvm/api/src/service/ty.rs +++ b/kclvm/api/src/service/ty.rs @@ -51,6 +51,7 @@ pub(crate) fn kcl_schema_ty_to_pb_ty(schema_ty: &SchemaType) -> KclType { filename: schema_ty.filename.clone(), pkg_path: schema_ty.pkgpath.clone(), description: schema_ty.doc.clone(), + base_schema: schema_ty.base.as_ref().map(|base| kcl_schema_ty_to_pb_ty(base)), ..Default::default() } } diff --git a/kclvm/query/src/query.rs b/kclvm/query/src/query.rs index c23983431..f71f0e39a 100644 --- a/kclvm/query/src/query.rs +++ b/kclvm/query/src/query.rs @@ -164,7 +164,10 @@ pub fn get_full_schema_type( let scope = resolve_file(&opts)?; for (name, o) in &scope.borrow().elems { if o.borrow().ty.is_schema() { - let schema_ty = o.borrow().ty.into_schema_type(); + let mut schema_ty = o.borrow().ty.into_schema_type(); + if let Some(base) = &schema_ty.base { + schema_ty.base = Some(Box::new(get_full_schema_type_recursive(*base.clone())?)); + } if opts.get_schema_opts == GetSchemaOption::All || (opts.get_schema_opts == GetSchemaOption::Definitions && !schema_ty.is_instance) || (opts.get_schema_opts == GetSchemaOption::Instances && schema_ty.is_instance) diff --git a/kclvm/spec/gpyrpc/gpyrpc.proto b/kclvm/spec/gpyrpc/gpyrpc.proto index 0dc914a20..e7c026a91 100644 --- a/kclvm/spec/gpyrpc/gpyrpc.proto +++ b/kclvm/spec/gpyrpc/gpyrpc.proto @@ -477,6 +477,7 @@ message KclType { string pkg_path = 13; // `pkg_path` represents the path name of the package where the attribute is located. string description = 14; // `description` represents the document of the attribute. map examples = 15; // A map object to hold examples, the key is the example name. + KclType base_schema = 16; } message Decorator { From 28720f8087eb21a6455ebeda67f148473305491d Mon Sep 17 00:00:00 2001 From: utnim2 Date: Sat, 4 May 2024 05:41:11 +0530 Subject: [PATCH 2/3] added the recursive function Signed-off-by: utnim2 --- kclvm/query/src/query.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kclvm/query/src/query.rs b/kclvm/query/src/query.rs index f71f0e39a..6646ac980 100644 --- a/kclvm/query/src/query.rs +++ b/kclvm/query/src/query.rs @@ -189,6 +189,14 @@ pub fn get_full_schema_type( Ok(result) } +fn get_full_schema_type_recursive(schema_ty: SchemaType) -> Result { + let mut result = schema_ty; + if let Some(base) = result.base { + result.base = Some(Box::new(get_full_schema_type_recursive(*base)?)); + } + Ok(result) +} + fn resolve_file(opts: &CompilationOptions) -> Result>> { let sess = Arc::new(ParseSession::default()); let mut program = match load_program( From 857a684323dc172e915a97f6e9c911c6d18f3eb3 Mon Sep 17 00:00:00 2001 From: utnim2 Date: Sat, 4 May 2024 13:28:37 +0530 Subject: [PATCH 3/3] fixed the types Signed-off-by: utnim2 --- kclvm/api/src/service/ty.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kclvm/api/src/service/ty.rs b/kclvm/api/src/service/ty.rs index 83fff2350..f171d46eb 100644 --- a/kclvm/api/src/service/ty.rs +++ b/kclvm/api/src/service/ty.rs @@ -51,7 +51,10 @@ pub(crate) fn kcl_schema_ty_to_pb_ty(schema_ty: &SchemaType) -> KclType { filename: schema_ty.filename.clone(), pkg_path: schema_ty.pkgpath.clone(), description: schema_ty.doc.clone(), - base_schema: schema_ty.base.as_ref().map(|base| kcl_schema_ty_to_pb_ty(base)), + base_schema: schema_ty + .base + .as_ref() + .map(|base| Box::new(kcl_schema_ty_to_pb_ty(&**base))), ..Default::default() } }