From 1354377ac612a3bb9c3664c50925b92e982a4ba4 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Thu, 4 Jul 2024 15:04:56 +0530 Subject: [PATCH 01/11] add inlay hints for function call args Signed-off-by: shruti2522 make fmt Signed-off-by: shruti2522 add inlay hints for function call args Signed-off-by: shruti2522 --- kclvm/sema/src/advanced_resolver/node.rs | 71 ++++++++-- ...y_hints__tests__assign_stmt_type_hint.snap | 131 ++++++++++++++++++ .../assign_stmt_type_hint.k | 6 + 3 files changed, 196 insertions(+), 12 deletions(-) diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index 85d0450d6..359bf2289 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -15,7 +15,7 @@ use crate::{ SymbolSemanticInfo, UnresolvedSymbol, ValueSymbol, }, }, - ty::{Type, TypeKind, SCHEMA_MEMBER_FUNCTIONS}, + ty::{Parameter, Type, TypeKind, SCHEMA_MEMBER_FUNCTIONS}, }; use super::AdvancedResolver; @@ -573,7 +573,22 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> { fn walk_call_expr(&mut self, call_expr: &'ctx ast::CallExpr) -> Self::Result { self.expr(&call_expr.func)?; - self.do_arguments_symbol_resolve(&call_expr.args, &call_expr.keywords)?; + let ty = self + .ctx + .node_ty_map + .borrow() + .get(&self.ctx.get_node_key(&call_expr.func.id)) + .unwrap() + .clone(); + if let TypeKind::Function(func_ty) = &ty.kind { + let func_params = &func_ty.params; + self.do_arguments_symbol_resolve_with_hint( + &call_expr.args, + &call_expr.keywords, + true, + func_params.to_vec(), + )?; + } Ok(None) } @@ -1235,32 +1250,64 @@ impl<'ctx> AdvancedResolver<'ctx> { args: &'ctx [ast::NodeRef], kwargs: &'ctx [ast::NodeRef], ) -> anyhow::Result<()> { - for arg in args.iter() { - self.expr(arg)?; - } + self.do_arguments_symbol_resolve_with_hint(args, kwargs, false, vec![]) + } + + pub fn do_arguments_symbol_resolve_with_hint( + &mut self, + args: &'ctx [ast::NodeRef], + kwargs: &'ctx [ast::NodeRef], + with_hint: bool, + mut params: Vec, + ) -> anyhow::Result<()> { for kw in kwargs.iter() { if let Some(value) = &kw.node.value { self.expr(value)?; } + let kw_name = kw.node.arg.node.get_name(); let (start_pos, end_pos): Range = kw.get_span_pos(); let value = self.gs.get_symbols_mut().alloc_value_symbol( - ValueSymbol::new(kw.node.arg.node.get_name(), start_pos, end_pos, None, false), + ValueSymbol::new(kw_name.clone(), start_pos, end_pos, None, false), self.ctx.get_node_key(&kw.id), self.ctx.current_pkgpath.clone().unwrap(), ); if let Some(value) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { - value.sema_info = SymbolSemanticInfo { - ty: self + let ty = self + .ctx + .node_ty_map + .borrow() + .get(&self.ctx.get_node_key(&kw.id)) + .map(|ty| ty.clone()); + if with_hint { + value.hint = Some(SymbolHint::VarHint(kw_name.clone())); + params.retain(|param| param.name != kw_name); + } + value.sema_info = SymbolSemanticInfo { ty, doc: None }; + } + } + for (i, arg) in args.iter().enumerate() { + self.expr(arg)?; + if with_hint { + let (start_pos, end_pos) = arg.get_span_pos(); + let value = self.gs.get_symbols_mut().alloc_value_symbol( + ValueSymbol::new(params[i].name.clone(), start_pos, end_pos, None, false), + self.ctx.get_node_key(&arg.id), + self.ctx.current_pkgpath.clone().unwrap(), + ); + if let Some(value) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { + let ty = self .ctx .node_ty_map .borrow() - .get(&self.ctx.get_node_key(&kw.id)) - .map(|ty| ty.clone()), - doc: None, - }; + .get(&self.ctx.get_node_key(&arg.id)) + .map(|ty| ty.clone()); + value.hint = Some(SymbolHint::VarHint(params[i].name.clone())); + value.sema_info = SymbolSemanticInfo { ty, doc: None }; + } } } + Ok(()) } diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap index efeded072..f218724c8 100644 --- a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap @@ -1,5 +1,6 @@ --- source: tools/src/LSP/src/inlay_hints.rs +assertion_line: 80 expression: "format!(\"{:#?}\", res)" --- Some( @@ -246,5 +247,135 @@ Some( padding_right: None, data: None, }, + InlayHint { + position: Position { + line: 23, + character: 4, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: ": (any, any, any) -> any", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: None, + text_edits: None, + tooltip: None, + padding_left: Some( + true, + ), + padding_right: Some( + true, + ), + data: None, + }, + InlayHint { + position: Position { + line: 27, + character: 1, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: ": any", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: None, + text_edits: None, + tooltip: None, + padding_left: Some( + true, + ), + padding_right: Some( + true, + ), + data: None, + }, + InlayHint { + position: Position { + line: 27, + character: 9, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "x: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: None, + text_edits: None, + tooltip: None, + padding_left: Some( + true, + ), + padding_right: Some( + true, + ), + data: None, + }, + InlayHint { + position: Position { + line: 27, + character: 12, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "y: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: None, + text_edits: None, + tooltip: None, + padding_left: Some( + true, + ), + padding_right: Some( + true, + ), + data: None, + }, + InlayHint { + position: Position { + line: 27, + character: 19, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "z: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: None, + text_edits: None, + tooltip: None, + padding_left: Some( + true, + ), + padding_right: Some( + true, + ), + data: None, + }, ], ) diff --git a/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k b/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k index 56b633380..60accee2e 100644 --- a/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k +++ b/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k @@ -20,3 +20,9 @@ ee = { a: "asda" } ccc = 1Ki + +func = lambda x, y, z{ + x * y + z +} + +z = func(a, y = 1, z = 2) From a2413aa9e95fe2e442f3c21ed74a53a57400e53b Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Thu, 4 Jul 2024 16:04:51 +0530 Subject: [PATCH 02/11] fix ci Signed-off-by: shruti2522 remove inlay hints for kwargs Signed-off-by: shruti2522 remove kw_name Signed-off-by: shruti2522 fix ci Signed-off-by: shruti2522 add inlay hints for function call args Signed-off-by: shruti2522 make fmt Signed-off-by: shruti2522 add inlay hints for function call args Signed-off-by: shruti2522 test ci Signed-off-by: shruti2522 test ci Signed-off-by: shruti2522 fix indexing error Signed-off-by: shruti2522 fix ci Signed-off-by: shruti2522 update test snaps Signed-off-by: shruti2522 fix ci Signed-off-by: shruti2522 fix ci Signed-off-by: shruti2522 --- .../kclvm_loader__tests__builtin_call_0.snap | 245 +---------------- .../kclvm_loader__tests__builtin_call_1.snap | 247 +++++++++++++++++- .../kclvm_loader__tests__builtin_call_2.snap | 247 +++++++++++++++++- .../kclvm_loader__tests__import_stmt_0.snap | 39 +++ kclvm/sema/src/advanced_resolver/node.rs | 55 ++-- ...y_hints__tests__assign_stmt_type_hint.snap | 60 +---- .../assign_stmt_type_hint.k | 2 +- 7 files changed, 568 insertions(+), 327 deletions(-) diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_0.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_0.snap index 8f93e0d4b..9eaa408ec 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_0.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_0.snap @@ -1,5 +1,6 @@ --- source: loader/src/tests.rs +assertion_line: 37 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -52,248 +53,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, - SymbolInfo { - ty: Type { - kind: StrLit( - "hello world", - ), - is_type_alias: false, - flags: STR | LITERAL, - }, - name: "@StringLitExpression", - range: ( - Position { - filename: "test.k", - line: 1, - column: Some( - 19, - ), - }, - Position { - filename: "test.k", - line: 1, - column: Some( - 19, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 0, - generation: 0, - }, - kind: Expression, - }, - ), - attrs: [ - SymbolRef { - id: Index { - index: 137, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 138, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 139, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 140, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 141, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 142, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 143, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 144, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 145, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 146, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 147, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 148, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 149, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 150, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 151, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 152, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 153, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 154, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 155, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 156, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 157, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 158, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 159, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 160, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 161, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 162, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 163, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 164, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 165, - generation: 0, - }, - kind: Function, - }, - ], - is_global: false, - }, SymbolInfo { ty: Type { kind: None, @@ -321,7 +80,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 0, generation: 0, }, kind: Expression, diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap index ac9539812..da59ec608 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap @@ -1,5 +1,6 @@ --- source: loader/src/tests.rs +assertion_line: 38 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -144,6 +145,248 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, + SymbolInfo { + ty: Type { + kind: StrLit( + "key", + ), + is_type_alias: false, + flags: STR | LITERAL, + }, + name: "key", + range: ( + Position { + filename: "test.k", + line: 1, + column: Some( + 11, + ), + }, + Position { + filename: "test.k", + line: 1, + column: Some( + 16, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 1, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [ + SymbolRef { + id: Index { + index: 137, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 138, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 139, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 140, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 141, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 142, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 143, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 144, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 145, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 146, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 147, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 148, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 149, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 150, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 151, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 152, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 153, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 154, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 155, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 156, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 157, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 158, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 159, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 160, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 161, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 162, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 163, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 164, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 165, + generation: 0, + }, + kind: Function, + }, + ], + is_global: false, + }, SymbolInfo { ty: Type { kind: StrLit( @@ -415,7 +658,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 2, generation: 0, }, kind: Value, @@ -899,7 +1142,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 3, generation: 0, }, kind: Value, diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap index 6d068c7ff..f33cf07aa 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap @@ -1,5 +1,6 @@ --- source: loader/src/tests.rs +assertion_line: 39 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -346,6 +347,248 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, + SymbolInfo { + ty: Type { + kind: StrLit( + "key", + ), + is_type_alias: false, + flags: STR | LITERAL, + }, + name: "key", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 8, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 13, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 2, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [ + SymbolRef { + id: Index { + index: 137, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 138, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 139, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 140, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 141, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 142, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 143, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 144, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 145, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 146, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 147, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 148, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 149, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 150, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 151, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 152, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 153, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 154, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 155, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 156, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 157, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 158, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 159, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 160, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 161, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 162, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 163, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 164, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 165, + generation: 0, + }, + kind: Function, + }, + ], + is_global: false, + }, SymbolInfo { ty: Type { kind: StrLit( @@ -617,7 +860,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 3, generation: 0, }, kind: Value, @@ -1101,7 +1344,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 3, + index: 4, generation: 0, }, kind: Value, diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__import_stmt_0.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__import_stmt_0.snap index 6d64a6a42..912bed796 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__import_stmt_0.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__import_stmt_0.snap @@ -1,5 +1,6 @@ --- source: loader/src/tests.rs +assertion_line: 29 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -442,6 +443,44 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, + SymbolInfo { + ty: Type { + kind: IntLit( + 10, + ), + is_type_alias: false, + flags: INT | LITERAL, + }, + name: "x", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 13, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 15, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 1, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [], + is_global: false, + }, SymbolInfo { ty: Type { kind: IntLit( diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index 359bf2289..3d95757db 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -1264,50 +1264,49 @@ impl<'ctx> AdvancedResolver<'ctx> { if let Some(value) = &kw.node.value { self.expr(value)?; } - let kw_name = kw.node.arg.node.get_name(); let (start_pos, end_pos): Range = kw.get_span_pos(); let value = self.gs.get_symbols_mut().alloc_value_symbol( - ValueSymbol::new(kw_name.clone(), start_pos, end_pos, None, false), + ValueSymbol::new(kw.node.arg.node.get_name(), start_pos, end_pos, None, false), self.ctx.get_node_key(&kw.id), self.ctx.current_pkgpath.clone().unwrap(), ); if let Some(value) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { + params.retain(|param| param.name != kw.node.arg.node.get_name()); + value.sema_info = SymbolSemanticInfo { + ty: self + .ctx + .node_ty_map + .borrow() + .get(&self.ctx.get_node_key(&kw.id)) + .map(|ty| ty.clone()), + doc: None, + }; + } + } + + for (arg, param) in args.iter().zip(params.iter()) { + self.expr(arg)?; + let (start_pos, end_pos) = arg.get_span_pos(); + let arg_value = self.gs.get_symbols_mut().alloc_value_symbol( + ValueSymbol::new(param.name.clone(), start_pos, end_pos, None, false), + self.ctx.get_node_key(&arg.id), + self.ctx.current_pkgpath.clone().unwrap(), + ); + + if let Some(val) = self.gs.get_symbols_mut().values.get_mut(arg_value.get_id()) { let ty = self .ctx .node_ty_map .borrow() - .get(&self.ctx.get_node_key(&kw.id)) + .get(&self.ctx.get_node_key(&arg.id)) .map(|ty| ty.clone()); if with_hint { - value.hint = Some(SymbolHint::VarHint(kw_name.clone())); - params.retain(|param| param.name != kw_name); + val.hint = Some(SymbolHint::VarHint(param.name.clone())); } - value.sema_info = SymbolSemanticInfo { ty, doc: None }; + val.sema_info = SymbolSemanticInfo { ty, doc: None }; } } - for (i, arg) in args.iter().enumerate() { - self.expr(arg)?; - if with_hint { - let (start_pos, end_pos) = arg.get_span_pos(); - let value = self.gs.get_symbols_mut().alloc_value_symbol( - ValueSymbol::new(params[i].name.clone(), start_pos, end_pos, None, false), - self.ctx.get_node_key(&arg.id), - self.ctx.current_pkgpath.clone().unwrap(), - ); - if let Some(value) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { - let ty = self - .ctx - .node_ty_map - .borrow() - .get(&self.ctx.get_node_key(&arg.id)) - .map(|ty| ty.clone()); - value.hint = Some(SymbolHint::VarHint(params[i].name.clone())); - value.sema_info = SymbolSemanticInfo { ty, doc: None }; - } - } - } - Ok(()) } diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap index f218724c8..1cf3a424b 100644 --- a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap @@ -1,6 +1,6 @@ --- source: tools/src/LSP/src/inlay_hints.rs -assertion_line: 80 +assertion_line: 118 expression: "format!(\"{:#?}\", res)" --- Some( @@ -265,12 +265,8 @@ Some( kind: None, text_edits: None, tooltip: None, - padding_left: Some( - true, - ), - padding_right: Some( - true, - ), + padding_left: None, + padding_right: None, data: None, }, InlayHint { @@ -291,12 +287,8 @@ Some( kind: None, text_edits: None, tooltip: None, - padding_left: Some( - true, - ), - padding_right: Some( - true, - ), + padding_left: None, + padding_right: None, data: None, }, InlayHint { @@ -317,12 +309,8 @@ Some( kind: None, text_edits: None, tooltip: None, - padding_left: Some( - true, - ), - padding_right: Some( - true, - ), + padding_left: None, + padding_right: None, data: None, }, InlayHint { @@ -343,38 +331,8 @@ Some( kind: None, text_edits: None, tooltip: None, - padding_left: Some( - true, - ), - padding_right: Some( - true, - ), - data: None, - }, - InlayHint { - position: Position { - line: 27, - character: 19, - }, - label: LabelParts( - [ - InlayHintLabelPart { - value: "z: ", - tooltip: None, - location: None, - command: None, - }, - ], - ), - kind: None, - text_edits: None, - tooltip: None, - padding_left: Some( - true, - ), - padding_right: Some( - true, - ), + padding_left: None, + padding_right: None, data: None, }, ], diff --git a/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k b/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k index 60accee2e..1b0ef2e75 100644 --- a/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k +++ b/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k @@ -25,4 +25,4 @@ func = lambda x, y, z{ x * y + z } -z = func(a, y = 1, z = 2) +z = func(a, 1, z = 2) From b5409df8dbb9e457ac52072370a85c793399f032 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Fri, 5 Jul 2024 12:56:19 +0530 Subject: [PATCH 03/11] update snaps Signed-off-by: shruti2522 --- .../kclvm_loader__tests__builtin_call_1.snap | 12 ++++++------ .../kclvm_loader__tests__builtin_call_2.snap | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap index da59ec608..e4566507d 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap @@ -174,7 +174,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 3, generation: 0, }, kind: Value, @@ -416,7 +416,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 0, + index: 2, generation: 0, }, kind: Expression, @@ -658,7 +658,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 1, generation: 0, }, kind: Value, @@ -900,7 +900,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 0, generation: 0, }, kind: Expression, @@ -1142,7 +1142,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 3, + index: 2, generation: 0, }, kind: Value, @@ -1180,7 +1180,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 1, generation: 0, }, kind: Expression, diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap index f33cf07aa..41705376a 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap @@ -376,7 +376,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 4, generation: 0, }, kind: Value, @@ -618,7 +618,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 0, + index: 2, generation: 0, }, kind: Expression, @@ -860,7 +860,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 3, + index: 2, generation: 0, }, kind: Value, @@ -1102,7 +1102,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 0, generation: 0, }, kind: Expression, @@ -1344,7 +1344,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 4, + index: 3, generation: 0, }, kind: Value, @@ -1382,7 +1382,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 1, generation: 0, }, kind: Expression, From 8ff1aaf06d9d7795b96842a1ded2c92db2f1dcca Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Sat, 6 Jul 2024 14:50:01 +0530 Subject: [PATCH 04/11] remove hints for builtin func calls Signed-off-by: shruti2522 remove inlay hints for system module functions Signed-off-by: shruti2522 change function name Signed-off-by: shruti2522 fix ci Signed-off-by: shruti2522 remove hints for builtin func calls Signed-off-by: shruti2522 --- .../kclvm_loader__tests__builtin_call_0.snap | 245 ++- .../kclvm_loader__tests__builtin_call_1.snap | 249 +-- .../kclvm_loader__tests__builtin_call_2.snap | 249 +-- ...lvm_loader__tests__builtin_call_2.snap.new | 1430 +++++++++++++++++ .../kclvm_loader__tests__import_stmt_0.snap | 39 - kclvm/sema/src/advanced_resolver/node.rs | 69 +- kclvm/sema/src/builtin/system_module.rs | 17 + 7 files changed, 1758 insertions(+), 540 deletions(-) create mode 100644 kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap.new diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_0.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_0.snap index 9eaa408ec..8f93e0d4b 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_0.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_0.snap @@ -1,6 +1,5 @@ --- source: loader/src/tests.rs -assertion_line: 37 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -53,6 +52,248 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, + SymbolInfo { + ty: Type { + kind: StrLit( + "hello world", + ), + is_type_alias: false, + flags: STR | LITERAL, + }, + name: "@StringLitExpression", + range: ( + Position { + filename: "test.k", + line: 1, + column: Some( + 19, + ), + }, + Position { + filename: "test.k", + line: 1, + column: Some( + 19, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 0, + generation: 0, + }, + kind: Expression, + }, + ), + attrs: [ + SymbolRef { + id: Index { + index: 137, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 138, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 139, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 140, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 141, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 142, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 143, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 144, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 145, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 146, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 147, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 148, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 149, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 150, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 151, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 152, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 153, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 154, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 155, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 156, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 157, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 158, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 159, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 160, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 161, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 162, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 163, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 164, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 165, + generation: 0, + }, + kind: Function, + }, + ], + is_global: false, + }, SymbolInfo { ty: Type { kind: None, @@ -80,7 +321,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 0, + index: 1, generation: 0, }, kind: Expression, diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap index e4566507d..ac9539812 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap @@ -1,6 +1,5 @@ --- source: loader/src/tests.rs -assertion_line: 38 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -145,248 +144,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, - SymbolInfo { - ty: Type { - kind: StrLit( - "key", - ), - is_type_alias: false, - flags: STR | LITERAL, - }, - name: "key", - range: ( - Position { - filename: "test.k", - line: 1, - column: Some( - 11, - ), - }, - Position { - filename: "test.k", - line: 1, - column: Some( - 16, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 3, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [ - SymbolRef { - id: Index { - index: 137, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 138, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 139, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 140, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 141, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 142, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 143, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 144, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 145, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 146, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 147, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 148, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 149, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 150, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 151, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 152, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 153, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 154, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 155, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 156, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 157, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 158, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 159, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 160, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 161, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 162, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 163, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 164, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 165, - generation: 0, - }, - kind: Function, - }, - ], - is_global: false, - }, SymbolInfo { ty: Type { kind: StrLit( @@ -416,7 +173,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 0, generation: 0, }, kind: Expression, @@ -900,7 +657,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 0, + index: 1, generation: 0, }, kind: Expression, @@ -1180,7 +937,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 2, generation: 0, }, kind: Expression, diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap index 41705376a..6d068c7ff 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap @@ -1,6 +1,5 @@ --- source: loader/src/tests.rs -assertion_line: 39 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -347,248 +346,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, - SymbolInfo { - ty: Type { - kind: StrLit( - "key", - ), - is_type_alias: false, - flags: STR | LITERAL, - }, - name: "key", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 8, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 13, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 4, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [ - SymbolRef { - id: Index { - index: 137, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 138, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 139, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 140, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 141, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 142, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 143, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 144, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 145, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 146, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 147, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 148, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 149, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 150, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 151, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 152, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 153, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 154, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 155, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 156, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 157, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 158, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 159, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 160, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 161, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 162, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 163, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 164, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 165, - generation: 0, - }, - kind: Function, - }, - ], - is_global: false, - }, SymbolInfo { ty: Type { kind: StrLit( @@ -618,7 +375,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 0, generation: 0, }, kind: Expression, @@ -1102,7 +859,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 0, + index: 1, generation: 0, }, kind: Expression, @@ -1382,7 +1139,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 2, generation: 0, }, kind: Expression, diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap.new b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap.new new file mode 100644 index 000000000..41705376a --- /dev/null +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap.new @@ -0,0 +1,1430 @@ +--- +source: loader/src/tests.rs +assertion_line: 39 +expression: "format!(\"{:#?}\", p.symbols.values())" +--- +[ + SymbolInfo { + ty: Type { + kind: Function( + FunctionType { + doc: "Return the top level argument by the key", + params: [ + Parameter { + name: "key", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: false, + }, + Parameter { + name: "type", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: true, + }, + Parameter { + name: "required", + ty: Type { + kind: Bool, + is_type_alias: false, + flags: BOOL, + }, + has_default: true, + }, + Parameter { + name: "default", + ty: Type { + kind: Any, + is_type_alias: false, + flags: ANY, + }, + has_default: true, + }, + Parameter { + name: "help", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: true, + }, + ], + self_ty: None, + return_ty: Type { + kind: Any, + is_type_alias: false, + flags: ANY, + }, + is_variadic: false, + kw_only_index: Some( + 1, + ), + }, + ), + is_type_alias: false, + flags: FUNCTION, + }, + name: "opt", + range: ( + Position { + filename: "test.k", + line: 1, + column: Some( + 0, + ), + }, + Position { + filename: "test.k", + line: 1, + column: Some( + 3, + ), + }, + ), + owner: Some( + SymbolRef { + id: Index { + index: 15, + generation: 0, + }, + kind: Package, + }, + ), + def: Some( + SymbolRef { + id: Index { + index: 0, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [], + is_global: true, + }, + SymbolInfo { + ty: Type { + kind: Function( + FunctionType { + doc: "Return the top level argument by the key", + params: [ + Parameter { + name: "key", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: false, + }, + Parameter { + name: "type", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: true, + }, + Parameter { + name: "required", + ty: Type { + kind: Bool, + is_type_alias: false, + flags: BOOL, + }, + has_default: true, + }, + Parameter { + name: "default", + ty: Type { + kind: Any, + is_type_alias: false, + flags: ANY, + }, + has_default: true, + }, + Parameter { + name: "help", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: true, + }, + ], + self_ty: None, + return_ty: Type { + kind: Any, + is_type_alias: false, + flags: ANY, + }, + is_variadic: false, + kw_only_index: Some( + 1, + ), + }, + ), + is_type_alias: false, + flags: FUNCTION, + }, + name: "option", + range: ( + Position { + filename: "test.k", + line: 1, + column: Some( + 6, + ), + }, + Position { + filename: "test.k", + line: 1, + column: Some( + 12, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 0, + generation: 0, + }, + kind: Function, + }, + ), + attrs: [], + is_global: false, + }, + SymbolInfo { + ty: Type { + kind: Any, + is_type_alias: false, + flags: ANY, + }, + name: "a", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 0, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 1, + ), + }, + ), + owner: Some( + SymbolRef { + id: Index { + index: 15, + generation: 0, + }, + kind: Package, + }, + ), + def: Some( + SymbolRef { + id: Index { + index: 1, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [], + is_global: true, + }, + SymbolInfo { + ty: Type { + kind: Function( + FunctionType { + doc: "Return the top level argument by the key", + params: [ + Parameter { + name: "key", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: false, + }, + Parameter { + name: "type", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: true, + }, + Parameter { + name: "required", + ty: Type { + kind: Bool, + is_type_alias: false, + flags: BOOL, + }, + has_default: true, + }, + Parameter { + name: "default", + ty: Type { + kind: Any, + is_type_alias: false, + flags: ANY, + }, + has_default: true, + }, + Parameter { + name: "help", + ty: Type { + kind: Str, + is_type_alias: false, + flags: STR, + }, + has_default: true, + }, + ], + self_ty: None, + return_ty: Type { + kind: Any, + is_type_alias: false, + flags: ANY, + }, + is_variadic: false, + kw_only_index: Some( + 1, + ), + }, + ), + is_type_alias: false, + flags: FUNCTION, + }, + name: "opt", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 4, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 7, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 0, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [], + is_global: false, + }, + SymbolInfo { + ty: Type { + kind: StrLit( + "key", + ), + is_type_alias: false, + flags: STR | LITERAL, + }, + name: "key", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 8, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 13, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 4, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [ + SymbolRef { + id: Index { + index: 137, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 138, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 139, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 140, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 141, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 142, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 143, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 144, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 145, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 146, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 147, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 148, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 149, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 150, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 151, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 152, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 153, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 154, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 155, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 156, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 157, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 158, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 159, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 160, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 161, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 162, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 163, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 164, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 165, + generation: 0, + }, + kind: Function, + }, + ], + is_global: false, + }, + SymbolInfo { + ty: Type { + kind: StrLit( + "key", + ), + is_type_alias: false, + flags: STR | LITERAL, + }, + name: "@StringLitExpression", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 13, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 13, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 2, + generation: 0, + }, + kind: Expression, + }, + ), + attrs: [ + SymbolRef { + id: Index { + index: 137, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 138, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 139, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 140, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 141, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 142, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 143, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 144, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 145, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 146, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 147, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 148, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 149, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 150, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 151, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 152, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 153, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 154, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 155, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 156, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 157, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 158, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 159, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 160, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 161, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 162, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 163, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 164, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 165, + generation: 0, + }, + kind: Function, + }, + ], + is_global: false, + }, + SymbolInfo { + ty: Type { + kind: StrLit( + "str", + ), + is_type_alias: false, + flags: STR | LITERAL, + }, + name: "type", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 15, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 25, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 2, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [ + SymbolRef { + id: Index { + index: 137, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 138, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 139, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 140, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 141, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 142, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 143, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 144, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 145, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 146, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 147, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 148, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 149, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 150, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 151, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 152, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 153, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 154, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 155, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 156, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 157, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 158, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 159, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 160, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 161, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 162, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 163, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 164, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 165, + generation: 0, + }, + kind: Function, + }, + ], + is_global: false, + }, + SymbolInfo { + ty: Type { + kind: StrLit( + "str", + ), + is_type_alias: false, + flags: STR | LITERAL, + }, + name: "@StringLitExpression", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 25, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 25, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 0, + generation: 0, + }, + kind: Expression, + }, + ), + attrs: [ + SymbolRef { + id: Index { + index: 137, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 138, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 139, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 140, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 141, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 142, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 143, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 144, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 145, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 146, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 147, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 148, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 149, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 150, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 151, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 152, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 153, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 154, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 155, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 156, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 157, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 158, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 159, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 160, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 161, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 162, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 163, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 164, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 165, + generation: 0, + }, + kind: Function, + }, + ], + is_global: false, + }, + SymbolInfo { + ty: Type { + kind: BoolLit( + true, + ), + is_type_alias: false, + flags: BOOL | LITERAL, + }, + name: "required", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 27, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 40, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 3, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [], + is_global: false, + }, + SymbolInfo { + ty: Type { + kind: BoolLit( + true, + ), + is_type_alias: false, + flags: BOOL | LITERAL, + }, + name: "@NameConstantLitExpression", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 40, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 40, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 1, + generation: 0, + }, + kind: Expression, + }, + ), + attrs: [], + is_global: false, + }, + SymbolInfo { + ty: Type { + kind: Any, + is_type_alias: false, + flags: ANY, + }, + name: "@CallExpression", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 41, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 41, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 3, + generation: 0, + }, + kind: Expression, + }, + ), + attrs: [], + is_global: false, + }, +] diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__import_stmt_0.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__import_stmt_0.snap index 912bed796..6d64a6a42 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__import_stmt_0.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__import_stmt_0.snap @@ -1,6 +1,5 @@ --- source: loader/src/tests.rs -assertion_line: 29 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -443,44 +442,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, - SymbolInfo { - ty: Type { - kind: IntLit( - 10, - ), - is_type_alias: false, - flags: INT | LITERAL, - }, - name: "x", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 13, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 15, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 1, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [], - is_global: false, - }, SymbolInfo { ty: Type { kind: IntLit( diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index 3d95757db..cada761e0 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -8,6 +8,7 @@ use kclvm_ast::walker::MutSelfTypedResultWalker; use kclvm_error::{diagnostic::Range, Position}; use crate::{ + builtin::{is_system_module_function, BUILTIN_FUNCTION_NAMES}, core::{ scope::LocalSymbolScopeKind, symbol::{ @@ -580,15 +581,43 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> { .get(&self.ctx.get_node_key(&call_expr.func.id)) .unwrap() .clone(); + if let TypeKind::Function(func_ty) = &ty.kind { + let func_fully_qualified_name = match &call_expr.func.node { + ast::Expr::Identifier(ident) => { + let names = ident + .names + .iter() + .map(|node| &node.node) + .cloned() + .collect::>() + .join("::"); + Some(names) + } + _ => None, + }; + + let func_name = func_fully_qualified_name + .as_ref() + .and_then(|name| name.split("::").last().map(String::from)); + let is_builtin = func_name.as_deref().map_or(false, |name| { + BUILTIN_FUNCTION_NAMES.contains(&name) || is_system_module_function(&name) + }); + let func_params = &func_ty.params; - self.do_arguments_symbol_resolve_with_hint( - &call_expr.args, - &call_expr.keywords, - true, - func_params.to_vec(), - )?; + + if is_builtin { + self.do_arguments_symbol_resolve(&call_expr.args, &call_expr.keywords)?; + } else { + self.do_arguments_symbol_resolve_with_hint( + &call_expr.args, + &call_expr.keywords, + true, + func_params.to_vec(), + )?; + } } + Ok(None) } @@ -1250,7 +1279,33 @@ impl<'ctx> AdvancedResolver<'ctx> { args: &'ctx [ast::NodeRef], kwargs: &'ctx [ast::NodeRef], ) -> anyhow::Result<()> { - self.do_arguments_symbol_resolve_with_hint(args, kwargs, false, vec![]) + for arg in args.iter() { + self.expr(arg)?; + } + for kw in kwargs.iter() { + if let Some(value) = &kw.node.value { + self.expr(value)?; + } + let (start_pos, end_pos): Range = kw.get_span_pos(); + let value = self.gs.get_symbols_mut().alloc_value_symbol( + ValueSymbol::new(kw.node.arg.node.get_name(), start_pos, end_pos, None, false), + self.ctx.get_node_key(&kw.id), + self.ctx.current_pkgpath.clone().unwrap(), + ); + + if let Some(value) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { + value.sema_info = SymbolSemanticInfo { + ty: self + .ctx + .node_ty_map + .borrow() + .get(&self.ctx.get_node_key(&kw.id)) + .map(|ty| ty.clone()), + doc: None, + }; + } + } + Ok(()) } pub fn do_arguments_symbol_resolve_with_hint( diff --git a/kclvm/sema/src/builtin/system_module.rs b/kclvm/sema/src/builtin/system_module.rs index e674c3cca..69624d520 100644 --- a/kclvm/sema/src/builtin/system_module.rs +++ b/kclvm/sema/src/builtin/system_module.rs @@ -1976,3 +1976,20 @@ pub fn get_system_member_function_ty(name: &str, func: &str) -> TypeRef { .map(|ty| Arc::new(ty)) .unwrap_or(Type::any_ref()) } + +pub fn is_system_module_function(name: &str) -> bool { + BASE64_FUNCTION_NAMES.contains(&name) + || NET_FUNCTION_NAMES.contains(&name) + || MANIFESTS_FUNCTION_NAMES.contains(&name) + || MATH_FUNCTION_NAMES.contains(&name) + || DATETIME_FUNCTION_NAMES.contains(&name) + || REGEX_FUNCTION_NAMES.contains(&name) + || YAML_FUNCTION_NAMES.contains(&name) + || JSON_FUNCTION_NAMES.contains(&name) + || CRYPTO_FUNCTION_NAMES.contains(&name) + || UNITS_FUNCTION_NAMES.contains(&name) + || COLLECTION_FUNCTION_NAMES.contains(&name) + || FILE_FUNCTION_NAMES.contains(&name) + || TEMPLATE_FUNCTION_NAMES.contains(&name) + || RUNTIME_FUNCTION_NAMES.contains(&name) +} From 2058190fbb3f3ead602be71a924077566a47d9f4 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Sat, 6 Jul 2024 21:21:05 +0530 Subject: [PATCH 05/11] update builtin loader snap to incliude inlay hints Signed-off-by: shruti2522 --- .../kclvm_loader__tests__builtin_call_2.snap | 249 ++- ...lvm_loader__tests__builtin_call_2.snap.new | 1430 ----------------- kclvm/sema/src/advanced_resolver/node.rs | 1 + 3 files changed, 247 insertions(+), 1433 deletions(-) delete mode 100644 kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap.new diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap index 6d068c7ff..41705376a 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap @@ -1,5 +1,6 @@ --- source: loader/src/tests.rs +assertion_line: 39 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -346,6 +347,248 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, + SymbolInfo { + ty: Type { + kind: StrLit( + "key", + ), + is_type_alias: false, + flags: STR | LITERAL, + }, + name: "key", + range: ( + Position { + filename: "test.k", + line: 3, + column: Some( + 8, + ), + }, + Position { + filename: "test.k", + line: 3, + column: Some( + 13, + ), + }, + ), + owner: None, + def: Some( + SymbolRef { + id: Index { + index: 4, + generation: 0, + }, + kind: Value, + }, + ), + attrs: [ + SymbolRef { + id: Index { + index: 137, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 138, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 139, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 140, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 141, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 142, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 143, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 144, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 145, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 146, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 147, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 148, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 149, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 150, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 151, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 152, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 153, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 154, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 155, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 156, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 157, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 158, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 159, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 160, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 161, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 162, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 163, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 164, + generation: 0, + }, + kind: Function, + }, + SymbolRef { + id: Index { + index: 165, + generation: 0, + }, + kind: Function, + }, + ], + is_global: false, + }, SymbolInfo { ty: Type { kind: StrLit( @@ -375,7 +618,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 0, + index: 2, generation: 0, }, kind: Expression, @@ -859,7 +1102,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 0, generation: 0, }, kind: Expression, @@ -1139,7 +1382,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 1, generation: 0, }, kind: Expression, diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap.new b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap.new deleted file mode 100644 index 41705376a..000000000 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap.new +++ /dev/null @@ -1,1430 +0,0 @@ ---- -source: loader/src/tests.rs -assertion_line: 39 -expression: "format!(\"{:#?}\", p.symbols.values())" ---- -[ - SymbolInfo { - ty: Type { - kind: Function( - FunctionType { - doc: "Return the top level argument by the key", - params: [ - Parameter { - name: "key", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: false, - }, - Parameter { - name: "type", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: true, - }, - Parameter { - name: "required", - ty: Type { - kind: Bool, - is_type_alias: false, - flags: BOOL, - }, - has_default: true, - }, - Parameter { - name: "default", - ty: Type { - kind: Any, - is_type_alias: false, - flags: ANY, - }, - has_default: true, - }, - Parameter { - name: "help", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: true, - }, - ], - self_ty: None, - return_ty: Type { - kind: Any, - is_type_alias: false, - flags: ANY, - }, - is_variadic: false, - kw_only_index: Some( - 1, - ), - }, - ), - is_type_alias: false, - flags: FUNCTION, - }, - name: "opt", - range: ( - Position { - filename: "test.k", - line: 1, - column: Some( - 0, - ), - }, - Position { - filename: "test.k", - line: 1, - column: Some( - 3, - ), - }, - ), - owner: Some( - SymbolRef { - id: Index { - index: 15, - generation: 0, - }, - kind: Package, - }, - ), - def: Some( - SymbolRef { - id: Index { - index: 0, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [], - is_global: true, - }, - SymbolInfo { - ty: Type { - kind: Function( - FunctionType { - doc: "Return the top level argument by the key", - params: [ - Parameter { - name: "key", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: false, - }, - Parameter { - name: "type", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: true, - }, - Parameter { - name: "required", - ty: Type { - kind: Bool, - is_type_alias: false, - flags: BOOL, - }, - has_default: true, - }, - Parameter { - name: "default", - ty: Type { - kind: Any, - is_type_alias: false, - flags: ANY, - }, - has_default: true, - }, - Parameter { - name: "help", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: true, - }, - ], - self_ty: None, - return_ty: Type { - kind: Any, - is_type_alias: false, - flags: ANY, - }, - is_variadic: false, - kw_only_index: Some( - 1, - ), - }, - ), - is_type_alias: false, - flags: FUNCTION, - }, - name: "option", - range: ( - Position { - filename: "test.k", - line: 1, - column: Some( - 6, - ), - }, - Position { - filename: "test.k", - line: 1, - column: Some( - 12, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 0, - generation: 0, - }, - kind: Function, - }, - ), - attrs: [], - is_global: false, - }, - SymbolInfo { - ty: Type { - kind: Any, - is_type_alias: false, - flags: ANY, - }, - name: "a", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 0, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 1, - ), - }, - ), - owner: Some( - SymbolRef { - id: Index { - index: 15, - generation: 0, - }, - kind: Package, - }, - ), - def: Some( - SymbolRef { - id: Index { - index: 1, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [], - is_global: true, - }, - SymbolInfo { - ty: Type { - kind: Function( - FunctionType { - doc: "Return the top level argument by the key", - params: [ - Parameter { - name: "key", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: false, - }, - Parameter { - name: "type", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: true, - }, - Parameter { - name: "required", - ty: Type { - kind: Bool, - is_type_alias: false, - flags: BOOL, - }, - has_default: true, - }, - Parameter { - name: "default", - ty: Type { - kind: Any, - is_type_alias: false, - flags: ANY, - }, - has_default: true, - }, - Parameter { - name: "help", - ty: Type { - kind: Str, - is_type_alias: false, - flags: STR, - }, - has_default: true, - }, - ], - self_ty: None, - return_ty: Type { - kind: Any, - is_type_alias: false, - flags: ANY, - }, - is_variadic: false, - kw_only_index: Some( - 1, - ), - }, - ), - is_type_alias: false, - flags: FUNCTION, - }, - name: "opt", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 4, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 7, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 0, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [], - is_global: false, - }, - SymbolInfo { - ty: Type { - kind: StrLit( - "key", - ), - is_type_alias: false, - flags: STR | LITERAL, - }, - name: "key", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 8, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 13, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 4, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [ - SymbolRef { - id: Index { - index: 137, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 138, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 139, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 140, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 141, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 142, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 143, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 144, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 145, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 146, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 147, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 148, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 149, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 150, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 151, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 152, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 153, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 154, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 155, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 156, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 157, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 158, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 159, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 160, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 161, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 162, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 163, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 164, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 165, - generation: 0, - }, - kind: Function, - }, - ], - is_global: false, - }, - SymbolInfo { - ty: Type { - kind: StrLit( - "key", - ), - is_type_alias: false, - flags: STR | LITERAL, - }, - name: "@StringLitExpression", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 13, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 13, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 2, - generation: 0, - }, - kind: Expression, - }, - ), - attrs: [ - SymbolRef { - id: Index { - index: 137, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 138, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 139, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 140, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 141, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 142, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 143, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 144, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 145, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 146, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 147, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 148, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 149, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 150, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 151, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 152, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 153, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 154, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 155, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 156, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 157, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 158, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 159, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 160, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 161, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 162, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 163, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 164, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 165, - generation: 0, - }, - kind: Function, - }, - ], - is_global: false, - }, - SymbolInfo { - ty: Type { - kind: StrLit( - "str", - ), - is_type_alias: false, - flags: STR | LITERAL, - }, - name: "type", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 15, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 25, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 2, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [ - SymbolRef { - id: Index { - index: 137, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 138, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 139, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 140, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 141, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 142, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 143, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 144, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 145, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 146, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 147, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 148, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 149, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 150, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 151, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 152, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 153, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 154, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 155, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 156, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 157, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 158, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 159, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 160, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 161, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 162, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 163, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 164, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 165, - generation: 0, - }, - kind: Function, - }, - ], - is_global: false, - }, - SymbolInfo { - ty: Type { - kind: StrLit( - "str", - ), - is_type_alias: false, - flags: STR | LITERAL, - }, - name: "@StringLitExpression", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 25, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 25, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 0, - generation: 0, - }, - kind: Expression, - }, - ), - attrs: [ - SymbolRef { - id: Index { - index: 137, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 138, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 139, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 140, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 141, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 142, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 143, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 144, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 145, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 146, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 147, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 148, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 149, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 150, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 151, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 152, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 153, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 154, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 155, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 156, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 157, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 158, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 159, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 160, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 161, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 162, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 163, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 164, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 165, - generation: 0, - }, - kind: Function, - }, - ], - is_global: false, - }, - SymbolInfo { - ty: Type { - kind: BoolLit( - true, - ), - is_type_alias: false, - flags: BOOL | LITERAL, - }, - name: "required", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 27, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 40, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 3, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [], - is_global: false, - }, - SymbolInfo { - ty: Type { - kind: BoolLit( - true, - ), - is_type_alias: false, - flags: BOOL | LITERAL, - }, - name: "@NameConstantLitExpression", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 40, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 40, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 1, - generation: 0, - }, - kind: Expression, - }, - ), - attrs: [], - is_global: false, - }, - SymbolInfo { - ty: Type { - kind: Any, - is_type_alias: false, - flags: ANY, - }, - name: "@CallExpression", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 41, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 41, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 3, - generation: 0, - }, - kind: Expression, - }, - ), - attrs: [], - is_global: false, - }, -] diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index cada761e0..c5a8b2447 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -600,6 +600,7 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> { let func_name = func_fully_qualified_name .as_ref() .and_then(|name| name.split("::").last().map(String::from)); + let is_builtin = func_name.as_deref().map_or(false, |name| { BUILTIN_FUNCTION_NAMES.contains(&name) || is_system_module_function(&name) }); From 487d0f394374c656481fa8bb5f8b6db0ba199df1 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Mon, 8 Jul 2024 10:07:20 +0530 Subject: [PATCH 06/11] test inlay hints Signed-off-by: shruti2522 --- .../kclvm_loader__tests__builtin_call_2.snap | 249 +----------------- kclvm/sema/src/advanced_resolver/node.rs | 68 ++--- kclvm/sema/src/builtin/system_module.rs | 17 -- 3 files changed, 22 insertions(+), 312 deletions(-) diff --git a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap index 41705376a..6d068c7ff 100644 --- a/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap +++ b/kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap @@ -1,6 +1,5 @@ --- source: loader/src/tests.rs -assertion_line: 39 expression: "format!(\"{:#?}\", p.symbols.values())" --- [ @@ -347,248 +346,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())" attrs: [], is_global: false, }, - SymbolInfo { - ty: Type { - kind: StrLit( - "key", - ), - is_type_alias: false, - flags: STR | LITERAL, - }, - name: "key", - range: ( - Position { - filename: "test.k", - line: 3, - column: Some( - 8, - ), - }, - Position { - filename: "test.k", - line: 3, - column: Some( - 13, - ), - }, - ), - owner: None, - def: Some( - SymbolRef { - id: Index { - index: 4, - generation: 0, - }, - kind: Value, - }, - ), - attrs: [ - SymbolRef { - id: Index { - index: 137, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 138, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 139, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 140, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 141, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 142, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 143, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 144, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 145, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 146, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 147, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 148, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 149, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 150, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 151, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 152, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 153, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 154, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 155, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 156, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 157, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 158, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 159, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 160, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 161, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 162, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 163, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 164, - generation: 0, - }, - kind: Function, - }, - SymbolRef { - id: Index { - index: 165, - generation: 0, - }, - kind: Function, - }, - ], - is_global: false, - }, SymbolInfo { ty: Type { kind: StrLit( @@ -618,7 +375,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 2, + index: 0, generation: 0, }, kind: Expression, @@ -1102,7 +859,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 0, + index: 1, generation: 0, }, kind: Expression, @@ -1382,7 +1139,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())" def: Some( SymbolRef { id: Index { - index: 1, + index: 2, generation: 0, }, kind: Expression, diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index c5a8b2447..91feca6ee 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -8,7 +8,6 @@ use kclvm_ast::walker::MutSelfTypedResultWalker; use kclvm_error::{diagnostic::Range, Position}; use crate::{ - builtin::{is_system_module_function, BUILTIN_FUNCTION_NAMES}, core::{ scope::LocalSymbolScopeKind, symbol::{ @@ -583,31 +582,9 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> { .clone(); if let TypeKind::Function(func_ty) = &ty.kind { - let func_fully_qualified_name = match &call_expr.func.node { - ast::Expr::Identifier(ident) => { - let names = ident - .names - .iter() - .map(|node| &node.node) - .cloned() - .collect::>() - .join("::"); - Some(names) - } - _ => None, - }; - - let func_name = func_fully_qualified_name - .as_ref() - .and_then(|name| name.split("::").last().map(String::from)); - - let is_builtin = func_name.as_deref().map_or(false, |name| { - BUILTIN_FUNCTION_NAMES.contains(&name) || is_system_module_function(&name) - }); - let func_params = &func_ty.params; - if is_builtin { + if func_params.is_empty() { self.do_arguments_symbol_resolve(&call_expr.args, &call_expr.keywords)?; } else { self.do_arguments_symbol_resolve_with_hint( @@ -1314,8 +1291,25 @@ impl<'ctx> AdvancedResolver<'ctx> { args: &'ctx [ast::NodeRef], kwargs: &'ctx [ast::NodeRef], with_hint: bool, - mut params: Vec, + params: Vec, ) -> anyhow::Result<()> { + for (arg, param) in args.iter().zip(params.iter()) { + self.expr(arg)?; + + let symbol_data = self.gs.get_symbols_mut(); + if let Some(arg_ref) = symbol_data + .symbols_info + .node_symbol_map + .get(&self.ctx.get_node_key(&arg.id)) + { + if let Some(value) = symbol_data.values.get_mut(arg_ref.get_id()) { + if with_hint { + value.hint = Some(SymbolHint::VarHint(param.name.clone())); + } + } + } + } + for kw in kwargs.iter() { if let Some(value) = &kw.node.value { self.expr(value)?; @@ -1328,7 +1322,6 @@ impl<'ctx> AdvancedResolver<'ctx> { ); if let Some(value) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { - params.retain(|param| param.name != kw.node.arg.node.get_name()); value.sema_info = SymbolSemanticInfo { ty: self .ctx @@ -1340,29 +1333,6 @@ impl<'ctx> AdvancedResolver<'ctx> { }; } } - - for (arg, param) in args.iter().zip(params.iter()) { - self.expr(arg)?; - let (start_pos, end_pos) = arg.get_span_pos(); - let arg_value = self.gs.get_symbols_mut().alloc_value_symbol( - ValueSymbol::new(param.name.clone(), start_pos, end_pos, None, false), - self.ctx.get_node_key(&arg.id), - self.ctx.current_pkgpath.clone().unwrap(), - ); - - if let Some(val) = self.gs.get_symbols_mut().values.get_mut(arg_value.get_id()) { - let ty = self - .ctx - .node_ty_map - .borrow() - .get(&self.ctx.get_node_key(&arg.id)) - .map(|ty| ty.clone()); - if with_hint { - val.hint = Some(SymbolHint::VarHint(param.name.clone())); - } - val.sema_info = SymbolSemanticInfo { ty, doc: None }; - } - } Ok(()) } diff --git a/kclvm/sema/src/builtin/system_module.rs b/kclvm/sema/src/builtin/system_module.rs index 69624d520..e674c3cca 100644 --- a/kclvm/sema/src/builtin/system_module.rs +++ b/kclvm/sema/src/builtin/system_module.rs @@ -1976,20 +1976,3 @@ pub fn get_system_member_function_ty(name: &str, func: &str) -> TypeRef { .map(|ty| Arc::new(ty)) .unwrap_or(Type::any_ref()) } - -pub fn is_system_module_function(name: &str) -> bool { - BASE64_FUNCTION_NAMES.contains(&name) - || NET_FUNCTION_NAMES.contains(&name) - || MANIFESTS_FUNCTION_NAMES.contains(&name) - || MATH_FUNCTION_NAMES.contains(&name) - || DATETIME_FUNCTION_NAMES.contains(&name) - || REGEX_FUNCTION_NAMES.contains(&name) - || YAML_FUNCTION_NAMES.contains(&name) - || JSON_FUNCTION_NAMES.contains(&name) - || CRYPTO_FUNCTION_NAMES.contains(&name) - || UNITS_FUNCTION_NAMES.contains(&name) - || COLLECTION_FUNCTION_NAMES.contains(&name) - || FILE_FUNCTION_NAMES.contains(&name) - || TEMPLATE_FUNCTION_NAMES.contains(&name) - || RUNTIME_FUNCTION_NAMES.contains(&name) -} From 8244340fc437d2074b41dcef2096701091f68461 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Mon, 8 Jul 2024 13:24:52 +0530 Subject: [PATCH 07/11] add function type param Signed-off-by: shruti2522 --- kclvm/sema/src/advanced_resolver/node.rs | 92 ++++++++++++------------ 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index 91feca6ee..5f3d6ca35 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -15,7 +15,7 @@ use crate::{ SymbolSemanticInfo, UnresolvedSymbol, ValueSymbol, }, }, - ty::{Parameter, Type, TypeKind, SCHEMA_MEMBER_FUNCTIONS}, + ty::{self, Type, TypeKind, SCHEMA_MEMBER_FUNCTIONS}, }; use super::AdvancedResolver; @@ -582,18 +582,12 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> { .clone(); if let TypeKind::Function(func_ty) = &ty.kind { - let func_params = &func_ty.params; - - if func_params.is_empty() { - self.do_arguments_symbol_resolve(&call_expr.args, &call_expr.keywords)?; - } else { - self.do_arguments_symbol_resolve_with_hint( - &call_expr.args, - &call_expr.keywords, - true, - func_params.to_vec(), - )?; - } + self.do_arguments_symbol_resolve_with_hint( + &call_expr.args, + &call_expr.keywords, + true, + &func_ty, + )?; } Ok(None) @@ -1291,46 +1285,50 @@ impl<'ctx> AdvancedResolver<'ctx> { args: &'ctx [ast::NodeRef], kwargs: &'ctx [ast::NodeRef], with_hint: bool, - params: Vec, + func_ty: &ty::FunctionType, ) -> anyhow::Result<()> { - for (arg, param) in args.iter().zip(params.iter()) { - self.expr(arg)?; - - let symbol_data = self.gs.get_symbols_mut(); - if let Some(arg_ref) = symbol_data - .symbols_info - .node_symbol_map - .get(&self.ctx.get_node_key(&arg.id)) - { - if let Some(value) = symbol_data.values.get_mut(arg_ref.get_id()) { - if with_hint { - value.hint = Some(SymbolHint::VarHint(param.name.clone())); + if func_ty.params.is_empty() { + self.do_arguments_symbol_resolve(args, kwargs)?; + } else { + for (arg, param) in args.iter().zip(func_ty.params.iter()) { + self.expr(arg)?; + + let symbol_data = self.gs.get_symbols_mut(); + if let Some(arg_ref) = symbol_data + .symbols_info + .node_symbol_map + .get(&self.ctx.get_node_key(&arg.id)) + { + if let Some(value) = symbol_data.values.get_mut(arg_ref.get_id()) { + if with_hint { + value.hint = Some(SymbolHint::VarHint(param.name.clone())); + } } } } - } - for kw in kwargs.iter() { - if let Some(value) = &kw.node.value { - self.expr(value)?; - } - let (start_pos, end_pos): Range = kw.get_span_pos(); - let value = self.gs.get_symbols_mut().alloc_value_symbol( - ValueSymbol::new(kw.node.arg.node.get_name(), start_pos, end_pos, None, false), - self.ctx.get_node_key(&kw.id), - self.ctx.current_pkgpath.clone().unwrap(), - ); + for kw in kwargs.iter() { + if let Some(value) = &kw.node.value { + self.expr(value)?; + } + let (start_pos, end_pos): Range = kw.get_span_pos(); + let value = self.gs.get_symbols_mut().alloc_value_symbol( + ValueSymbol::new(kw.node.arg.node.get_name(), start_pos, end_pos, None, false), + self.ctx.get_node_key(&kw.id), + self.ctx.current_pkgpath.clone().unwrap(), + ); - if let Some(value) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { - value.sema_info = SymbolSemanticInfo { - ty: self - .ctx - .node_ty_map - .borrow() - .get(&self.ctx.get_node_key(&kw.id)) - .map(|ty| ty.clone()), - doc: None, - }; + if let Some(value) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { + value.sema_info = SymbolSemanticInfo { + ty: self + .ctx + .node_ty_map + .borrow() + .get(&self.ctx.get_node_key(&kw.id)) + .map(|ty| ty.clone()), + doc: None, + }; + } } } Ok(()) From 51ca5ff4183b3edebb86b11253779a445c687f96 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Mon, 8 Jul 2024 17:43:15 +0530 Subject: [PATCH 08/11] fix ci Signed-off-by: shruti2522 --- kclvm/sema/src/advanced_resolver/node.rs | 20 +++++++++++++++---- kclvm/sema/src/core/symbol.rs | 2 ++ .../assign_stmt_type_hint.k | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index 5f3d6ca35..af3cb8ee2 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -1292,17 +1292,29 @@ impl<'ctx> AdvancedResolver<'ctx> { } else { for (arg, param) in args.iter().zip(func_ty.params.iter()) { self.expr(arg)?; - let symbol_data = self.gs.get_symbols_mut(); + if let Some(arg_ref) = symbol_data .symbols_info .node_symbol_map .get(&self.ctx.get_node_key(&arg.id)) { - if let Some(value) = symbol_data.values.get_mut(arg_ref.get_id()) { - if with_hint { - value.hint = Some(SymbolHint::VarHint(param.name.clone())); + match arg_ref.get_kind() { + crate::core::symbol::SymbolKind::Value => { + if let Some(value) = symbol_data.values.get_mut(arg_ref.get_id()) { + if with_hint { + value.hint = Some(SymbolHint::VarHint(param.name.clone())); + } + } + } + crate::core::symbol::SymbolKind::Expression => { + if let Some(expr) = symbol_data.exprs.get_mut(arg_ref.get_id()) { + if with_hint { + expr.hint = Some(SymbolHint::VarHint(param.name.clone())); + } + } } + _ => {} } } } diff --git a/kclvm/sema/src/core/symbol.rs b/kclvm/sema/src/core/symbol.rs index 57596aa02..7891a04e1 100644 --- a/kclvm/sema/src/core/symbol.rs +++ b/kclvm/sema/src/core/symbol.rs @@ -1959,6 +1959,7 @@ pub struct ExpressionSymbol { pub(crate) name: String, pub(crate) sema_info: SymbolSemanticInfo, + pub(crate) hint: Option, } impl Symbol for ExpressionSymbol { @@ -2072,6 +2073,7 @@ impl ExpressionSymbol { end, sema_info: SymbolSemanticInfo::default(), owner, + hint: None, } } } diff --git a/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k b/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k index 1b0ef2e75..290036550 100644 --- a/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k +++ b/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k @@ -25,4 +25,4 @@ func = lambda x, y, z{ x * y + z } -z = func(a, 1, z = 2) +value = func(a, 1, z = 2) From 4dfdeb10a0bae120508a13c371b7aed984071329 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Tue, 9 Jul 2024 20:42:47 +0530 Subject: [PATCH 09/11] add get_hint for expression Signed-off-by: shruti2522 --- kclvm/sema/src/advanced_resolver/node.rs | 7 ------ kclvm/sema/src/core/symbol.rs | 2 +- ...y_hints__tests__assign_stmt_type_hint.snap | 24 +------------------ .../assign_stmt_type_hint.k | 2 +- 4 files changed, 3 insertions(+), 32 deletions(-) diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index af3cb8ee2..43fc22cf6 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -1300,13 +1300,6 @@ impl<'ctx> AdvancedResolver<'ctx> { .get(&self.ctx.get_node_key(&arg.id)) { match arg_ref.get_kind() { - crate::core::symbol::SymbolKind::Value => { - if let Some(value) = symbol_data.values.get_mut(arg_ref.get_id()) { - if with_hint { - value.hint = Some(SymbolHint::VarHint(param.name.clone())); - } - } - } crate::core::symbol::SymbolKind::Expression => { if let Some(expr) = symbol_data.exprs.get_mut(arg_ref.get_id()) { if with_hint { diff --git a/kclvm/sema/src/core/symbol.rs b/kclvm/sema/src/core/symbol.rs index 7891a04e1..3ce428176 100644 --- a/kclvm/sema/src/core/symbol.rs +++ b/kclvm/sema/src/core/symbol.rs @@ -2030,7 +2030,7 @@ impl Symbol for ExpressionSymbol { } fn get_hint(&self) -> Option<&Self::SymbolHint> { - None + self.hint.as_ref() } fn simple_dump(&self) -> String { diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap index 1cf3a424b..5949f9f8f 100644 --- a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap @@ -294,29 +294,7 @@ Some( InlayHint { position: Position { line: 27, - character: 9, - }, - label: LabelParts( - [ - InlayHintLabelPart { - value: "x: ", - tooltip: None, - location: None, - command: None, - }, - ], - ), - kind: None, - text_edits: None, - tooltip: None, - padding_left: None, - padding_right: None, - data: None, - }, - InlayHint { - position: Position { - line: 27, - character: 12, + character: 13, }, label: LabelParts( [ diff --git a/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k b/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k index 290036550..3d63c8e4f 100644 --- a/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k +++ b/kclvm/tools/src/LSP/src/test_data/inlay_hints/assign_stmt_type_hint/assign_stmt_type_hint.k @@ -25,4 +25,4 @@ func = lambda x, y, z{ x * y + z } -value = func(a, 1, z = 2) +k = func(a, 1, z = 2) From 241c044ca72ce1232f0042315e67c2e448342ef5 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Tue, 9 Jul 2024 20:51:02 +0530 Subject: [PATCH 10/11] add value symbol Signed-off-by: shruti2522 --- kclvm/sema/src/advanced_resolver/node.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index 43fc22cf6..af3cb8ee2 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -1300,6 +1300,13 @@ impl<'ctx> AdvancedResolver<'ctx> { .get(&self.ctx.get_node_key(&arg.id)) { match arg_ref.get_kind() { + crate::core::symbol::SymbolKind::Value => { + if let Some(value) = symbol_data.values.get_mut(arg_ref.get_id()) { + if with_hint { + value.hint = Some(SymbolHint::VarHint(param.name.clone())); + } + } + } crate::core::symbol::SymbolKind::Expression => { if let Some(expr) = symbol_data.exprs.get_mut(arg_ref.get_id()) { if with_hint { From 0eace130d426824b4ada618a6d46a484fa8a8923 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Wed, 10 Jul 2024 12:36:48 +0530 Subject: [PATCH 11/11] correct character position Signed-off-by: shruti2522 --- kclvm/tools/src/LSP/src/inlay_hints.rs | 7 ++++++- ..._server__inlay_hints__tests__assign_stmt_type_hint.snap | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kclvm/tools/src/LSP/src/inlay_hints.rs b/kclvm/tools/src/LSP/src/inlay_hints.rs index 2e4905805..31c37b1e3 100644 --- a/kclvm/tools/src/LSP/src/inlay_hints.rs +++ b/kclvm/tools/src/LSP/src/inlay_hints.rs @@ -92,7 +92,12 @@ fn get_hint_label(symbol: &KCLSymbol, hint: &SymbolHint) -> (InlayHintLabelPart, }, LspPosition::new( (start.line - 1).try_into().unwrap(), - start.column.unwrap_or(0).try_into().unwrap(), + start + .column + .unwrap_or(1) + .saturating_sub(1) + .try_into() + .unwrap(), ), ), } diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap index 5949f9f8f..e6ada19c5 100644 --- a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap @@ -294,7 +294,7 @@ Some( InlayHint { position: Position { line: 27, - character: 13, + character: 12, }, label: LabelParts( [