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 complete after some special expr. #1641

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 29 additions & 24 deletions kclvm/sema/src/advanced_resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,33 +1051,38 @@ impl<'ctx> AdvancedResolver<'ctx> {
.borrow()
.get(&self.ctx.get_node_key(&expr.id))
{
Some(ty) => {
if let ast::Expr::Missing(_) = expr.node {
return Ok(None);
}
let (_, end) = expr.get_span_pos();
let mut expr_symbol = ExpressionSymbol::new(
format!("@{}", expr.node.get_expr_name()),
end.clone(),
end,
None,
);
expr_symbol.sema_info.ty = if matches!(&expr.node, | ast::Expr::Call(_)) {
if let TypeKind::Function(func_ty) = &ty.kind {
Some(func_ty.return_ty.clone())
Some(ty) => match expr.node {
ast::Expr::Missing(_)
| ast::Expr::Binary(_)
| ast::Expr::CompClause(_)
| ast::Expr::Keyword(_)
| ast::Expr::Arguments(_)
| ast::Expr::Compare(_) => return Ok(None),
_ => {
let (_, end) = expr.get_span_pos();
let mut expr_symbol = ExpressionSymbol::new(
format!("@{}", expr.node.get_expr_name()),
end.clone(),
end,
None,
);
expr_symbol.sema_info.ty = if matches!(&expr.node, | ast::Expr::Call(_)) {
if let TypeKind::Function(func_ty) = &ty.kind {
Some(func_ty.return_ty.clone())
} else {
Some(ty.clone())
}
} else {
Some(ty.clone())
}
} else {
Some(ty.clone())
};
};

Ok(self.gs.get_symbols_mut().alloc_expression_symbol(
expr_symbol,
self.ctx.get_node_key(&expr.id),
self.ctx.current_pkgpath.clone().unwrap(),
))
}
Ok(self.gs.get_symbols_mut().alloc_expression_symbol(
expr_symbol,
self.ctx.get_node_key(&expr.id),
self.ctx.current_pkgpath.clone().unwrap(),
))
}
},
None => Ok(None),
},
res => res,
Expand Down
8 changes: 8 additions & 0 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2151,4 +2151,12 @@ mod tests {
15,
Some('.')
);

completion_label_test_snapshot!(
complete_after_compare_expr_1,
"src/test_data/completion_test/dot/special_expr/compare.k",
2,
23,
Some('.')
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: tools/src/LSP/src/completion.rs
expression: "format!(\"{:?}\", got_labels)"
---
["capitalize(…)", "count(…)", "endswith(…)", "find(…)", "format(…)", "index(…)", "isalnum(…)", "isalpha(…)", "isdigit(…)", "islower(…)", "isspace(…)", "istitle(…)", "isupper(…)", "join(…)", "lower(…)", "lstrip(…)", "removeprefix(…)", "removesuffix(…)", "replace(…)", "rfind(…)", "rindex(…)", "rsplit(…)", "rstrip(…)", "split(…)", "splitlines(…)", "startswith(…)", "strip(…)", "title(…)", "upper(…)"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
v = ""
if v == "" and "" == v :
a = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
v = ""
if v == "" and "" == v :
a = 1
Loading