Skip to content

Commit

Permalink
feat: fix CR comments
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <[email protected]>
  • Loading branch information
zong-zhe committed Nov 23, 2023
1 parent 032b145 commit 81ae72f
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion kclvm/api/src/service/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub(crate) fn get_schema_type(serv: *mut kclvm_service, args: *const c_char) ->
/// Get full schema types from a kcl file or code.
///
/// # Parameters
/// `exec_options`: [Option<ExecProgramArgs>]
/// `exec_args`: [Option<ExecProgramArgs>]
/// the items and compile parameters selected by the user in the KCL CLI
/// serialized as protobuf byte sequence
///
Expand Down
4 changes: 2 additions & 2 deletions kclvm/api/src/service/service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl KclvmServiceImpl {
/// };
///
/// let result = serv.get_full_schema_type(&GetFullSchemaTypeArgs {
/// exec_options: Some(args),
/// exec_args: Some(args),
/// schema_name: "a".to_string()
/// }).unwrap();
/// assert_eq!(result.schema_type_list.len(), 1);
Expand All @@ -240,7 +240,7 @@ impl KclvmServiceImpl {
&self,
args: &GetFullSchemaTypeArgs,
) -> anyhow::Result<GetSchemaTypeResult> {
let args_json = serde_json::to_string(&args.exec_options.clone().unwrap()).unwrap();
let args_json = serde_json::to_string(&args.exec_args.clone().unwrap()).unwrap();

let mut type_list = Vec::new();

Expand Down
2 changes: 1 addition & 1 deletion kclvm/api/src/testdata/get-full-schema-type.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exec_options": {
"exec_args": {
"work_dir" : "./src/testdata/get_schema_ty/aaa",
"k_filename_list":[
"./src/testdata/get_schema_ty/aaa/main.k"
Expand Down
31 changes: 31 additions & 0 deletions kclvm/query/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,37 @@ pub struct CompilationOptions {
pub get_schema_opts: GetSchemaOption,
}

/// Service for getting the full schema type list.
///
/// # Examples
///
/// ```
/// use kclvm_parser::LoadProgramOptions;
/// use kclvm_query::query::CompilationOptions;
/// use kclvm_query::query::get_full_schema_type;
/// use std::path::Path;
/// use maplit::hashmap;
///
/// let work_dir_parent = Path::new(".").join("src").join("test_data").join("get_schema_ty");
///
/// let result = get_full_schema_type(
/// Some("a"),
/// CompilationOptions {
/// k_files: vec![
/// work_dir_parent.join("aaa").join("main.k").canonicalize().unwrap().display().to_string()
/// ],
/// loader_opts: Some(LoadProgramOptions {
/// work_dir: work_dir_parent.join("aaa").canonicalize().unwrap().display().to_string(),
/// package_maps: hashmap!{
/// "bbb".to_string() => work_dir_parent.join("bbb").canonicalize().unwrap().display().to_string(),
/// },
/// ..Default::default()
/// }),
/// ..Default::default()
/// }
/// ).unwrap();
/// assert_eq!(result.len(), 1);
/// ```
pub fn get_full_schema_type(
schema_name: Option<&str>,
opts: CompilationOptions,
Expand Down
5 changes: 5 additions & 0 deletions kclvm/query/src/test_data/get_schema_ty/aaa/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "aaa"
edition = "0.0.1"
version = "0.0.1"

5 changes: 5 additions & 0 deletions kclvm/query/src/test_data/get_schema_ty/aaa/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import bbb as b

a = b.B {
name: "b instance in a"
}
5 changes: 5 additions & 0 deletions kclvm/query/src/test_data/get_schema_ty/bbb/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "bbb"
edition = "0.0.1"
version = "0.0.1"

2 changes: 2 additions & 0 deletions kclvm/query/src/test_data/get_schema_ty/bbb/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema B:
name: str
2 changes: 1 addition & 1 deletion kclvm/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ message OverrideFile_Result {
}

message GetFullSchemaType_Args {
ExecProgram_Args exec_options = 1;
ExecProgram_Args exec_args = 1;
string schema_name = 2;
}

Expand Down

0 comments on commit 81ae72f

Please sign in to comment.