diff --git a/user-deploy-cloud-pat-script.sh b/user-deploy-cloud-pat-script.sh index eb48a3c7..51daad4a 100755 --- a/user-deploy-cloud-pat-script.sh +++ b/user-deploy-cloud-pat-script.sh @@ -38,7 +38,9 @@ spec: - name: GITHUB_PAT value: $_GITHUB_PAT - name: PROVIDER - value: $_PROVIDER + value: $_PROVIDER + - name: LOG_LEVEL + value: Debug EOF # Display the generated YAML for debugging diff --git a/vibi-dpu/Cargo.toml b/vibi-dpu/Cargo.toml index 5556d053..7d12ddb9 100644 --- a/vibi-dpu/Cargo.toml +++ b/vibi-dpu/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vibi-dpu" -version = "2.0.3" +version = "2.0.4" edition = "2021" authors = ["Tapish Rathore "] license = "GPL-3.0-or-later" diff --git a/vibi-dpu/src/graph/file_imports.rs b/vibi-dpu/src/graph/file_imports.rs index 0722c460..1edae75b 100644 --- a/vibi-dpu/src/graph/file_imports.rs +++ b/vibi-dpu/src/graph/file_imports.rs @@ -340,6 +340,7 @@ impl ImportIdentifier { } let import_struct_str = import_struct_str_res.expect("Uncaught error in import_struct_str_res"); let prompt_str = format!("{}\nOutput -", &import_struct_str); + log::debug!("[ImportIdentifier/get_import_path] code_chunk: {}", chunk); let import_path_opt = call_llm_api(prompt_str).await; // deserialize output if import_path_opt.is_none() { @@ -358,6 +359,7 @@ impl ImportIdentifier { return None; } let import_path: ImportPathOutput = import_path_res.expect("Unacaught error in import_path_res"); + log::debug!("[ImportIdentifier/get_import_path] import_path: {:?}", &import_path); if !import_path.get_matching_import().possible_file_path().is_empty() { return None; } diff --git a/vibi-dpu/src/graph/function_call.rs b/vibi-dpu/src/graph/function_call.rs index 7c6cde22..cd2f7bb7 100644 --- a/vibi-dpu/src/graph/function_call.rs +++ b/vibi-dpu/src/graph/function_call.rs @@ -267,7 +267,9 @@ impl FunctionCallIdentifier { let chunks = numbered_content.chunks(50); for chunk in chunks { let chunk_str = chunk.join("\n"); + log::debug!("[FunctionCallIdentifier/functions_in_file] chunk = {}", &chunk_str); if let Some(mut func_calls) = self.functions_in_chunk(&chunk_str, filepath, lang).await { + log::debug!("[FunctionCallIdentifier/functions_in_file] chunk = {:?}", &func_calls); all_func_calls.function_calls.append(&mut func_calls.function_calls); } } @@ -346,7 +348,7 @@ impl FunctionCallIdentifier { hunk_func_pairs.push((hunk.clone(), matching_func_calls_output)); } } - + log::debug!("[FunctionCallIdentifier/function_calls_in_hunks] hunk_func_pairs = {:?}", &hunk_func_pairs); if hunk_func_pairs.is_empty() { None } else { diff --git a/vibi-dpu/src/graph/function_name.rs b/vibi-dpu/src/graph/function_name.rs index c79d41c7..77c83356 100644 --- a/vibi-dpu/src/graph/function_name.rs +++ b/vibi-dpu/src/graph/function_name.rs @@ -84,6 +84,7 @@ impl FunctionNameIdentifier { } let prompt_str = prompt_str_res.expect("Uncaught error in prompt_str_res"); let final_prompt = format!("{}\nOutput - ", &prompt_str); + log::debug!("[FunctionNameIdentifier/function_name_in_line] code_line: {}", code_line); let prompt_response_opt = call_llm_api(final_prompt).await; if prompt_response_opt.is_none() { log::error!("[FunctionNameIdentifier/function_name_in_line] Unable to call llm for code line: {:?}", code_line); @@ -103,6 +104,7 @@ impl FunctionNameIdentifier { if func_name.get_function_name().is_empty() { return None; } + log::debug!("[FunctionNameIdentifier/function_name_in_line] func_name: {:?}", &func_name); self.cached_output.insert(code_line.trim().to_string(), func_name.get_function_name().to_string()); return Some(func_name); } diff --git a/vibi-dpu/src/graph/gitops.rs b/vibi-dpu/src/graph/gitops.rs index 86e8c851..429a0613 100644 --- a/vibi-dpu/src/graph/gitops.rs +++ b/vibi-dpu/src/graph/gitops.rs @@ -65,15 +65,14 @@ impl FileHunks { &mut self.added_hunks } - pub fn is_func_in_hunks(&self, function_name: &str) -> &Option { - for hunk_lines in self.added_hunks() { - if let Some(func_raw) = hunk_lines.function_line() { - if func_raw.contains(function_name) { - return hunk_lines.line_number(); - } - } + pub fn is_func_in_hunks(&self, function_name: &str, edge_color: &str) -> &Option { + let hunks; + if edge_color == "green" { + hunks = self.added_hunks(); + } else { + hunks = self.deleted_hunks(); } - for hunk_lines in self.deleted_hunks() { + for hunk_lines in hunks { if let Some(func_raw) = hunk_lines.function_line() { if func_raw.contains(function_name) { return hunk_lines.line_number(); diff --git a/vibi-dpu/src/graph/graph_edges.rs b/vibi-dpu/src/graph/graph_edges.rs index 34420edf..39993f66 100644 --- a/vibi-dpu/src/graph/graph_edges.rs +++ b/vibi-dpu/src/graph/graph_edges.rs @@ -44,7 +44,7 @@ async fn outgoing_edges(base_filepaths: &Vec, diff_graph: &DiffGraph, { let func_call_identifier_opt = FunctionCallIdentifier::new(); if func_call_identifier_opt.is_none() { - log::error!("[incoming_edges] Unable to create new FunctionCallIdentifier"); + log::error!("[outgoing_edges] Unable to create new FunctionCallIdentifier"); return; } let mut func_call_identifier = func_call_identifier_opt.expect("Empty func_call_identifier_opt"); @@ -87,6 +87,11 @@ async fn process_func_calls(import_identifier: &mut ImportIdentifier, func_call_ graph_elems: &mut MermaidGraphElements, edge_color: &str) { for (source_filepath, src_file_hunks) in diff_graph.hunk_diff_map().file_line_map() { + let lang_opt = detect_language(source_filepath); + if lang_opt.is_none() { + log::error!("[process_func_calls] Unable to determine language: {}", source_filepath); + continue; + } let mut source_file_name = source_filepath.to_owned(); // get func calls if let Some(source_file) = absolute_to_relative_path(source_filepath, review) { @@ -98,34 +103,65 @@ async fn process_func_calls(import_identifier: &mut ImportIdentifier, func_call_ } else { diff_hunks = src_file_hunks.deleted_hunks(); } - let lang_opt = detect_language(source_filepath); - if lang_opt.is_none() { - log::error!("[get_import_path_file] Unable to determine language: {}", source_filepath); - return; - } + log::debug!("[process_func_calls] file name: {}\n, diff_hunks: {:?}, edge: {}", &source_file_name, diff_hunks, edge_color); let lang = lang_opt.expect("Empty lang_opt"); let source_file_path = Path::new(source_filepath); let source_file_pathbuf = source_file_path.to_path_buf(); if let Some(hunk_func_calls) = func_call_identifier. function_calls_in_hunks(&source_file_pathbuf, &lang, diff_hunks).await { for (hunk_lines, func_call_output) in hunk_func_calls { - for dest_func_call in func_call_output.function_calls() { - if let Some(import_filepath) = import_identifier.get_import_path_file( - source_filepath, &lang, dest_func_call.function_name()).await { - // get file - // get diffgraph all files and see if they contain filepath - let possible_diff_file_paths: Vec<&String> = diff_graph.hunk_diff_map().all_files().into_iter() - .filter(|file_path| file_path.contains(import_filepath.get_matching_import().possible_file_path())).collect(); - if !possible_diff_file_paths.is_empty() { - for possible_diff_file_path in possible_diff_file_paths { - if diff_graph.hunk_diff_map().all_files().contains(&possible_diff_file_path) - { - let hunks_for_func = diff_graph.hunk_diff_map().file_line_map() - .get(possible_diff_file_path).expect("Empty entry in file_line_map"); - if let Some(possible_file_rel) = absolute_to_relative_path(possible_diff_file_path, review) { - if let Some(dest_func_def_line) = hunks_for_func.is_func_in_hunks(dest_func_call.function_name()) { - if let Some(src_func_name) = hunk_lines.function_line() { - if let Some(src_func_line_number) = hunk_lines.line_number() { + if let Some(src_func_name) = hunk_lines.function_line() { + if let Some(src_func_line_number) = hunk_lines.line_number() { + for dest_func_call in func_call_output.function_calls() { + if let Some(import_filepath) = import_identifier.get_import_path_file( + source_filepath, &lang, dest_func_call.function_name()).await { + // get file + // get diffgraph all files and see if they contain filepath + let possible_diff_file_paths: Vec<&String> = diff_graph.hunk_diff_map().all_files().into_iter() + .filter(|file_path| file_path.contains(import_filepath.get_matching_import().possible_file_path())).collect(); + log::debug!("[process_func_calls] possible_diff_file_paths = {:?}", &possible_diff_file_paths); + if !possible_diff_file_paths.is_empty() { + for possible_diff_file_path in possible_diff_file_paths { + if diff_graph.hunk_diff_map().all_files().contains(&possible_diff_file_path) + { + log::debug!("[process_func_calls] possible_diff_file_path ={}", &possible_diff_file_path); + if let Some(possible_file_rel) = absolute_to_relative_path(possible_diff_file_path, review) { + let hunks_for_func = diff_graph.hunk_diff_map().file_line_map() + .get(possible_diff_file_path).expect("Empty entry in file_line_map"); + if let Some(dest_func_def_line) = hunks_for_func.is_func_in_hunks(dest_func_call.function_name(), edge_color) { + graph_elems.add_edge( + edge_color, + dest_func_call.line_number().to_owned() as usize, + src_func_name, + dest_func_call.function_name(), + &source_file_name, + &possible_file_rel, + "yellow", + "", + src_func_line_number, + dest_func_def_line); + } + } + } + } + } else { + // search all files + // TODO - see if git checkout is needed + let possible_file_pathbufs: Vec<&PathBuf> = base_filepaths.iter() + .filter(|file_path| + file_path.to_string_lossy().contains(import_filepath.get_matching_import().possible_file_path())).collect(); + log::debug!("[process_func_calls] possible_file_pathbufs = {:?}", &possible_file_pathbufs); + if !possible_file_pathbufs.is_empty() { + for possible_file_pathbuf in possible_file_pathbufs { + let possible_file_path: String = possible_file_pathbuf.to_string_lossy().to_string(); + if let Some(possible_file_rel) = + absolute_to_relative_path(&possible_file_path, review) { + // search only for func def with specific name + // if something comes up, add edge! + if let Some(func_def) = funcdef_identifier.function_defs_in_file( + possible_file_pathbuf, &lang, dest_func_call.function_name()).await { + log::debug!("[process_func_calls] func_def ={:#?}", &func_def); + if let Some(dest_func_def_line) = func_def.get_function_line_number() { graph_elems.add_edge( edge_color, dest_func_call.line_number().to_owned() as usize, @@ -136,51 +172,16 @@ async fn process_func_calls(import_identifier: &mut ImportIdentifier, func_call_ "yellow", "", src_func_line_number, - dest_func_def_line); - } - } - } - } - } - } - } else { - // search all files - // TODO - see if git checkout is needed - let possible_file_pathbufs: Vec<&PathBuf> = base_filepaths.iter() - .filter(|file_path| - file_path.to_string_lossy().contains(import_filepath.get_matching_import().possible_file_path())).collect(); - if !possible_file_pathbufs.is_empty() { - for possible_file_pathbuf in possible_file_pathbufs { - let possible_file_path: String = possible_file_pathbuf.to_string_lossy().to_string(); - // search only for func def with specific name - // if something comes up, add edge! - if let Some(func_defs) = funcdef_identifier.function_defs_in_file( - possible_file_pathbuf, &lang, dest_func_call.function_name()).await { - if let Some(dest_func_def_line) = func_defs.get_function_line_number() { - if let Some(src_func_name) = hunk_lines.function_line() { - if let Some(src_func_line_number) = hunk_lines.line_number() { - if let Some(possible_file_rel) = - absolute_to_relative_path(&possible_file_path, review) { - graph_elems.add_edge( - edge_color, - dest_func_call.line_number().to_owned() as usize, - src_func_name, - dest_func_call.function_name(), - &source_file_name, - &possible_file_rel, - "yellow", - "", - src_func_line_number, - &dest_func_def_line); - } + &dest_func_def_line); } } } } } } - } - } + } + } + } } } } diff --git a/vibi-dpu/src/graph/utils.rs b/vibi-dpu/src/graph/utils.rs index 71bf45c9..f047818a 100644 --- a/vibi-dpu/src/graph/utils.rs +++ b/vibi-dpu/src/graph/utils.rs @@ -20,7 +20,6 @@ struct LlmResponse { pub async fn call_llm_api(prompt: String) -> Option { let client = get_client(); let url = "http://34.100.208.132/api/generate"; - log::debug!("[call_llm_api] Prompt = {:?}", &prompt); let response_res = client.post(url) .json(&json!({"model": "phind-codellama", "prompt": prompt})) .send() @@ -76,11 +75,11 @@ pub async fn call_llm_api(prompt: String) -> Option { } } } + log::debug!("[call_llm_api] final response = {}", &final_response); let final_response_trimmed = final_response.trim(); if final_response_trimmed.starts_with("{") && !final_response_trimmed.ends_with("}") { final_response.push_str("}"); } - log::debug!("[call_llm_api] final_response = {:?}", &final_response); Some(final_response) }