From dcd481d84408ebecc80a3af8a20230ee01aef035 Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 7 Nov 2023 13:03:31 +0800 Subject: [PATCH] feat: deprecated schema sematic settings attr Signed-off-by: peefy --- kclvm/sema/src/resolver/global.rs | 17 ------------- kclvm/tools/src/LSP/src/completion.rs | 35 ++++++++++++++------------- kclvm/tools/src/LSP/src/hover.rs | 10 ++------ kclvm/tools/src/LSP/src/tests.rs | 7 ++---- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/kclvm/sema/src/resolver/global.rs b/kclvm/sema/src/resolver/global.rs index 6ea805ab1..52f71a60d 100644 --- a/kclvm/sema/src/resolver/global.rs +++ b/kclvm/sema/src/resolver/global.rs @@ -568,23 +568,6 @@ impl<'ctx> Resolver<'ctx> { }; // Schema attributes let mut attr_obj_map: IndexMap = IndexMap::default(); - let settings_dummy_pos = Position { - filename: self.ctx.filename.clone(), - line: pos.line, - column: pos.column, - }; - attr_obj_map.insert( - kclvm_runtime::SCHEMA_SETTINGS_ATTR_NAME.to_string(), - SchemaAttr { - is_optional: true, - has_default: false, - default: None, - ty: Type::dict_ref(self.str_ty(), self.any_ty()), - range: (settings_dummy_pos.clone(), settings_dummy_pos), - doc: None, - decorators: vec![], - }, - ); let parsed_doc = parse_doc_string( &schema_stmt .doc diff --git a/kclvm/tools/src/LSP/src/completion.rs b/kclvm/tools/src/LSP/src/completion.rs index 45f9daff6..fd7456a1b 100644 --- a/kclvm/tools/src/LSP/src/completion.rs +++ b/kclvm/tools/src/LSP/src/completion.rs @@ -533,18 +533,16 @@ pub(crate) fn get_dot_completion( // ``` kclvm_sema::ty::TypeKind::Schema(schema) => { for (name, attr) in &schema.attrs { - if name != "__settings__" { - items.insert(KCLCompletionItem { - label: name.clone(), - detail: Some(format!( - "{}: {}", - name, - attr.ty.ty_str() - )), - documentation: attr.doc.clone(), - kind: Some(KCLCompletionItemKind::SchemaAttr), - }); - } + items.insert(KCLCompletionItem { + label: name.clone(), + detail: Some(format!( + "{}: {}", + name, + attr.ty.ty_str() + )), + documentation: attr.doc.clone(), + kind: Some(KCLCompletionItemKind::SchemaAttr), + }); } } @@ -748,7 +746,7 @@ mod tests { CompletionResponse::List(_) => panic!("test failed"), }; - expected_labels.extend(["__settings__", "name", "age"]); + expected_labels.extend(["name", "age"]); assert_eq!(got_labels, expected_labels); } @@ -871,7 +869,7 @@ mod tests { CompletionResponse::List(_) => panic!("test failed"), }; - let expected_labels: Vec<&str> = vec!["__settings__", "a"]; + let expected_labels: Vec<&str> = vec!["a"]; assert_eq!(got_labels, expected_labels); } @@ -995,7 +993,7 @@ mod tests { CompletionResponse::List(_) => panic!("test failed"), }; - let expected_labels: Vec<&str> = vec!["__settings__", "a"]; + let expected_labels: Vec<&str> = vec!["a"]; assert_eq!(got_labels, expected_labels); } @@ -1162,8 +1160,11 @@ mod tests { arr[1], CompletionItem { label: "Person(b){}".to_string(), - kind: Some(CompletionItemKind:: CLASS), - detail: Some("__main__\n\nschema Person[b: int](Base)\nAttributes:\n__settings__?: {str:any}\nc: int".to_string()), + kind: Some(CompletionItemKind::CLASS), + detail: Some( + "__main__\n\nschema Person[b: int](Base)\nAttributes:\nc: int" + .to_string() + ), documentation: Some(lsp_types::Documentation::String("".to_string())), ..Default::default() } diff --git a/kclvm/tools/src/LSP/src/hover.rs b/kclvm/tools/src/LSP/src/hover.rs index 407f5c568..03d08791d 100644 --- a/kclvm/tools/src/LSP/src/hover.rs +++ b/kclvm/tools/src/LSP/src/hover.rs @@ -179,10 +179,7 @@ mod tests { assert_eq!(s, "hover doc test"); } if let MarkedString::String(s) = vec[2].clone() { - assert_eq!( - s, - "Attributes:\n\n__settings__?: {str:any}\n\nname: str\n\nage: int" - ); + assert_eq!(s, "Attributes:\n\nname: str\n\nage: int"); } } _ => unreachable!("test error"), @@ -225,10 +222,7 @@ mod tests { assert_eq!(s, "hover doc test"); } if let MarkedString::String(s) = vec[2].clone() { - assert_eq!( - s, - "Attributes:\n\n__settings__?: {str:any}\n\nname: str\n\nage?: int" - ); + assert_eq!(s, "Attributes:\n\nname: str\n\nage?: int"); } } _ => unreachable!("test error"), diff --git a/kclvm/tools/src/LSP/src/tests.rs b/kclvm/tools/src/LSP/src/tests.rs index c258c335e..121d272eb 100644 --- a/kclvm/tools/src/LSP/src/tests.rs +++ b/kclvm/tools/src/LSP/src/tests.rs @@ -850,9 +850,7 @@ fn hover_test() { contents: HoverContents::Array(vec![ MarkedString::String("__main__\n\nschema Person".to_string()), MarkedString::String("hover doc test".to_string()), - MarkedString::String( - "Attributes:\n\n__settings__?: {str:any}\n\nname: str\n\nage?: int".to_string() - ), + MarkedString::String("Attributes:\n\nname: str\n\nage?: int".to_string()), ]), range: None }) @@ -1225,7 +1223,6 @@ fn konfig_completion_test_main() { "kubevela_output", "server_output", "schedulingStrategy", - "__settings__", "name", "workloadType", "renderType", @@ -1310,7 +1307,7 @@ fn konfig_hover_test_main() { let expect: Vec = vec![ "base.pkg.kusion_models.kube.frontend\n\nschema Server", "Server is abstaction of Deployment and StatefulSet.", - "Attributes:\n\n__settings__?: {str:any}\n\nname?: str\n\nworkloadType: str(Deployment) | str(StatefulSet)\n\nrenderType?: str(Server) | str(KubeVelaApplication)\n\nreplicas: int\n\nimage: str\n\nschedulingStrategy: SchedulingStrategy\n\nmainContainer: Main\n\nsidecarContainers?: [Sidecar]\n\ninitContainers?: [Sidecar]\n\nuseBuiltInLabels?: bool\n\nlabels?: {str:str}\n\nannotations?: {str:str}\n\nuseBuiltInSelector?: bool\n\nselector?: {str:str}\n\npodMetadata?: ObjectMeta\n\nvolumes?: [Volume]\n\nneedNamespace?: bool\n\nenableMonitoring?: bool\n\nconfigMaps?: [ConfigMap]\n\nsecrets?: [Secret]\n\nservices?: [Service]\n\ningresses?: [Ingress]\n\nserviceAccount?: ServiceAccount\n\nstorage?: ObjectStorage\n\ndatabase?: DataBase" + "Attributes:\n\nname?: str\n\nworkloadType: str(Deployment) | str(StatefulSet)\n\nrenderType?: str(Server) | str(KubeVelaApplication)\n\nreplicas: int\n\nimage: str\n\nschedulingStrategy: SchedulingStrategy\n\nmainContainer: Main\n\nsidecarContainers?: [Sidecar]\n\ninitContainers?: [Sidecar]\n\nuseBuiltInLabels?: bool\n\nlabels?: {str:str}\n\nannotations?: {str:str}\n\nuseBuiltInSelector?: bool\n\nselector?: {str:str}\n\npodMetadata?: ObjectMeta\n\nvolumes?: [Volume]\n\nneedNamespace?: bool\n\nenableMonitoring?: bool\n\nconfigMaps?: [ConfigMap]\n\nsecrets?: [Secret]\n\nservices?: [Service]\n\ningresses?: [Ingress]\n\nserviceAccount?: ServiceAccount\n\nstorage?: ObjectStorage\n\ndatabase?: DataBase" ] .iter() .map(|s| MarkedString::String(s.to_string()))