diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index da2d82521..6df4640a1 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -846,6 +846,7 @@ impl<'ctx> AdvancedResolver<'ctx> { | ast::Expr::Schema(_) | ast::Expr::ConfigIfEntry(_) | ast::Expr::Quant(_) + | ast::Expr::Lambda(_) ) { let (start, end) = expr.get_span_pos(); self.ctx.start_pos = start; diff --git a/kclvm/tools/src/LSP/src/completion.rs b/kclvm/tools/src/LSP/src/completion.rs index 8cb74d1e2..0e6939892 100644 --- a/kclvm/tools/src/LSP/src/completion.rs +++ b/kclvm/tools/src/LSP/src/completion.rs @@ -1824,4 +1824,43 @@ mod tests { CompletionResponse::List(_) => panic!("test failed"), } } + + #[macro_export] + macro_rules! completion_label_test_snapshot { + ($name:ident, $file:expr, $line:expr, $column: expr, $trigger: expr) => { + #[test] + fn $name() { + insta::assert_snapshot!(format!("{:?}", { + let (file, program, _, gs) = compile_test_file($file); + + let pos = KCLPos { + filename: file.clone(), + line: $line, + column: Some($column), + }; + let tool = toolchain::default(); + + let mut got = completion($trigger, &program, &pos, &gs, &tool).unwrap(); + + match &mut got { + CompletionResponse::Array(arr) => { + let mut labels: Vec = + arr.iter().map(|item| item.label.clone()).collect(); + labels.sort(); + labels + } + CompletionResponse::List(_) => panic!("test failed"), + } + })); + } + }; + } + + completion_label_test_snapshot!( + lambda_1, + "src/test_data/completion_test/lambda/lambda_1/lambda_1.k", + 8, + 5, + None + ); } diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__completion__tests__lambda_1.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__completion__tests__lambda_1.snap new file mode 100644 index 000000000..31b3c212e --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__completion__tests__lambda_1.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/LSP/src/completion.rs +expression: "format!(\"{:?}\", labels)" +--- +["abs(…)", "all_true(…)", "any_true(…)", "bin(…)", "bool(…)", "case", "cases", "dict(…)", "float(…)", "func1", "hex(…)", "int(…)", "isunique(…)", "len(…)", "list(…)", "max(…)", "min(…)", "multiplyof(…)", "oct(…)", "option(…)", "ord(…)", "pow(…)", "print(…)", "range(…)", "round(…)", "sorted(…)", "str(…)", "sum(…)", "typeof(…)", "zip(…)"] diff --git a/kclvm/tools/src/LSP/src/test_data/completion_test/lambda/lambda_1/lambda_1.k b/kclvm/tools/src/LSP/src/test_data/completion_test/lambda/lambda_1/lambda_1.k new file mode 100644 index 000000000..5874be935 --- /dev/null +++ b/kclvm/tools/src/LSP/src/test_data/completion_test/lambda/lambda_1/lambda_1.k @@ -0,0 +1,9 @@ +cases: [str] = ["a"] + +func1 = lambda elems: [any], func: (any) -> (any) { + +} + +func1(cases, lambda case: str { + +})