Skip to content

Commit

Permalink
fix: fix config if expr pos (#1027)
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored Feb 4, 2024
1 parent 801e620 commit 13bea0b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
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"
}
}

0 comments on commit 13bea0b

Please sign in to comment.