Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix lambda expr scope range in advanced resolver #1439

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kclvm/sema/src/advanced_resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1824,4 +1824,42 @@ 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 labels: Vec<String> =
arr.iter().map(|item| item.label.clone()).collect();
insta::assert_snapshot!(format!("{:?}", 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
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tools/src/LSP/src/completion.rs
assertion_line: 1863
expression: "format!(\"{:?}\", labels)"
---
["option(…)", "print(…)", "multiplyof(…)", "isunique(…)", "len(…)", "abs(…)", "all_true(…)", "any_true(…)", "hex(…)", "bin(…)", "oct(…)", "ord(…)", "sorted(…)", "range(…)", "max(…)", "min(…)", "sum(…)", "pow(…)", "round(…)", "zip(…)", "int(…)", "float(…)", "bool(…)", "str(…)", "list(…)", "dict(…)", "typeof(…)", "case", "func1", "cases"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cases: [str] = ["a"]

func1 = lambda elems: [any], func: (any) -> (any) {

}

func1(cases, lambda case: str {

})
Loading