Repository: kcl-lang/kcl (language: rust)

Issue:
[WIP] Feat : Support Call Kclvm Cli by C API
<!-- Thank you for contributing to KusionStack!

Note: 

1. With pull requests:

    - Open your pull request against "main"
    - Your pull request should have no more than two commits, if not you should squash them.
    - It should pass all tests in the available continuous integration systems such as GitHub Actions.
    - You should add/modify tests to cover your proposed code changes.
    - If your pull request contains a new feature, please document it on the README.

2. Please create an issue first to describe the problem.

    We recommend that link the issue with the PR in the following question.
    For more info, check https://kusionstack.io/docs/governance/contribute/
-->

#### 1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

- [ ] N
- [x] Y 
re #125 

#### 2. What is the scope of this PR (e.g. component or file name):

<!-- You can add the scope of this change here. 
-->
        KCLVM/kclvm/spec
        KCLVM/kclvm/src/lib.rs

#### 3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

<!-- You can choose a brief description here -->
- [ ] Affects user behaviors
- [ ] Contains syntax changes
- [ ] Contains variable changes
- [x] Contains experimental features
- [ ] Performance regression: Consumes more CPU
- [ ] Performance regression: Consumes more Memory
- [ ] Other

<!-- You can add more details here.
-->
    Support user to call kclvm_cli by c_api


#### 4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

- [x] N
- [ ] Y 

<!-- You can add more details here.

-->

#### 5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

<!-- You can choose a brief description here -->
- [x] Unit test
- [ ] Integration test
- [ ] Benchmark (add benchmark stats below)
- [ ] Manual test (add detailed scripts or steps below)
- [ ] Other

<!-- You can add more details here.
None
-->
KCLVM/kclvm/src/api_test.rs

#### 6. Release note

<!-- compatibility change, improvement, bugfix, and new feature need a release note -->

