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)