diff --git a/kclvm/tools/src/LSP/src/find_refs.rs b/kclvm/tools/src/LSP/src/find_refs.rs index fe1376d3f..3a9d8e7a8 100644 --- a/kclvm/tools/src/LSP/src/find_refs.rs +++ b/kclvm/tools/src/LSP/src/find_refs.rs @@ -66,7 +66,13 @@ pub(crate) fn find_refs_from_def Result<(), anyhow::Error>>( ) -> Vec { let mut ref_locations = vec![]; for (_, word_index) in &mut *word_index_map.write() { - if let Some(locs) = word_index.get(name.as_str()).cloned() { + if let Some(mut locs) = word_index.get(name.as_str()).cloned() { + if locs.len() >= 20 { + let _ = logger(format!( + "Found more than 20 matched symbols, only the first 20 will be processed" + )); + locs = locs[0..20].to_vec(); + } let matched_locs: Vec = locs .into_iter() .filter(|ref_loc| { diff --git a/kclvm/tools/src/LSP/src/tests.rs b/kclvm/tools/src/LSP/src/tests.rs index 85d93e7ee..7bd86fe24 100644 --- a/kclvm/tools/src/LSP/src/tests.rs +++ b/kclvm/tools/src/LSP/src/tests.rs @@ -1551,9 +1551,12 @@ fn lsp_invalid_subcommand_test() { #[test] fn find_refs_test() { - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("src") + .join("test_data") + .join("find_refs_test"); let mut path = root.clone(); - path.push("src/test_data/find_refs_test/main.k"); + path.push("main.k"); let path = path.to_str().unwrap(); let src = std::fs::read_to_string(path).unwrap(); @@ -1641,9 +1644,12 @@ fn find_refs_test() { #[test] fn find_refs_with_file_change_test() { - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("src") + .join("test_data") + .join("find_refs_test"); let mut path = root.clone(); - path.push("src/test_data/find_refs_test/main.k"); + path.push("main.k"); let path = path.to_str().unwrap(); let src = std::fs::read_to_string(path).unwrap(); @@ -1742,11 +1748,14 @@ p2 = Person { #[test] fn rename_test() { - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("src") + .join("test_data") + .join("rename_test"); let mut path = root.clone(); let mut main_path = root.clone(); - path.push("src/test_data/rename_test/pkg/vars.k"); - main_path.push("src/test_data/rename_test/main.k"); + path.push("pkg/vars.k"); + main_path.push("main.k"); let path = path.to_str().unwrap(); let src = std::fs::read_to_string(path).unwrap();