Skip to content

Commit

Permalink
fix: lsp completion depend on func return type for func call expr (#1472
Browse files Browse the repository at this point in the history
)

Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored and shruti2522 committed Jul 4, 2024
1 parent 69bf678 commit 2123149
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 1 deletion.
11 changes: 10 additions & 1 deletion kclvm/sema/src/advanced_resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,16 @@ impl<'ctx> AdvancedResolver<'ctx> {
end,
None,
);
expr_symbol.sema_info.ty = Some(ty.clone());
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())
};

Ok(self.gs.get_symbols_mut().alloc_expression_symbol(
expr_symbol,
self.ctx.get_node_key(&expr.id),
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 @@ -2024,4 +2024,28 @@ mod tests {
8,
None
);

completion_label_without_builtin_func_test_snapshot!(
func_return_ty_1,
"src/test_data/completion_test/dot/func_return/func_return_1/func_return_1.k",
4,
8,
Some('.')
);

completion_label_without_builtin_func_test_snapshot!(
func_return_ty_2,
"src/test_data/completion_test/dot/func_return/func_return_2/func_return_2.k",
8,
12,
Some('.')
);

completion_label_without_builtin_func_test_snapshot!(
func_return_ty_3,
"src/test_data/completion_test/dot/func_return/func_return_3/func_return_3.k",
3,
2,
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,5 @@
---
source: tools/src/LSP/src/completion.rs
expression: "format!(\"{:?}\", got_labels)"
---
["name"]
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)"
---
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
f: () -> str = lambda {
""
}
a = f()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
schema Name:
name: str

f1: (str) -> Name = lambda s: str -> Name {
Name {name: s}
}

b = f1("a")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
f: () -> str = lambda {
""
}

0 comments on commit 2123149

Please sign in to comment.