diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index d7910d7e7..c63fb1d31 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -1407,7 +1407,6 @@ dependencies = [ "im-rc", "indexmap 1.9.3", "kclvm-ast", - "kclvm-compiler", "kclvm-config", "kclvm-driver", "kclvm-error", diff --git a/kclvm/compiler/src/codegen/llvm/context.rs b/kclvm/compiler/src/codegen/llvm/context.rs index 923984083..feec66f67 100644 --- a/kclvm/compiler/src/codegen/llvm/context.rs +++ b/kclvm/compiler/src/codegen/llvm/context.rs @@ -26,6 +26,7 @@ use kclvm_ast::walker::TypedResultWalker; use kclvm_error::*; use kclvm_runtime::{ApiFunc, MAIN_PKG_PATH, PKG_PATH_PREFIX}; use kclvm_sema::builtin; +use kclvm_sema::pkgpath_without_prefix; use kclvm_sema::plugin; use crate::codegen::abi::Align; @@ -35,7 +36,6 @@ use crate::codegen::{ PKG_INIT_FUNCTION_SUFFIX, }; use crate::codegen::{CodeGenContext, GLOBAL_LEVEL}; -use crate::pkgpath_without_prefix; use crate::value; use super::OBJECT_FILE_SUFFIX; diff --git a/kclvm/compiler/src/codegen/llvm/node.rs b/kclvm/compiler/src/codegen/llvm/node.rs index d68ff9f0f..e5869e169 100644 --- a/kclvm/compiler/src/codegen/llvm/node.rs +++ b/kclvm/compiler/src/codegen/llvm/node.rs @@ -11,13 +11,14 @@ use inkwell::{AddressSpace, IntPredicate}; use kclvm_ast::ast::{self, CallExpr, ConfigEntry, NodeRef}; use kclvm_ast::walker::TypedResultWalker; use kclvm_runtime::{ApiFunc, PKG_PATH_PREFIX}; +use kclvm_sema::pkgpath_without_prefix; +use crate::check_backtrack_stop; use crate::codegen::error as kcl_error; use crate::codegen::llvm::context::BacktrackMeta; use crate::codegen::llvm::utils; use crate::codegen::traits::*; use crate::codegen::{ENTRY_NAME, GLOBAL_LEVEL, INNER_LEVEL, PKG_INIT_FUNCTION_SUFFIX}; -use crate::{check_backtrack_stop, pkgpath_without_prefix}; use super::context::{CompileResult, LLVMCodeGenContext}; use crate::value; diff --git a/kclvm/compiler/src/codegen/llvm/schema.rs b/kclvm/compiler/src/codegen/llvm/schema.rs index 6c4bb2b93..dc994920f 100644 --- a/kclvm/compiler/src/codegen/llvm/schema.rs +++ b/kclvm/compiler/src/codegen/llvm/schema.rs @@ -3,6 +3,7 @@ use inkwell::values::{BasicValueEnum, FunctionValue}; use inkwell::AddressSpace; use kclvm_ast::ast; +use kclvm_sema::pkgpath_without_prefix; use std::collections::HashMap; use std::str; @@ -11,8 +12,6 @@ use crate::codegen::error as kcl_error; use crate::codegen::traits::{BuilderMethods, DerivedValueCalculationMethods, ValueMethods}; use crate::value; -use crate::pkgpath_without_prefix; - impl<'ctx> LLVMCodeGenContext<'ctx> { /// Emit all schema left identifiers because all the schema attribute can be forward referenced pub fn emit_schema_left_identifiers( diff --git a/kclvm/compiler/src/macros.rs b/kclvm/compiler/src/macros.rs index cc47ea8c4..68fe9492d 100644 --- a/kclvm/compiler/src/macros.rs +++ b/kclvm/compiler/src/macros.rs @@ -10,13 +10,3 @@ macro_rules! check_backtrack_stop { } }; } - -#[macro_export] -macro_rules! pkgpath_without_prefix { - ($pkgpath: expr) => { - match $pkgpath.strip_prefix('@') { - Some(v) => v.to_string(), - None => $pkgpath.to_string(), - } - }; -} diff --git a/kclvm/runner/src/assembler.rs b/kclvm/runner/src/assembler.rs index 9b519cee3..6c3d95b58 100644 --- a/kclvm/runner/src/assembler.rs +++ b/kclvm/runner/src/assembler.rs @@ -372,7 +372,7 @@ impl KclvmAssembler { &code_file_path, )?; let lib_relative_path = file_path.replacen(root, ".", 1); - save_pkg_cache( + let _ = save_pkg_cache( root, &target, &pkgpath, diff --git a/kclvm/sema/src/lib.rs b/kclvm/sema/src/lib.rs index 7bba0f88d..3f119adbf 100644 --- a/kclvm/sema/src/lib.rs +++ b/kclvm/sema/src/lib.rs @@ -10,5 +10,8 @@ pub mod pre_process; pub mod resolver; pub mod ty; +#[macro_use] +mod macros; + #[macro_use] extern crate compiler_base_macros; diff --git a/kclvm/sema/src/macros.rs b/kclvm/sema/src/macros.rs new file mode 100644 index 000000000..8848527c2 --- /dev/null +++ b/kclvm/sema/src/macros.rs @@ -0,0 +1,11 @@ +//! Copyright The KCL Authors. All rights reserved. + +#[macro_export] +macro_rules! pkgpath_without_prefix { + ($pkgpath: expr) => { + match $pkgpath.strip_prefix('@') { + Some(v) => v.to_string(), + None => $pkgpath.to_string(), + } + }; +} diff --git a/kclvm/sema/src/resolver/global.rs b/kclvm/sema/src/resolver/global.rs index 6ea805ab1..dfd766793 100644 --- a/kclvm/sema/src/resolver/global.rs +++ b/kclvm/sema/src/resolver/global.rs @@ -470,7 +470,6 @@ impl<'ctx> Resolver<'ctx> { should_add_schema_ref: bool, ) -> SchemaType { let name = &schema_stmt.name.node; - let pos = schema_stmt.name.get_end_pos(); if RESERVED_TYPE_IDENTIFIERS.contains(&name.as_str()) { self.handler.add_compile_error( &format!( @@ -568,23 +567,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/Cargo.toml b/kclvm/tools/src/LSP/Cargo.toml index c1e0c43d8..b6f612da4 100644 --- a/kclvm/tools/src/LSP/Cargo.toml +++ b/kclvm/tools/src/LSP/Cargo.toml @@ -28,7 +28,6 @@ kclvm-parser = { path = "../../../parser" } kclvm-sema = { path = "../../../sema" } kclvm-ast = { path = "../../../ast" } kclvm-utils = { path = "../../../utils" } -kclvm-compiler = { path = "../../../compiler" } kclvm-version = { path = "../../../version" } compiler_base_session = { path = "../../../../compiler_base/session" } diff --git a/kclvm/tools/src/LSP/src/completion.rs b/kclvm/tools/src/LSP/src/completion.rs index 45f9daff6..5b061aa64 100644 --- a/kclvm/tools/src/LSP/src/completion.rs +++ b/kclvm/tools/src/LSP/src/completion.rs @@ -22,8 +22,8 @@ use indexmap::IndexSet; use kclvm_ast::ast::{Expr, ImportStmt, Node, Program, Stmt}; use kclvm_ast::pos::GetPos; use kclvm_ast::MAIN_PKG; -use kclvm_compiler::pkgpath_without_prefix; use kclvm_config::modfile::KCL_FILE_EXTENSION; +use kclvm_sema::pkgpath_without_prefix; use kclvm_error::Position as KCLPos; use kclvm_sema::builtin::{ @@ -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() } @@ -1189,7 +1190,7 @@ mod tests { match got { CompletionResponse::Array(arr) => { assert_eq!( - arr[1], + arr[0], CompletionItem { label: "c".to_string(), kind: Some(CompletionItemKind::FIELD), diff --git a/kclvm/tools/src/LSP/src/goto_def.rs b/kclvm/tools/src/LSP/src/goto_def.rs index 224a07612..c092160d2 100644 --- a/kclvm/tools/src/LSP/src/goto_def.rs +++ b/kclvm/tools/src/LSP/src/goto_def.rs @@ -11,12 +11,12 @@ use indexmap::{IndexMap, IndexSet}; use kclvm_ast::pos::{ContainsPos, GetPos}; use kclvm_ast::ast::{Expr, Identifier, ImportStmt, Node, Program, Stmt}; -use kclvm_compiler::pkgpath_without_prefix; use kclvm_error::Position as KCLPos; use kclvm_sema::builtin::{get_system_member_function_ty, STRING_MEMBER_FUNCTIONS}; use kclvm_sema::core::global_state::GlobalState; use kclvm_sema::core::symbol::SymbolRef; +use kclvm_sema::pkgpath_without_prefix; use kclvm_sema::resolver::scope::{ builtin_scope, ProgramScope, Scope, ScopeObject, ScopeObjectKind, }; 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/notification.rs b/kclvm/tools/src/LSP/src/notification.rs index e82d7fb61..338c84f4e 100644 --- a/kclvm/tools/src/LSP/src/notification.rs +++ b/kclvm/tools/src/LSP/src/notification.rs @@ -94,7 +94,7 @@ impl LanguageServerState { let new_word_index = build_word_index_for_file_content(text.clone(), &text_document.uri); let binding = text_document.uri.path(); let file_path = Path::new(binding); //todo rename - let mut word_index_map = &mut *self.word_index_map.write(); + let word_index_map = &mut *self.word_index_map.write(); for (key, value) in word_index_map { let workspace_folder_path = Path::new(key.path()); if file_path.starts_with(workspace_folder_path) { 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())) diff --git a/kclvm/tools/src/LSP/src/util.rs b/kclvm/tools/src/LSP/src/util.rs index 23b9be2a8..06d5d92cf 100644 --- a/kclvm/tools/src/LSP/src/util.rs +++ b/kclvm/tools/src/LSP/src/util.rs @@ -5,7 +5,6 @@ use kclvm_ast::ast::{ }; use kclvm_ast::pos::ContainsPos; use kclvm_ast::MAIN_PKG; -use kclvm_compiler::pkgpath_without_prefix; use kclvm_config::modfile::KCL_FILE_EXTENSION; use kclvm_driver::kpm_metadata::fetch_metadata; use kclvm_driver::{get_kcl_files, lookup_compile_unit}; @@ -16,6 +15,7 @@ use kclvm_parser::{load_program, ParseSession}; use kclvm_sema::advanced_resolver::AdvancedResolver; use kclvm_sema::core::global_state::GlobalState; use kclvm_sema::namer::Namer; +use kclvm_sema::pkgpath_without_prefix; use kclvm_sema::resolver::resolve_program_with_opts; use kclvm_sema::resolver::scope::ProgramScope; use kclvm_sema::resolver::scope::Scope;