Skip to content

Commit

Permalink
fix: fix lambda expr scope range in advanced resolver (#1439)
Browse files Browse the repository at this point in the history
* fix: fix lambda expr scope range

Signed-off-by: he1pa <18012015693@163.com>

* update ut

Signed-off-by: he1pa <18012015693@163.com>

---------

Signed-off-by: he1pa <18012015693@163.com>
  • Loading branch information
He1pa authored Jun 26, 2024
1 parent 577f337 commit e0b4791
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
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
39 changes: 39 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,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<String> =
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
);
}
Original file line number Diff line number Diff line change
@@ -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(…)"]
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 {

})

0 comments on commit e0b4791

Please sign in to comment.