Skip to content

Commit

Permalink
fix: remove missing expr expr_symbol
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa committed Feb 5, 2024
1 parent 801e620 commit 180ddc7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kclvm/sema/src/advanced_resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,9 @@ impl<'ctx> AdvancedResolver<'ctx> {
match self.walk_expr(&expr.node) {
None => match self.ctx.node_ty_map.get(&self.ctx.get_node_key(&expr.id)) {
Some(ty) => {
if let ast::Expr::Missing(_) = expr.node {
return None;
}
let (_, end) = expr.get_span_pos();
let mut expr_symbol = ExpressionSymbol::new(
format!("@{}", expr.node.get_expr_name()),
Expand Down
24 changes: 24 additions & 0 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,4 +1488,28 @@ mod tests {
CompletionResponse::List(_) => panic!("test failed"),
};
}

#[test]
#[bench_test]
fn missing_expr_completion() {
let (file, program, _, _, gs) =
compile_test_file("src/test_data/completion_test/dot/missing_expr/missing_expr.k");

let pos = KCLPos {
filename: file.to_owned(),
line: 10,
column: Some(16),
};

let got = completion(Some('.'), &program, &pos, &gs).unwrap();
match got {
CompletionResponse::Array(arr) => {
assert_eq!(arr.len(), 2);
let labels: Vec<String> = arr.iter().map(|item| item.label.clone()).collect();
assert!(labels.contains(&"cpu".to_string()));
assert!(labels.contains(&"memory".to_string()));
}
CompletionResponse::List(_) => panic!("test failed"),
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
schema ResourceRequirement:
cpu?: str
memory?: str

schema ResourceRequirements:
limits?: ResourceRequirement
requests?: ResourceRequirement

check:
limits?

0 comments on commit 180ddc7

Please sign in to comment.