diff --git a/kclvm/tools/src/LSP/src/hover.rs b/kclvm/tools/src/LSP/src/hover.rs index 6e9fb78f1..4aa1de38e 100644 --- a/kclvm/tools/src/LSP/src/hover.rs +++ b/kclvm/tools/src/LSP/src/hover.rs @@ -424,4 +424,28 @@ mod tests { _ => unreachable!("test error"), } } + + #[test] + #[bench_test] + fn import_pkg_hover() { + let (file, program, _, _, gs) = compile_test_file("src/test_data/hover_test/import_pkg.k"); + let pos = KCLPos { + filename: file.clone(), + line: 3, + column: Some(7), + }; + let got = hover(&program, &pos, &gs).unwrap(); + match got.contents { + lsp_types::HoverContents::Array(vec) => { + assert_eq!(vec.len(), 2); + if let MarkedString::String(s) = vec[0].clone() { + assert_eq!(s, "fib\n\nschema Fib"); + } + if let MarkedString::String(s) = vec[1].clone() { + assert_eq!(s, "Attributes:\n\nn: int\n\nvalue: int"); + } + } + _ => unreachable!("test error"), + } + } } diff --git a/kclvm/tools/src/LSP/src/test_data/hover_test/import_pkg.k b/kclvm/tools/src/LSP/src/test_data/hover_test/import_pkg.k new file mode 100644 index 000000000..a972f027f --- /dev/null +++ b/kclvm/tools/src/LSP/src/test_data/hover_test/import_pkg.k @@ -0,0 +1,3 @@ +import .fib + +fib.Fib{} \ No newline at end of file diff --git a/kclvm/tools/src/LSP/src/tests.rs b/kclvm/tools/src/LSP/src/tests.rs index 78db83c96..ceec1c8d5 100644 --- a/kclvm/tools/src/LSP/src/tests.rs +++ b/kclvm/tools/src/LSP/src/tests.rs @@ -48,6 +48,7 @@ use std::time::Duration; use kclvm_ast::ast::Program; use kclvm_error::Diagnostic as KCLDiagnostic; use kclvm_error::Position as KCLPos; +use kclvm_parser::KCLModuleCache; use kclvm_sema::resolver::scope::ProgramScope; use lsp_types::Diagnostic; @@ -125,7 +126,7 @@ pub(crate) fn compile_test_file( let (program, prog_scope, diags, gs) = parse_param_and_compile( Param { file: file.clone(), - module_cache: None, + module_cache: Some(KCLModuleCache::default()), }, Some(Arc::new(RwLock::new(Default::default()))), )