Skip to content

Commit

Permalink
chore: deprecated sematic schema settings attr and re-org crates
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Nov 7, 2023
1 parent b24a298 commit b695c82
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 70 deletions.
1 change: 0 additions & 1 deletion kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kclvm/compiler/src/codegen/llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion kclvm/compiler/src/codegen/llvm/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions kclvm/compiler/src/codegen/llvm/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(
Expand Down
10 changes: 0 additions & 10 deletions kclvm/compiler/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
};
}
2 changes: 1 addition & 1 deletion kclvm/runner/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions kclvm/sema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 11 additions & 0 deletions kclvm/sema/src/macros.rs
Original file line number Diff line number Diff line change
@@ -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(),
}
};
}
18 changes: 0 additions & 18 deletions kclvm/sema/src/resolver/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -568,23 +567,6 @@ impl<'ctx> Resolver<'ctx> {
};
// Schema attributes
let mut attr_obj_map: IndexMap<String, SchemaAttr> = 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
Expand Down
1 change: 0 additions & 1 deletion kclvm/tools/src/LSP/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
39 changes: 20 additions & 19 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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),
});
}
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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()
}
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion kclvm/tools/src/LSP/src/goto_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
10 changes: 2 additions & 8 deletions kclvm/tools/src/LSP/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion kclvm/tools/src/LSP/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 2 additions & 5 deletions kclvm/tools/src/LSP/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -1225,7 +1223,6 @@ fn konfig_completion_test_main() {
"kubevela_output",
"server_output",
"schedulingStrategy",
"__settings__",
"name",
"workloadType",
"renderType",
Expand Down Expand Up @@ -1310,7 +1307,7 @@ fn konfig_hover_test_main() {
let expect: Vec<MarkedString> = 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()))
Expand Down
2 changes: 1 addition & 1 deletion kclvm/tools/src/LSP/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down

0 comments on commit b695c82

Please sign in to comment.