From 2021b34f537846ae6223540ce97a7cfa479c3c03 Mon Sep 17 00:00:00 2001 From: "xiarui.xr" Date: Mon, 11 Sep 2023 11:20:22 +0800 Subject: [PATCH] chore: code style and format code --- kclvm/api/src/service/ty.rs | 4 ++-- kclvm/sema/src/resolver/doc.rs | 31 +++++++++++++++++++++++++------ kclvm/sema/src/resolver/mod.rs | 2 +- kclvm/sema/src/ty/mod.rs | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/kclvm/api/src/service/ty.rs b/kclvm/api/src/service/ty.rs index ebdf1cba6..37f05ffd9 100644 --- a/kclvm/api/src/service/ty.rs +++ b/kclvm/api/src/service/ty.rs @@ -1,4 +1,4 @@ -use crate::gpyrpc::{Decorator, KclType, Example}; +use crate::gpyrpc::{Decorator, Example, KclType}; use indexmap::IndexSet; use kclvm_runtime::SCHEMA_SETTINGS_ATTR_NAME; use kclvm_sema::ty::{DictType, SchemaType, Type}; @@ -62,7 +62,7 @@ fn get_schema_ty_examples(schema_ty: &SchemaType) -> HashMap { let exa = Example { summary: example.summary.clone(), description: example.description.clone(), - value: example.value.clone() + value: example.value.clone(), }; examples.insert(key.clone(), exa); } diff --git a/kclvm/sema/src/resolver/doc.rs b/kclvm/sema/src/resolver/doc.rs index 020ad6abd..72d398151 100644 --- a/kclvm/sema/src/resolver/doc.rs +++ b/kclvm/sema/src/resolver/doc.rs @@ -1,5 +1,5 @@ use pcre2::bytes::Regex; -use std::collections::{HashSet, HashMap}; +use std::collections::{HashMap, HashSet}; use std::iter::Iterator; use std::str; @@ -281,7 +281,10 @@ pub(crate) fn parse_doc_string(ori: &String) -> Doc { 0 | 1 | 2 => "".to_string(), _ => example_section[2..].join("\n"), }; - examples.insert("Default example".to_string(), Example::new("".to_string(), "".to_string(), default_example_content)); + examples.insert( + "Default example".to_string(), + Example::new("".to_string(), "".to_string(), default_example_content), + ); } Doc::new(summary, attrs, examples) } @@ -296,7 +299,11 @@ pub(crate) struct Doc { impl Doc { fn new(summary: String, attrs: Vec, examples: HashMap) -> Self { - Self { summary, attrs, examples: examples } + Self { + summary, + attrs, + examples, + } } } @@ -323,7 +330,11 @@ pub struct Example { impl Example { fn new(summary: String, description: String, value: String) -> Self { - Self { summary, description, value } + Self { + summary, + description, + value, + } } } @@ -611,8 +622,16 @@ unindented line ] ); assert!(doc.examples.contains_key("Default example")); - assert_eq!(doc.examples.get("Default example"), Some(&Example::new("".to_string(), "".to_string(), "myCustomApp = AppConfiguration { + assert_eq!( + doc.examples.get("Default example"), + Some(&Example::new( + "".to_string(), + "".to_string(), + "myCustomApp = AppConfiguration { name = \"componentName\" -}".to_string()))); +}" + .to_string() + )) + ); } } diff --git a/kclvm/sema/src/resolver/mod.rs b/kclvm/sema/src/resolver/mod.rs index 3394d0a82..a5253e089 100644 --- a/kclvm/sema/src/resolver/mod.rs +++ b/kclvm/sema/src/resolver/mod.rs @@ -26,10 +26,10 @@ use crate::lint::{CombinedLintPass, Linter}; use crate::pre_process::pre_process_program; use crate::resolver::scope::ScopeObject; use crate::resolver::ty_alias::process_program_type_alias; +use crate::ty::TypeContext; use crate::{resolver::scope::Scope, ty::SchemaType}; use kclvm_ast::ast::Program; use kclvm_error::*; -use crate::ty::TypeContext; use self::scope::{builtin_scope, ProgramScope}; diff --git a/kclvm/sema/src/ty/mod.rs b/kclvm/sema/src/ty/mod.rs index 463bbc36d..81832505e 100644 --- a/kclvm/sema/src/ty/mod.rs +++ b/kclvm/sema/src/ty/mod.rs @@ -178,7 +178,7 @@ pub struct SchemaType { /// The schema definition document string. pub doc: String, /// The code snippets of the schema usage examples - pub examples: HashMap, + pub examples: HashMap, /// Indicates whether the schema is a type of a instance or /// a type (value). Besides, it is necessary to distinguish /// between a type instance and a type value, such as the following code: