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

feat: lsp hover for dict into schema expr key #1343

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion kclvm/sema/src/advanced_resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> {
}
self.ctx.maybe_def = true;
self.walk_identifier_expr(target)?;

if let Some(target_ty) = self.ctx.node_ty_map.get(&self.ctx.get_node_key(&target.id)) {
match &target_ty.kind {
TypeKind::Schema(_) => {
let schema_symbol = self
.gs
.get_symbols()
.get_type_symbol(&target_ty, self.get_current_module_info())
.ok_or(anyhow!("schema_symbol not found"))?;
self.ctx.current_schema_symbol = Some(schema_symbol);
}
_ => {}
}
}
self.ctx.maybe_def = false;
}
self.walk_type_expr(assign_stmt.ty.as_ref().map(|ty| ty.as_ref()))?;
Expand Down Expand Up @@ -861,7 +875,7 @@ impl<'ctx> AdvancedResolver<'ctx> {
}
None => Ok(None),
},
some => some,
res => res,
}
}

Expand Down
1 change: 1 addition & 0 deletions kclvm/tools/src/LSP/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ serde_json = { version = "1.0", default-features = false }
parking_lot = { version = "0.12.0", default-features = false }
rustc-hash = { version = "1.1.0", default-features = false }
proc_macro_crate = { path = "../../benches/proc_macro_crate" }
insta = "1.8.0"
He1pa marked this conversation as resolved.
Show resolved Hide resolved

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.37.0", features = ["full"] }
30 changes: 30 additions & 0 deletions kclvm/tools/src/LSP/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,34 @@ mod tests {
_ => unreachable!("test error"),
}
}

#[test]
#[bench_test]
fn dict_key_in_schema() {
let (file, program, _, gs) =
compile_test_file("src/test_data/hover_test/dict_key_in_schema/dict_key_in_schema.k");
let pos = KCLPos {
filename: file.clone(),
line: 5,
column: Some(5),
};
let got = hover(&program, &pos, &gs).unwrap();
insta::assert_snapshot!(format!("{:?}", got));

let pos = KCLPos {
filename: file.clone(),
line: 9,
column: Some(5),
};
let got = hover(&program, &pos, &gs).unwrap();
insta::assert_snapshot!(format!("{:?}", got));

let pos = KCLPos {
filename: file.clone(),
line: 13,
column: Some(5),
};
let got = hover(&program, &pos, &gs).unwrap();
insta::assert_snapshot!(format!("{:?}", got));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: tools/src/LSP/src/hover.rs
expression: "format!(\"{:?}\", got)"
---
Hover { contents: Scalar(String("name: int")), range: None }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: tools/src/LSP/src/hover.rs
expression: "format!(\"{:?}\", got)"
---
Hover { contents: Scalar(String("name: int")), range: None }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: tools/src/LSP/src/hover.rs
expression: "format!(\"{:?}\", got)"
---
Hover { contents: Scalar(String("name: int")), range: None }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
schema Name:
name: int

n1: Name = {
name = 1
}

n2 = Name{
name: 1
}

n3: Name = Name{
name: 1
}
Loading