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

enhance: add limitation on find refs target number #913

Merged
merged 2 commits into from
Nov 24, 2023
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
8 changes: 7 additions & 1 deletion kclvm/tools/src/LSP/src/find_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ pub(crate) fn find_refs_from_def<F: Fn(String) -> Result<(), anyhow::Error>>(
) -> Vec<Location> {
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() {
Peefy marked this conversation as resolved.
Show resolved Hide resolved
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<Location> = locs
.into_iter()
.filter(|ref_loc| {
Expand Down
23 changes: 16 additions & 7 deletions kclvm/tools/src/LSP/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Loading