From 81ae72ffe904d63f6f1dfb5f7e9368d60b58e1c3 Mon Sep 17 00:00:00 2001 From: zongz Date: Thu, 23 Nov 2023 13:49:55 +0800 Subject: [PATCH] feat: fix CR comments Signed-off-by: zongz --- kclvm/api/src/service/capi.rs | 2 +- kclvm/api/src/service/service_impl.rs | 4 +-- .../src/testdata/get-full-schema-type.json | 2 +- kclvm/query/src/query.rs | 31 +++++++++++++++++++ .../src/test_data/get_schema_ty/aaa/kcl.mod | 5 +++ .../src/test_data/get_schema_ty/aaa/main.k | 5 +++ .../src/test_data/get_schema_ty/bbb/kcl.mod | 5 +++ .../src/test_data/get_schema_ty/bbb/main.k | 2 ++ kclvm/spec/gpyrpc/gpyrpc.proto | 2 +- 9 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 kclvm/query/src/test_data/get_schema_ty/aaa/kcl.mod create mode 100644 kclvm/query/src/test_data/get_schema_ty/aaa/main.k create mode 100644 kclvm/query/src/test_data/get_schema_ty/bbb/kcl.mod create mode 100644 kclvm/query/src/test_data/get_schema_ty/bbb/main.k diff --git a/kclvm/api/src/service/capi.rs b/kclvm/api/src/service/capi.rs index 5c4856f07..cab3d29f3 100644 --- a/kclvm/api/src/service/capi.rs +++ b/kclvm/api/src/service/capi.rs @@ -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] +/// `exec_args`: [Option] /// the items and compile parameters selected by the user in the KCL CLI /// serialized as protobuf byte sequence /// diff --git a/kclvm/api/src/service/service_impl.rs b/kclvm/api/src/service/service_impl.rs index 0288c8087..bf5ea86cd 100644 --- a/kclvm/api/src/service/service_impl.rs +++ b/kclvm/api/src/service/service_impl.rs @@ -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); @@ -240,7 +240,7 @@ impl KclvmServiceImpl { &self, args: &GetFullSchemaTypeArgs, ) -> anyhow::Result { - 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(); diff --git a/kclvm/api/src/testdata/get-full-schema-type.json b/kclvm/api/src/testdata/get-full-schema-type.json index 55601b793..176db0716 100644 --- a/kclvm/api/src/testdata/get-full-schema-type.json +++ b/kclvm/api/src/testdata/get-full-schema-type.json @@ -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" diff --git a/kclvm/query/src/query.rs b/kclvm/query/src/query.rs index 0cfd96503..5cbc1989d 100644 --- a/kclvm/query/src/query.rs +++ b/kclvm/query/src/query.rs @@ -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, diff --git a/kclvm/query/src/test_data/get_schema_ty/aaa/kcl.mod b/kclvm/query/src/test_data/get_schema_ty/aaa/kcl.mod new file mode 100644 index 000000000..1e29d9eb2 --- /dev/null +++ b/kclvm/query/src/test_data/get_schema_ty/aaa/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "aaa" +edition = "0.0.1" +version = "0.0.1" + diff --git a/kclvm/query/src/test_data/get_schema_ty/aaa/main.k b/kclvm/query/src/test_data/get_schema_ty/aaa/main.k new file mode 100644 index 000000000..e2c858985 --- /dev/null +++ b/kclvm/query/src/test_data/get_schema_ty/aaa/main.k @@ -0,0 +1,5 @@ +import bbb as b + +a = b.B { + name: "b instance in a" +} \ No newline at end of file diff --git a/kclvm/query/src/test_data/get_schema_ty/bbb/kcl.mod b/kclvm/query/src/test_data/get_schema_ty/bbb/kcl.mod new file mode 100644 index 000000000..e9ea10a52 --- /dev/null +++ b/kclvm/query/src/test_data/get_schema_ty/bbb/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "bbb" +edition = "0.0.1" +version = "0.0.1" + diff --git a/kclvm/query/src/test_data/get_schema_ty/bbb/main.k b/kclvm/query/src/test_data/get_schema_ty/bbb/main.k new file mode 100644 index 000000000..21dad4f9e --- /dev/null +++ b/kclvm/query/src/test_data/get_schema_ty/bbb/main.k @@ -0,0 +1,2 @@ +schema B: + name: str \ No newline at end of file diff --git a/kclvm/spec/gpyrpc/gpyrpc.proto b/kclvm/spec/gpyrpc/gpyrpc.proto index e9017a4f1..40eb391ed 100644 --- a/kclvm/spec/gpyrpc/gpyrpc.proto +++ b/kclvm/spec/gpyrpc/gpyrpc.proto @@ -215,7 +215,7 @@ message OverrideFile_Result { } message GetFullSchemaType_Args { - ExecProgram_Args exec_options = 1; + ExecProgram_Args exec_args = 1; string schema_name = 2; }