Please refer to [Release Notes Language Style Guide](https://kusionstack.io/docs/governance/release-policy/) to write a quality release note.

```release-note
None
```



Discussion / hints:
****CLA Assistant Lite bot**** All contributors have signed the CLA  ✍️ ✅
I have read the CLA Document and I hereby sign the CLA
## Pull Request Test Coverage Report for [Build 2744948016](https://coveralls.io/builds/51191024)

* **2** of **5523**   **(0.04%)**  changed or added relevant lines in **6** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage decreased (**-7.6%**) to **51.731%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [kclvm/spec/src/main.rs](https://coveralls.io/builds/51191024/source?filename=kclvm%2Fspec%2Fsrc%2Fmain.rs#L2) | 1 | 3 | 33.33%
| [kclvm/spec/src/service/util.rs](https://coveralls.io/builds/51191024/source?filename=kclvm%2Fspec%2Fsrc%2Fservice%2Futil.rs#L2) | 0 | 25 | 0.0%
| [kclvm/spec/src/service/service.rs](https://coveralls.io/builds/51191024/source?filename=kclvm%2Fspec%2Fsrc%2Fservice%2Fservice.rs#L10) | 0 | 109 | 0.0%
| [kclvm/spec/src/service/api.rs](https://coveralls.io/builds/51191024/source?filename=kclvm%2Fspec%2Fsrc%2Fservice%2Fapi.rs#L10) | 0 | 153 | 0.0%
| [kclvm/spec/src/model/gpyrpc.rs](https://coveralls.io/builds/51191024/source?filename=kclvm%2Fspec%2Fsrc%2Fmodel%2Fgpyrpc.rs#L28) | 0 | 5232 | 0.0%
<!-- | **Total:** | **2** | **5523** | **0.04%** | -->


|  Totals | [![Coverage Status](https://coveralls.io/builds/51191024/badge)](https://coveralls.io/builds/51191024) |
| :-- | --: |
| Change from base [Build 2743999583](https://coveralls.io/builds/51186839): |  -7.6% |
| Covered Lines: | 22244 |
| Relevant Lines: | 42999 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Fix patch:
diff --git a/kclvm/tools/src/LSP/src/hover.rs b/kclvm/tools/src/LSP/src/hover.rs
index c69c19b40..8c77fd0ac 100644
--- a/kclvm/tools/src/LSP/src/hover.rs
+++ b/kclvm/tools/src/LSP/src/hover.rs
@@ -77,6 +77,17 @@ pub fn hover(kcl_pos: &KCLPos, gs: &GlobalState) -> Option<lsp_types::Hover> {
 
                         if !schema_ty.doc.is_empty() {
                             docs.push((schema_ty.doc.clone(), MarkedStringType::String));
+
+                            // Add examples to the hover content
+                            if !schema_ty.examples.is_empty() {
+                                let examples = schema_ty
+                                    .examples
+                                    .iter()
+                                    .map(|(_, example)| format!("{}\n", example.value))
+                                    .collect::<Vec<String>>()
+                                    .join("\n");
+                                docs.push((examples, MarkedStringType::LanguageString));
+                            }
                         }
                     }
                     _ => {}
@@ -777,4 +788,41 @@ mod tests {
             }));
         assert_eq!(got.contents, expected);
     }
+
+    #[test]
+    #[bench_test]
+    fn schema_doc_with_examples_hover_test() {
+        let (file, _program, _, gs, _) =
+            compile_test_file("src/test_data/hover_test/schema_with_examples.k");
+
+        let pos = KCLPos {
+            filename: file.clone(),
+            line: 1,
+            column: Some(8),
+        };
+        let got = hover(&pos, &gs).unwrap();
+
+        let expect_content = vec![
+            lsp_types::MarkedString::String("__main__".to_string()),
+            lsp_types::MarkedString::LanguageString(lsp_types::LanguageString {
+                language: "KCL".to_string(),
+                value: "schema Server:\n    workloadType: str = \"Deployment\"\n    name: str\n    labels?: {str:str}".to_string(),
+            }),
+            lsp_types::MarkedString::String("Server is an abstraction of Deployment and StatefulSet.".to_string()),
+            lsp_types::MarkedString::LanguageString(lsp_types::LanguageString {
+                language: "KCL".to_string(),
+                value: "import models.kube.frontend\nimport models.kube.frontend.container\nimport models.kube.templates.resource as res_tpl\n\nappConfiguration: frontend.Server {\n    mainContainer = container.Main {\n        name = \"php-redis\"\n        env: {\n            \"GET_HOSTS_FROM\": {value = \"dns\"}\n        }\n    }\n}\n".to_string()
+            }),
+        ];
+
+        match got.contents {
+            lsp_types::HoverContents::Array(vec) => {
+                assert_eq!(vec.len(), expect_content.len());
+                for (i, expected) in expect_content.iter().enumerate() {
+                    assert_eq!(&vec[i], expected);
+                }
+            }
+            _ => unreachable!("test error"),
+        }
+    }
 }


Test patch:
diff --git a/kclvm/tools/src/LSP/src/test_data/hover_test/schema_with_examples.k b/kclvm/tools/src/LSP/src/test_data/hover_test/schema_with_examples.k
new file mode 100644
index 000000000..94064b785
--- /dev/null
+++ b/kclvm/tools/src/LSP/src/test_data/hover_test/schema_with_examples.k
@@ -0,0 +1,31 @@
+schema Server:
+    """Server is an abstraction of Deployment and StatefulSet.
+
+    Attributes
+    ----------
+    workloadType : str, default is "Deployment", required
+        Use this attribute to specify which kind of long-running service you want.
+        Valid values: Deployment, StatefulSet.
+    name : str, required
+        The name of the long-running service.
+    labels : {str:str}, optional
+        The labels of the long-running service.
+
+    Examples
+    --------
+    import models.kube.frontend
+    import models.kube.frontend.container
+    import models.kube.templates.resource as res_tpl
+    
+    appConfiguration: frontend.Server {
+        mainContainer = container.Main {
+            name = "php-redis"
+            env: {
+                "GET_HOSTS_FROM": {value = "dns"}
+            }
+        }
+    }
+    """
+    workloadType : str = "Deployment"
+    name: str
+    labels?: {str: str}
diff --git a/kclvm/tools/src/LSP/src/tests.rs b/kclvm/tools/src/LSP/src/tests.rs
index 6143fb414..c786436fd 100644
--- a/kclvm/tools/src/LSP/src/tests.rs
+++ b/kclvm/tools/src/LSP/src/tests.rs
@@ -2006,6 +2006,10 @@ fn konfig_hover_test_main() {
                     value: "schema Server:\n    name?: str\n    workloadType: \"Deployment\" | \"StatefulSet\" = \"Deployment\"\n    renderType?: \"Server\" | \"KubeVelaApplication\" = \"Server\"\n    replicas: int = option(\"replicas\") or 1\n    image: str = option(\"image\")\n    schedulingStrategy: SchedulingStrategy = strategy.SchedulingStrategy {}\n    mainContainer: Main\n    sidecarContainers?: [Sidecar]\n    initContainers?: [Sidecar]\n    useBuiltInLabels?: bool = True\n    labels?: {str:str}\n    annotations?: {str:str}\n    useBuiltInSelector?: bool = True\n    selector?: {str:str}\n    podMetadata?: ObjectMeta\n    volumes?: [Volume]\n    needNamespace?: bool = True\n    enableMonitoring?: bool = False\n    configMaps?: [ConfigMap]\n    secrets?: [Secret]\n    services?: [Service]\n    ingresses?: [Ingress]\n    serviceAccount?: ServiceAccount\n    storage?: ObjectStorage\n    database?: DataBase".to_string()
                 }),
                 MarkedString::String("Server is abstaction of Deployment and StatefulSet.".to_string()),
+                MarkedString::LanguageString(lsp_types::LanguageString {
+                    language: "KCL".to_string(),
+                    value: "import base.pkg.kusion_models.kube.frontend\nimport base.pkg.kusion_models.kube.frontend.container\nimport base.pkg.kusion_models.kube.templates.resource as res_tpl\n\nappConfiguration: frontend.Server {\n    mainContainer = container.Main {\n        name = \"php-redis\"\n        env = [\n            {\n                name = \"GET_HOSTS_FROM\"\n                value = \"dns\"\n            }\n        ]\n        ports = [{containerPort = 80}]\n    }\n    selector = {\n        tier = \"frontend\"\n    }\n    podMetadata.labels: {\n        tier = \"frontend\"\n    }\n    schedulingStrategy.resource = res_tpl.tiny\n}\n".to_string()
+                }),
             ];
             assert_eq!(expect, arr);
         }