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 config if expr pos #1027

Merged
merged 1 commit into from
Feb 4, 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
5 changes: 4 additions & 1 deletion kclvm/parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,7 @@ impl<'a> Parser<'a> {
// elif ...
let mut need_skip_newlines = false;
let mut elif_list = Vec::new();
let mut last_token = self.token;
loop {
if !self.token.is_keyword(kw::Elif) {
break;
Expand All @@ -1589,6 +1590,7 @@ impl<'a> Parser<'a> {
x,
self.sess.struct_token_loc(token, self.prev_token),
)));
last_token = self.prev_token;
}

if let TokenKind::Newline = self.token.kind {
Expand Down Expand Up @@ -1618,6 +1620,7 @@ impl<'a> Parser<'a> {
Expr::Config(orelse),
self.sess.struct_token_loc(token, self.prev_token),
));
last_token = self.prev_token;

if_entry.node.orelse = Some(t);
}
Expand Down Expand Up @@ -1648,7 +1651,7 @@ impl<'a> Parser<'a> {

Box::new(Node::node(
Expr::ConfigIfEntry(if_entry.node),
self.sess.struct_token_loc(token, self.prev_token),
self.sess.struct_token_loc(token, last_token),
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Node {
line: 1,
column: 1,
end_line: 1,
end_column: 17,
end_column: 18,
},
operation: Union,
insert_index: -1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Node {
line: 1,
column: 1,
end_line: 1,
end_column: 17,
end_column: 18,
},
operation: Union,
insert_index: -1,
Expand Down
20 changes: 20 additions & 0 deletions kclvm/tools/src/LSP/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,26 @@ mod tests {
}
}

#[test]
#[bench_test]
fn expr_after_config_if_hover() {
let (file, program, _, _, gs) = compile_test_file("src/test_data/hover_test/hover.k");
let pos = KCLPos {
filename: file.clone(),
line: 41,
column: Some(13),
};
let got = hover(&program, &pos, &gs).unwrap();
match got.contents {
lsp_types::HoverContents::Scalar(marked_string) => {
if let MarkedString::String(s) = marked_string {
assert_eq!(s, "stratege: str");
}
}
_ => unreachable!("test error"),
}
}

#[test]
#[bench_test]
fn schema_scope_variable_hover() {
Expand Down
16 changes: 16 additions & 0 deletions kclvm/tools/src/LSP/src/test_data/hover_test/hover.k
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ print(1)

a = "".capitalize()
b = a.capitalize()

schema Deployment:
spec: DeploymentSpec

schema DeploymentSpec:
stratege: str
replicas?: int

d = Deployment{
spec: DeploymentSpec {
if True:
replicas = 1
stratege: "a"
}
}

Loading