Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_schema_type function will now return SchemaType instances with base schema information included #1272

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kclvm/api/src/service/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +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| Box::new(kcl_schema_ty_to_pb_ty(&**base))),
..Default::default()
}
}
Expand Down
13 changes: 12 additions & 1 deletion kclvm/query/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -186,6 +189,14 @@ pub fn get_full_schema_type(
Ok(result)
}

fn get_full_schema_type_recursive(schema_ty: SchemaType) -> Result<SchemaType> {
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<Rc<RefCell<Scope>>> {
let sess = Arc::new(ParseSession::default());
let mut program = match load_program(
Expand Down
1 change: 1 addition & 0 deletions kclvm/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Example> examples = 15; // A map object to hold examples, the key is the example name.
KclType base_schema = 16;
}

message Decorator {
Expand Down
Loading